Monday, August 27, 2007

java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode

My battles with CXF continues :-) I was calling a web service, which was protected by basic authentication, and even though I did set username and password, I got this exception:
java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode

Hmm. A google on that exact string turned up nothing. After some searching around, I got to a solution. It has to do with "chunked transfer encoding", which can be set on HttpURLConnection. In my case, I turned this off in code, by doing this against the CXF API:
FooService service = new FooService();
Foo port = service.getFoo();
Client client = ClientProxy.getClient(port);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();

HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpConduit.setClient(httpClientPolicy);
It is the last three lines, that did the trick. It turns off the use of chunking inside HTTPConduit.

7 comments:

Anonymous said...

you rock! :P
I was having the same problem, and this solved it. thanks.

dain said...

I got this same exception message but it was caused by the server side using basic auth. In my case all I had to do was set the username and password on the proxy.

MyPort port = ...;
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
bindingProvider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");

Rick said...

And i was also having the same problem and adding the BindingProvider user/password finally got it working.
Thank you

Anonymous said...

Even I had the same problem and this solved it.
Thank you.

Anonymous said...

Awesome ! I was struggling with the same problem. Thanks to you, now its resolved. :).

Regards,
Varun

Sam said...

Thanks! Exactly what i was looking for

Anonymous said...

you are hero :)

my problem solved with your solution.