I am getting "peer not authenticated" using google map api's after creating javafx package.
It is working fine when directly run from code or from executable jar file, The following is the exception I am getting,
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:390)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:561)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at com.precisionhawk.flightplanner.utils.LocationUtils.performAPICall(LocationUtils.java:109)
at com.precisionhawk.flightplanner.utils.LocationUtils.getAutocompleteResults(LocationUtils.java:74)
at com.precisionhawk.flightplanner.controls.AddressTextField$1$1.run(AddressTextField.java:103)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
I am using http client for calling the api. I have tried bypassing the X509 certificate but still no luck
below is my code
SSLContext ctx = null;
try {
SSLUtilities.trustAllHostnames();
SSLUtilities.trustAllHttpsCertificates();
HttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(url.toString());
getRequest.addHeader("accept", "application/json");
HttpResponse response = httpClient.execute(getRequest);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
String inputLine;
while ((inputLine = br.readLine()) != null) {
result = result + inputLine;
}
br.close();
LOG.info("Autocomplete API call Response: " + result);
}
catch (Exception e) {
LOG.error("Autocomplete Exception: "+e.getMessage());
}
If by "creating javafx package" you mean creating a Self-Contained Application, then a reason for this is that the sun cryptography extensions are not included with the default self-contained application packaging as detailed in the JavaFX deployment blog.
Quoting from the deployment blog, there are instructions on including the sun jce provider with the self-contained application for JavaFX 2.2. Likely for future releases of the JavaFX deployment tools, a more convenient way will be provided to do this.
Fine tuning application bundle
If you are using packaging tools to produce an installable package there could be a need to tweak the application image before it is wrapped into the installer. Why? For example you may want to sign the application, so it does not appear to be untrusted to the OS (for example to please Mac OS X Gatekeeper).
Also by default a self-contained application does not contain full copy of Java Runtime. We only include set of mandatory components. Part of the reason why this approach was taken is that we want to reduce the package size. However, there are situations where your application may depend on these optional components and in that case you will need a way to add them to the private runtime. For example https connections will not work if jre/lib/ext/sunjce_provider.jar is missing.
Currently this can be achieved by providing a custom config script that is executed after application image is populated. Like in the example above with the icon, you need to enable verbose output to find the name of the script file and then drop it to the location where packaging tools will find it. Note that scripting language is platform specific too. Currently we only support shell for Mac/Linux and Windows Script on windows.
How do you find out where the application image is located? Currently custom scripts are run in the directory where config files are stored but application image can be accessed using relative platform specific path. You can derive this path from verbose output or by setting environment variable JAVAFX_ANT_DEBUG to true to keep intermediate build artifacts.
Here is sample script (contributed by John Petersen) you can use to add jre/lib/ext/sunjce_provider.jar to the application package of MyApp on the Windows platform. Script using Javascript but you could also use VBScript for Windows scripting.
<?xml version="1.0" ?>
<package>
<job id="postImage">
<script language="JScript">
<![CDATA[
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var oFolder = oFSO.getFolder(".");
var from = oFolder.path + "\\MyApp\\app\\sunjce_provider.jar";
var to = oFolder.path + "\\MyApp\\runtime\\jre\\lib\\ext";
if (!oFSO.FolderExists(to)) {
oFSO.CreateFolder(to);
}
to += "\\";
oFSO.CopyFile(from, to);
]]>
</script>
</job>
</package>
I am using maven. so how should i call this script from pom.xml that will create the jar within jre/lib/ext folder?
I am not a maven expert. The solution above is for apache ant. You will need to work out your own solution to this issue if you wish to continue using maven.
Related
I am trying to make a HTTP POST request to a server with https. When I was testing making the call I did it on a standalone java program (not deployed on a server) and initaially got the error:
unable to find valid certification path to requested target
however I fixed this with creating a cacert using a tool online called InstallCert and pointing java there with:
System.setProperty("javax.net.ssl.trustStore", "C:\\Users\\...\\jssecacerts");
However, when I implement the same fix in the code that I deploy on Apache Tomcat it doesnt work and I get the same error as before. So my question is do .war files deployed on Apache Tomcat use a different trust store than the java one? Or do they not use the system properties? How can I get Apache Tomcat to use the cacert?
Thanks
EDIT:
So I've tried to do some more research and get it fixed with no success. I tried following http://andyarismendi.blogspot.co.uk/2012/01/changing-tomcats-ca-trust-keystore-file.html to try and get it fixed.
Changing the server.xml file made no difference. However, changing the Tomcat Java Options with
-Djavax.next.ssl.trustStore="myFile"
Altered the response that I got, with this I get:
java.io.IOException: Server returned response code 500 for URL websitesURL
I also saw in some places that copying the jssecacerts file into my jre\lib\security directory could fix this. However this just cause the response code 500 error...
This is the code that is being used to make the POST Request:
//System.setProperty("javax.net.ssl.trustStore", "C:\\file\\path\\jssecacerts");
try
{
OAuthClient client = new OAuthClient(new URLConnectionClient());
//grant_type=password
OAuthClientRequest.TokenRequestBuilder trb = new OAuthClientRequest.TokenRequestBuilder(TOKEN_URL)
.setGrantType(GrantType.PASSWORD)
.setClientId(CLIENT_ID)
.setUsername(username)
.setPassword(password);
OAuthClientRequest ocr = trb.buildBodyMessage();
ocr.setHeader("Authorization", base64EncodedBasicAuthentication(CLIENT_ID, CLIENT_SECRET));
String responseBody = client.accessToken(ocr, OAuthJSONAccessTokenResponse.class).getBody();
return responseBody;
}
catch(Exception e)
{
e.printStackTrace();
return e.getMessage();
}
I'm trying to export my spring application from glassfish 4 to JBoss wildfly 8.x or 9 alpha, but when my application starts in some part of my code throws the exception:
Caused by: java.lang.RuntimeException: java.nio.file.FileSystemNotFoundException: Provider "vfs" not installed
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:218)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
... 3 more
Caused by: java.nio.file.FileSystemNotFoundException: Provider "vfs" not installed
at java.nio.file.Paths.get(Paths.java:147) [rt.jar:1.7.0_72]
at com.springmvcangular.backend.utils.entity.BaseEntityInitializer.extendsEntities(BaseEntityInitializer.java:123)
at com.springmvcangular.backend.utils.entity.BaseEntityInitializer.initializeBaseEntities(BaseEntityInitializer.java:88)
at com.springmvcangular.backend.config.ApplicationInitializer.onStartup(ApplicationInitializer.java:60)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:178)
... 7 more
in my class BaseEntityInitializer in that exception line i have:
packagepath = Paths.get(this.getClass().getClassLoader()
.getResource(path.replace('.', '/')).toURI());
where path its a package path like com.something.model, so why in my glassfish 4 server this works perfectly and what i need for use it in wildfly? i don't know what is missing in wildfly or if i need to include some library.
It happens to work by chance in GlassFish. Nowhere in the ClassLoader contract (or the Java EE platform specification) is it specified what kind of URL you get back. In the GlassFish ClasLoder it probably happens to be a jar:// or file:// URL for which there happens to be a FileSystemProvider (jar:// only by accident BTW). In WildFly the URL happens to be a JBoss VFS URL. There are various hacks that you can apply to make it work for now but they all can't hide the fact that you're relying on not portable behavior. You're better off using something like URL#openStream() instead which is portable and should therefore work everywhere.
Update
What you can try to do is doing more at compile time. Options include:
Do the transformation with Javassist at compile time. This also reduces the chances of conflicts with the Javassist shipping with WildFly.
Gather the information about the resources at compile time and store it in a file at a well known location. You can have the same file name in multiple JARs as ClassLoader#getResources(String) can return multiple results.
If you provide more specific information about the problem you're trying to solve I may be able to give more specific answers.
This is my solution how to iterate over files/directories in Wildfly:
List<String> fileNames = new LinkedList<>();
URL resourceUrl = getClass().getResource("/your/path");
VirtualJarInputStream virtualJarInputStream = (VirtualJarInputStream) resourceUrl.openStream();
JarEntry next = null;
while ((next = virtualJarInputStream.getNextJarEntry()) != null) {
fileNames.add(next.getName());
}
import org.jboss.vfs.VirtualFile; // https://mvnrepository.com/artifact/org.jboss/jboss-vfs
URLConnection connection = Objects.requireNonNull(getClass().getClassLoader().getResource("/template/cyber")).openConnection();
VirtualFile virtualFile = (VirtualFile) connection.getContent();
Stream<Path> walk = Files.walk(Paths.get(virtualFile.getPhysicalFile().toURI()));
List<String> result = walk.filter(Files::isRegularFile).map(Path::toString).collect(Collectors.toList());
I have an application named HelloWorld installed, yet not deployed. Its state is Installed, like such:
When I'm trying to deploy it on target server, say AdminServer, it results in creating a new application named helloworld.war which is deployed on AdminServer whereas the original HelloWorld app remains in Installed state. App helloworld.war is the one that is in state Active... Snapshot:
Here's the code I use to deploy the already installed app:
File warFilePath = new File("c:/helloworld.war"); // war file path on AdminServer machine
Target adminServerTarget = deployManager.getTarget("AdminServer");
WebLogicTargetModuleID targetModuleID = deployManager.createTargetModuleID(
"HelloWorld", ModuleType.WAR, adminServerTarget);
WebLogicTargetModuleID[] targetModuleIDs = new WebLogicTargetModuleID[1];
targetModuleIDs[0] = targetModuleID;
ProgressObject redeployProcessObject =
deployManager.redeploy(targetModuleIDs, warFilePath, null /*no deployment plan*/ );
There are two surprising facts, though.
First, when running this code on WebLogic versions 9.x to 10.3.3 it works great.
Second, when running this code from WLST prompt, with jython it also works great even on version 10.3.4 (I can attach the exact commands although they're the same as java except for syntactic adoptions)...
My question is, how do I make it work also on 10.3.4?
I should have thought that no one would answer this question... :)
Anyway, I found a solution. I should have used deploy instead of redeploy, with a DeploymentOptions of which name is the existing application name (HelloWorld):
ProgressObject redeployProcessObject = null;
try {
final DeploymentOptions options = new DeploymentOptions();
options.setName(applicationName);
redeployProcessObject = deployManager.deploy(
targetModuleIDs, warFilePath, null /*no deployment plan*/, options);
} catch (TargetException e) {
final String message =
String.format("Deployment of application %s on target %s failed: %s",
applicationName, allTargets, e.getMessage());
_log.error(message, e);
}
According to the docs, redeploy only replaces the current application files and plan with an updated version. Whereas deploy distributes the files (from the AdminServer) to the target(s) and starts the application.
Also, after digging deep in WebLogic's jython scripts and jars I found out that this is exactly what's done when invoking redeploy in the WLST.
I am having trouble setting up the Php-Java Bridge setup properly.
I will explain what I have done.
My site is in pure php
For our payment transaction process we need to set up a php-java bridge
I followed this link to setup the bridge PHP-JAVA BRIDGE INSTALATION.
Here I learned that I need to have a private jvm to install the bridge.
So 1st i installed apache-tomcat-6.0.14 in Private JVM using my c-panel. After instalation it asked me to Map a domain to private JVM. So I mapped my domain example.com (which is the only option available) to it.
Then it asked to enable a traffic redirection from Apache web server to my Java application server (there was a check box and i clicked it)
Finally it asked me to deploy the WAR File (JavaBridge.WAR was my file) and everthing seems fine
Now when i go to http://example.com/JavaBridge/ I could see the javabridge examples and it works fine.
SO FAR SO GOOD
Now my problem starts here when I try to access a java class file from php. A sample test.php is what I create and put the following code into it.
<?php
require_once("http://example.com:portnumber/JavaBridge/java/Java.inc");
$System = java("java.lang.System");
echo $System->getProperties(); //This Part echo's correctly and shows the data so it means i can access Java.inc Correctly
$path_e24class = getcwd(). '/e24PaymentPipe.class'; //This part fails both test.php and java class file e24PaymentPipe.class are in the same directory in publich_html folder
java_require($path_e24class);
$pipe = new Java("e24PaymentPipe");
$pipe->setAction("1");
?>
My site contents reside in the public_html folder and the WAR file are deployed in private jvm.
These are the error message am getting.
1) Warning: java_require() not supported anymore. Please use tomcat or jee hot deployment instead
Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new e24PaymentPipe. Cause: java.lang.ClassNotFoundException: e24PaymentPipe VM: 1.6.0_22#http://java.sun.com/" at: #-10
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) #-9
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) #-8
java.lang.Class.forName0(Native Method) #-7
java.lang.Class.forName(Class.java:247) #-6
php.java.bridge.Util.classForName(Util.java:1518) #-5
php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445) #-4
php.java.bridge.Request.handleRequest(Request.java:458) #-3
php.java.bridge.Request.handleRequests(Request.java:500) #-2
php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1
php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) #0
http://example.com:portnumber/JavaBridge/java/Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(3, 'java.util.Prope...', 'T', false) #1
Finally I don't know much about the java. So am stuck here not knowing what to do.
Here is a great step by step tutorial you can follow, which shows everything required! It is a little old (2007) but helped me a while ago.
There is also another option. You can install Apache Tomcat and deploy your war there. You can have even multiple tomcat instances simultaneously with your httpd running at the same time on the same machine, as long as you respect the port settings. You can even front them with Apache httpd.
you can try this:
package your code to jar, and copy it to java.ext.dirs which you can found in JavaBridge.log
copy the related class libraries to java.ext.dirs
restart the service of JavaBridge
good luck!
<?php require_once("JavaBridge/java/Java.inc");
try {
$hd = new java("hdfs.HDFS");
$hd->get("hdfs://master:9000/user/hadoop/test-in/logo_cn.png", "/home/hadoop/1.png");
} catch (JavaException $ex) { echo "An exception occured: "; echo $ex; echo "<br>\n";}
?>
You can use this php implementation on github that works with php 5.3.
See credits on the git readme for more information.
You can try this; put the JavaBridge.jar in tomcat's lib folder e.g. apache-tomcat-7.0.12/lib.
Restart tomcat server and then,
$pipe = new java("com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe");
$pipe->setAction("1");
This way I created the php version of the object.
Why don't you put the e24PaymentPipe class in your Java application's classpath and skip the two lines below:
// $path_e24class = getcwd(). '/e24PaymentPipe.class';
// java_require($path_e24class);
$pipe = new java("fully.qualified.classpath.e24PaymentPipe");
You are mixing PHP side and Java side operations. in theory the java_require (which is deprecated) was designed to work on the Java side. You are specifying a PHP side path.
You can save yourself a lot of grief by using a pure PHP implementation of the e24PaymentPipe library.
Disclaimer
The link is to my github repo of the library, but I did not write it. See the readme in for original credits.
I have downloaded MySQL JDBC driver from http://www.mysql.com/downloads/connector/j/. How do I configure it?
To the point, you just need to put it in the program's runtime classpath and then load it as follows:
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new RuntimeException("Cannot find the driver in the classpath!", e);
}
If you're using an IDE, then you need to add the library to the project's Build Path. If you're running it using java.exe, then you need to specify the full path to the JDBC driver JAR file in the -cp argument, e.g. (Windows-targeted):
java -cp .;/path/to/mysql-connector-java-5.1.12.jar com.example.YourClass
For more information and hints check this small MySQL+JDBC kickoff tutorial.
Update: As per the comments, you're using Flex and you apparently want to interact with the DB at the server using Flex. Well, Flex runs at the client machine and Java + the DB runs at the server machine. Both are connected by network with HTTP as communication protocol. You need to write Java code on the server side accordingly (Servlet? Webservice?) which interacts with the DB based on the parameters/pathinfo given with the HTTP request and returns the desired results. Then you can just invoke HTTP requests from inside Flex and process the HTTP response.
You can follow the guidelines given at: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-installing.html.
Also check the comments for more ideas and info. I.e: putting it in [PATH_TO_JAVA]/jre/lib/ext/ (on Win Mashine) or /Library/Java/Extensions (Mac OS X) etc.
Refer < http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html> or
The JDBC .jar file needs to be added to the library, this can be done by adding it manually to '...jre\lib\ext' folder of your Java installation. It will be automatically included in the default library available to every project you create.