简体   繁体   中英

Getting “peer not authenticated” while using google map api's

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM