I use Netbeans to generate web service client code, client-style JAX-WS, so i can invoke a web service API.
However, when I invoke the web service API, I get the exception: com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 307: Temporary Redirect
Why do I get this? What is the workaround? I know the problem isn't with the web service itself, because I can get responses fine via soapUI and .Net.
Faced the same problem about a month ago.
Web service client classes were generated using Apache CXF and web service returned HTTP status 307, which led to the same exception.
Invocation of the same web service method using soapUI with property
Follow Redirects
set totrue
was successful and returned needed data.After googling awhile, it looked like there is no property to enable following redirects in the JAX-WS for this.
So, below is the code which is currently working, though I'm not sure it is compliant with any standards:
Supposing generated client classes looks like:
Now, upon executing following code:
wsClient
should return instance which is both instance ofRetrieveMyObjects
&javax.xml.ws.BindingProvider
interfaces. It is not stated anywhere on the surface of JAX-WS, but it seems that a lot of code is based on that fact. One can re-assure him\herself by executing something like:Now, when we are sure that
retrieveMyObjectsPort
is instance ofjavax.xml.ws.BindingProvider
we can send plain HTTP POST request to it, simulating SOAP request (though it looks incredibly incorrect & ugly, but this works in my case and I didn't find anything better while googling) and check whether web service will send redirect status as a response:Now, what this method does is: it takes
BindingProvider.ENDPOINT_ACCESS_PROPERTY
ofretrieveMyObjectsPort
i.e. the url to which this port method will be sending SOAP requests and sends plain HTTP POST request as described above. Then it checks whether response status is307 - Temporary Redirect
(other statuses like 302 or 301 may also be included) and if it is, gets the URL to which web service is redirecting and sets new endpoint for the specified port.In my case this
checkRedirect
method is called once for each web service port interface and then everything seems to work fine:http://example.com:50678/restOfUrl
https://example.com:43578/restOfUrl
(please note that web service client authentication is present) - endpoint of a port is set to that urlDisclaimer: I'm quite new to webservices and this is what I managed to achieve due to the lack of solutions for this questions, so please correct me if something is wrong here.
Hope this helps
Yes I know this post is old, but I've had similar errors, and thought maybe somebody would benefit from my solution.
the one that plagued me the most was:
Which turns out to mean an incomplete response header. Apparently jax-ws does some kind of validation that includes validating the HTTP headers as well. And the server I was using was just sending an empty header.
It worked like a charm after adding
'application/soap+xml'
to theContent-Type
header.