Search code examples
javacertificateglassfish

Getting 'Unable to find valid certification path to requested target' in Glassfish but not in standalone Java App


Working with Eclipse IDE, given the following class, from which I omit everything unnecessary:

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceClient;
//...

@WebServiceClient
public class CustomService extends Service {
    
    public CustomService(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    //...   
}

When it is invoked from the 'main' method of another standalone class, when passing through the line super(wsdlLocation, serviceName), it works correctly.

BUT, when it is invoked from a class that is executed upon Glassfish loading, when passing through the line super(wsdlLocation, serviceName), it throws the following exception:

com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.

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
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

How to solve it?


Solution

  • Here is the solution that works in my case:

    From EDGE explorer, I had to access the WSDL URL and export the certificate.

    enter image description here

    enter image description here

    enter image description here

    Move it to the config path of Glassfish (C:\PROYECT\glassfish4\glassfish\domains\domain1\config), and from there, import it.

    keytool -import -trustcacerts -alias DigiCert_Global_Root_G2 -file "DigiCert Global Root G2.crt" -keystore cacerts.jks