title: JaxB not Unmarshalling due to SSL error on cloud foundry?
body: <p>I have an web application, Using thymeleaf, springboot, angularjs, and oracle sql developer db. </p>
  
  <p>Locally I am able to connect and get values from oracle. But when I push my application to cloud foundry, I am getting status=500.</p>
  
  <p><strong>ERROR</strong></p>
  
  <p>The url that I am unmarshalling has a untrusted certificate ("Your connection is not secured)". I added cacerts into my jvm, which allowed it to work locally. but I believe I need to add the cacerts into cloud foundry. How would I be able to do so? </p>
  
  <p><strong>SSL error</strong></p>
  
  <pre><code> ERR java.net.ConnectException: Connection timed out  
   ERR at java.net.PlainSocketImpl.socketConnect(Native Method)  
   ERR at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)  
   ERR at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)  
   ERR at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)  
   ERR at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)  
   ERR at java.net.Socket.connect(Socket.java:589)  
   ERR at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)  
   ERR at sun.net.NetworkClient.doConnect(NetworkClient.java:180)  
   ERR at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)  
   ERR at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)  
   ERR at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)  
   ERR at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)  
   ERR at sun.net.www.protocol.https.HttpsClient.&lt;init&gt;(HttpsClient.java:264)  
   ERR at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)  
   ERR at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)  
   ERR at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)  
   ERR at rest.springframework.controllers.IndexController.getDetails(IndexController.java:59)  
   ERR at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
   ERR at java.lang.reflect.Method.invoke(Method.java:498)  
   ERR at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)  
  </code></pre>
  
  <p><strong>ERR at rest.springframework.jaxb.JAXSample.readXML(JAXSample.java:34)</strong>  </p>
  
  <p><strong>Reason</strong></p>
  
  <p>I removed jaxB unmarshalling from my application and uploaded into cloud foundry and I was did not get status=500. How can I add SSL to prevent this from happening?</p>
  
  <p><strong>JaxB Sample</strong></p>
  
  <pre><code>public deviceCert readXML(String MAC) throws MalformedURLException {
    results customer = null;
    deviceCert dcert = null;
    String APPKEY = "Production";
  
    try {
        JAXBContext jaxbContext  = JAXBContext.newInstance(results.class);
        //line 34 is below VV.
        URL url = new URL("https://untrusted.page.that.I.Am/unmarshalling" + "?mac=" + MAC + "&amp;app_key=" + APPKEY);
  
        HttpURLConnection http = (HttpURLConnection) url.openConnection(); 
  
        http.addRequestProperty("User-Agent", "Mozilla/4.76"); 
        InputStream is = http.getInputStream();
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        customer = (results) jaxbUnmarshaller.unmarshal(is);
  
        List&lt;deviceCert&gt; dcerts = customer.getDcerts();
        dcert = dcerts.get(0);
  </code></pre>
  
  <p>Found related link <a href="https://stackoverflow.com/questions/39391896/pivotal-cloud-foundry-security-certificates?rq=1">here</a></p>
  
  <p>I followed <a href="https://docs.cloudfoundry.org/cf-cli/self-signed.html" rel="nofollow noreferrer">CF CLI SSL</a> But that did not do the trick.</p>
  
  <p><strong>Attempt</strong></p>
  
  <ol>
  <li>Created folders resources/config/truststore in my application.</li>
  <li>Added Cert.cer into truststore folder.</li>
  <li>Pushed app to cloud foundry.</li>
  <li>cf set-env my-app JAVA_OPTS '-Djavax.net.ssl.TrustStore=classpath:resources/config/truststore'</li>
  </ol>
  
  <p><em>Same error nothings changed.</em></p>
  
  <p><strong>Attempt 2</strong></p>
  
  <pre><code> &lt;dependency&gt;
    &lt;groupId&gt;io.pivotal.spring.cloud&lt;/groupId&gt;
    &lt;artifactId&gt;cloudfoundry-certificate-truster&lt;/artifactId&gt;
    &lt;version&gt;1.0.1.RELEASE&lt;/version&gt;
   &lt;/dependency&gt;
  </code></pre>
  
  <ol>
  <li><p>added dependency</p></li>
  <li><p>Repackaged app, upload to cf.</p></li>
  <li><p>Added environment variable on cloud foundry </p>
  
  <p>CF_TARGET=<a href="https://api.my-cf-domain.com" rel="nofollow noreferrer">https://api.my-cf-domain.com</a></p>
  
  <pre><code>           //url of my secured/untrusted page
  </code></pre></li>
  </ol>
  
  <p><a href="https://github.com/pivotal-cf/cloudfoundry-certificate-truster" rel="nofollow noreferrer">Github example</a></p>
  
  <p><strong>New StackTrace error</strong></p>
  
  <pre><code>ERR at java.util.concurrent.FutureTask.get(FutureTask.java:205)
  ERR at io.pivotal.springcloud.ssl.SslCertificateTruster.getUntrustedCertificateInternal(SslCertificateTruster.java:90)
  ERR at io.pivotal.springcloud.ssl.SslCertificateTruster.getUntrustedCertificate(SslCertificateTruster.java:66)
  ERR at io.pivotal.springcloud.ssl.CloudFoundryCertificateTruster.trustCertificatesInternal(CloudFoundryCertificateTruster.java:44)
  ERR at io.pivotal.springcloud.ssl.CloudFoundryCertificateTruster.trustCertificates(CloudFoundryCertificateTruster.java:32)
  ERR at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:420)
  ERR at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:403)
  ERR at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:394)
  ERR at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:261)
  ERR at org.springframework.boot.SpringApplication.&lt;init&gt;(SpringApplication.java:237)
  ERR at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
  ERR at rest.springframework.SpringBootWebApplication.main(SpringBootWebApplication.java:13)
  ERR at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  ERR at java.lang.reflect.Method.invoke(Method.java:498)
  ERR at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
  ERR at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
  ERR at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
  </code></pre>
  
  <p>Why does this work find locally but not on the cloud?</p>