1

My code

SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
            SOAPConnection conn = scf.createConnection();

            // Create message
            MessageFactory mf = MessageFactory.newInstance();
            // SOAPMessage msg = mf.createMessage();

            String urlval = "backend url";

            SOAPMessage rp = conn.call(sOAPMessage, urlval); //here I'm getting exception

            System.out.println("\nXML response\n");

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            rp.writeTo(out);
            String strMsg = new String(out.toByteArray());

            String soapResponse = strMsg.replaceAll("&", "&");

            System.out.println(soapResponse);

            // Close connection
            conn.close();

Error

    com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
SEVERE: SAAJ0009: Message send failed
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
    at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source)
    at test.WebServiceUATTest.sendSoapMessage(WebServiceUATTest.java:96)
    at test.WebServiceUATTest.main(WebServiceUATTest.java:143)
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
    at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source)
    ... 3 more
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
    at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
    at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
    at sun.security.ssl.Handshaker.processLoop(Unknown Source)
    at sun.security.ssl.Handshaker.process_record(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
    ... 4 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
    at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
    at sun.security.validator.Validator.validate(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    ... 17 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
    at java.security.cert.CertPathBuilder.build(Unknown Source)
    ... 23 more
  • stack trace already there...and added code..pl see. – Paddy02 Jul 11 '18 at 10:30
  • Please show us exception stacktrace since it is not clear where the exception was originated from. – Alexey R. Jul 11 '18 at 10:31
  • What is the relation with this question and testing or QA? – Patrick Jul 11 '18 at 10:37
1

You get this error because you're trying to access your service endpoint by HTTPS protocol however SSL certificate that is returned by the service cannot be verified (it cannot be considered trusted). Here you have several options how to resolve your issue:

  1. Download server certificate and add it to a storage of trusted certificates that is used by the jre you run your app under. See this post for details
  2. You can amend your code so that it would trust all the certificates you get. See this post for details (Trust all hosts section).
  3. You can ask the owners of the service to run it over HTTP as well so there will be no need to validate any certificate since certificates are not used for HTTP connectivity.

The last point is the simplest one in terms of your efforts, the first one is a kind of balance between your efforts and the efforts of your folks.

  • thanx alexey..will try this solution... – Paddy02 Jul 16 '18 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.