Search code examples
grailscommand-linewsdlcxf

wsdl2java CXF command line error about disableCNCheck option


I'm using CXF wsdl2java command line tool to generate Java classes from a WSDL under https connection. Everything goes fine during generation, but when i call one of the services offered by the WSDL I get this exception:

java.io.IOException: The https URL hostname does not match the Common Name (CN) on the server certificate. To disable this check (NOT recommended for production) set the CXF client TLS configuration property "disableCNCheck" to true.

Is this disableCNCheck something I can set during java classes generation? It seems not, or at least it's not a valid option for wsdl2java.

Is it something I have to specify in the wsdl or in my (grails) application, which uses the generated java classes?


Solution

  • It turns out that is not something about generation time, but runtime stuff.

    To set the disableCNCheck flag, I did it this way:

    protected void disableCNCheck(Object port) {
        Client client = ClientProxy.getClient(port)
    
        TLSClientParameters params = new TLSClientParameters()
        params.setDisableCNCheck(true)
        HTTPConduit httpConduit = (HTTPConduit) client?.getConduit()
        httpConduit?.setTlsClientParameters(params)
    }
    

    where port is the object used to talk with the SSL-protected API service.