Search code examples
javahttpsjax-ws

Jax-ws with https url ends up as http


I am attempting to call a webservice (developed in C#) using JAX-WS, over https. I have tried setting up an invocation through SoapUI, and this works.

But, when trying to do the same through a generated jax-ws client, all I get is a 301 response back. This is similar to what I get using SoapUI with a http url to the same service, and also wireshark tells me that I do a HTTP (HTTP/XML) POST operation. This leads me to belive that for some reason, my generated JAX-WS client attempts to invoke over http, instead of https.

Examplified code:

 new MyServiceInterface(new URL("https://acme.com/services/MyService.svc?wsdl"))
                       .getMyPort().test();

As you can see, I supply a https url when creating my client. Is there anything else needed in order to make sure that JAX-WS uses https? The namespace URIs are all http, could this cause problems?

Update:

I have implemented a SOAP-request for the service in quesiton using the guide from the accepted answer here: Working Soap client example Pretty much repeated the information from SoapUI, and now it gives me the a proper 200 response.

Update 2:

When debugging my JAX-WS-client, I find this property:

"javax.xml.ws.service.endpoint.address" -> "http://acme.com/services/MyService.svc"

This has http, not https. Relevant?

Update 3:

When using the debugger to change "javax.xml.ws.service.endpoint.address" to the https url, rather than http, my client works. But why is it http to begin with?


Solution

  • One cause could be if the WSDL referenced an http URL.

    new MyServiceInterface(new URL("https://acme.com/services/MyService.svc?wsdl")) .getMyPort().test();

    I'd suggest downloading https://acme.com/services/MyService.svc?wsdl and looking at the <address> or endpoint within the <service>. If it looks like this:

    <soap:address location="http://acme.com/services/MyService.svc"/>
    

    That could account for what you are seeing in the javax.xml.ws.service.endpoint.address.

    If that's the case and you cannot control/fix the remote WSDL, you may need to programmatically override the endpoint:

    MyServicePort myPort = new MyServiceInterface(new URL("https://acme.com/services/MyService.svc?wsdl")).getMyPort();
    // set endpoint to use https
    String endpointURL = "https://acme.com/services/MyService.svc";
    BindingProvider bp = (BindingProvider) myPort;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
    myPort.test();