SOAP Web service need to send request using https protocol in java - java

I need to send request to my web service using https protocol.
Using SOAP UI it's working fine and providing response for https request as well however if i am sending https request it's providing below exception
javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://abc:8443/xyz/FileTransferService?wsdl. It failed with:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:184)
at ##com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:166)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:131)
at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:267)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:230)
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(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1497)

If you want to use https, you just download the wsdl first, and make the wsdlLocation and url in your generated client class point to that file.
or generate your client like this
URL url = new URL("https://......?wsdl");
QName qname = new QName("NameSpace of the Service", "ServiceName");
Service service = Service.create(url, qname);
ServiceClass port= service.getPort(ServiceClass.class);
then you could can start to use the port.
You can find the example of later one in the website.
http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat-ssl-connection/
Oh, I forgot one thing. You have to add trust key in your java keystore. The following website shows the way to do it.
http://java.globinch.com/enterprise-java/security/pkix-path-building-failed-validation-sun-security-validatorexception/

I know it is a quite old question but maybe an answer is never bad.
Normally this happens when the JVM cacerts file does not contains the root CA's certificate who signed your server SSL certificate. But be careful which JVM is running so which cacerts file you should edit. You can find the cacerts file under $JAVA_HOME/jre/lib/security/
If you are using glassfish 3 you should edit the cacerts.jks file under your specific domain config directory and not in the common JVM runtime folder.
Probably you have switched off the SSL certificate check in your SOAP UI.

Related

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I am trying to connect to a mail server and read my inbox. My code works for gmail but does not seem to work with my exchange server because of the error:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
I have tried the following as per my research:
1. downloaded the InstallCert.java and ran the folllowing command:
java InstallCert mail.simbatech.biz:993
and imported the one certificate that came in, I afterwards copied the jssecacerts file to jre/lib/security directory of my java Installation but the same error still persists. Is there Any other way to do this?
It sounds like you're doing the right things, but apparently your application is not using the certificate file you created. Where is your application running? If it's running in an application server, the server may be overriding the trust store configuration and may thus be ignoring your jssecacerts file. Try enabling additional debug output as described in the JavaMail FAQ.

Getting error: PKIX path building failed: unable to find valid certification path to requested target

I'm trying to send a xml to another system via web service. But while trying to send i'm getting the following error. I've installed the certificate they gave to me. but still its not working.
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
There are two possible sources for this error:
either the opposite side is using genuinely untrusted certificate (self-signed or signed by untrusted CA),
or the opposite side is not sending certificate validation chain (e.g. there is intermediate signing certificate along the way to your trusted CA, but this ceriticate is not present in the SSL handshake).
Solution for the first case is to add the untrusted CA (or the ceriticate itself) to your JRE truststore (${java.home}/lib/security/cacerts) or better - create your own truststore (which will not get removed when upgrading Java) and provide that to your application via javax.net.ssl.trustStore JVM property.
Solution for the second case is either to go with the first case solution or better - convince the opposite side to send correct certificate chain.
Add certificate to JRE truststore # ${java.home}/lib/security/cacerts OR if you have your own trustStore & provide path to that in your application/JVM. For example one possible way could be
or via java code
import java.util.Properties;
...
Properties systemProps = System.getProperties();
systemProps.put("javax.net.ssl.keyStorePassword","passwordForKeystore");
systemProps.put("javax.net.ssl.keyStore","pathToKeystore.ks");
systemProps.put("javax.net.ssl.trustStore", "pathToTruststore.ts");
systemProps.put("javax.net.ssl.trustStorePassword","passwordForTrustStore");
System.setProperties(systemProps);
...
For more refer to details on RedHat site
May be it will help refer to question

GlassFish connecting to SLL web service

I have a web app running on GlassFish v3 locally. The app connects to a REST web service that is on another server (not local). The connection is done through HTTPS. While trying to connect I get:
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
I added the cert from the external ws directory to the local java keystore but that did not fix the problem.
Do I have to instruct GlassF to use the local keystore or something ? Or just by adding it to the java keystore it should work for the local GlassF too ?
You have two options:
1.) Replace the cacerts in the $JAVA_HOME/jre/lib/security directory with your keystore.
2.) Change the keystore at runtime like this:
System.setProperty("javax.net.ssl.keyStore", <path to the new keystore>);
System.setProperty("javax.net.ssl.keyStorePassword",<password of the keystore>);
System.setProperty("javax.net.ssl.trustStore",<path to the new keystore>);
Hope that helps!
EDIT: You might find this question helpful as well. The selected answer suggests to:
1.) Copy your keystore file to C:\glassfish3\glassfish\domains\domain1\config\
2.) Configure GlassFish to use SSL

org.apache.axis2.AxisFault: sun.security.validator.ValidatorException:

org.apache.axis2.AxisFault: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I am getting the baove exception, i know it is because it is not able to find the certificates.
when i created a new JKS file with only the certificate enteries provided by the 3rd party and setting in system.setProperty("javax.net.XXXX") it works.
But due to this my other functionalities in application does not work as it is not able to find any certificate.
so i created jssecacerts using class file and imported the two certificates as well, but pointing and setting in system properties this jssecaerts file, it does not work and rest everything works fine.
What could be the issue..???
You could add your additional certificates for use by Axis2 in your own X509TrustManager and build an SSLContext from it. This is described in this answer.
Then you would have to pass the subsequent SSLSocketFactory to Axis2 using an Apache HttpClient 3.x SecureProtocolSocketFactory (see the Axis 2 documentation on the subject).

Intellij IDEA - Webservices client from WSDL with certificates

I am somewhat new to SSL/TLS and Java trust/keystores. I am attempting to generate a client to consume a web service from a IIS-hosted WSDL file. This worked fine before the service was configured to require certificates. I now receive a Wsdl url connection exception.
In an attempt to bypass this, I saved a local copy of the WSDL via IE (with the appropriate certs in place via the Certificates MMC snap-in). I then attempted to point IDEA to that location (file:/C:/projects/wsdl/wsdlname.wsdl).
This fails with the following error messages:
parsing WSDL...
[ERROR] sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid
certification path to requested target unknown location
[ERROR] invalid entity name: "Auth" (in namespace: "******")
line 0 of unknown location
Note: I've starred out the namespace.
Is there a way to configure IntelliJ IDEA to be able to present a valid certificate if I want to use the generation utility/wizard?
Is there a potential issue with the web service that is causing even the local WSDL import to fail?
Thanks in advance.
It should help if you install the certificate into JVM that is used to run IDEA via keytool.

Categories