401 error when consuming a Web service with HTTP Basic authentication using CXF?

According to HTTP basic authentication with JAX-WS (Client).

According to HTTP basic authentication with JAX-WS (Client): 2. The service class creation A constructor of the service object requires access to the WSDL. And again it does not support basic authentication out of the box.

You have an option to download the wsdl file and use it locally. Another option is to use the default authenticator: Authenticator. SetDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( USER_NAME, PASSWORD.toCharArray()); } }).

Excellent! That has definitely got me further, I'm now getting a "MessageCreationException: Couldn't create SOAP message due to exception: XML reader error: javax.xml.stream. XMLStreamException: ParseError at row,col:1,1".

Any idea on what might be the issue here? – seanhodges Jun 14 '10 at 13:08 Oh, and I used the Authenticator.setDefault() approach. Using the wrong user/password fails as expected, so it looks like it is nearly working... – seanhodges Jun 14 '10 at 13:10 Thanks, guys!

It worked for me too. This site has the best answers! – Grigory Nov 5 '10 at 13:22 @Grigory: Glad it helped.

– Pascal Thivent Nov 6 '10 at 9:30.

Just a point of note, you aren't using CXF. You are using the JAX-WS reference implementation built into the JDK. With CXF, you CAN use Spring config for everything and not set the default Authenticator.

See the page at: cxf.apache.org/docs/client-http-transpor... about the http-conf:authorization settings.

Thanks, I was inadvertently using JAX-WS. The Spring info will come in useful later too. Just wish I could mark 2 answers as accepted :) – seanhodges Jun 21 '10 at 16:19.

Related Questions