This discussion is archived
0 Replies Latest reply: Jun 7, 2013 2:45 AM by Ramon RSS

Basic authentication in client on WLS

Ramon Newbie
Currently Being Moderated
Hello all,

I've been breaking my head over an issue with a webgui that I am creating with Java servlets involving a web service.

I am accessing this service using JAX-WS, but the issue is that the service requires basic authentication on both the WSDL and the methods. There are many resources online describing how you can solve this using a default authenticator and using Sun's http handler, but I cannot get it working on Weblogic Server 10.3.6.0.

If I create a unit test in my project with the mentioned solutions applied it runs like a charm, but as soon as I deploy it to WLS I get 401 unauthorized messages.

A small example:

Authenticator.setDefault(new Authenticator() {
     @Override
     protected PasswordAuthentication getPasswordAuthentication() {
     return new PasswordAuthentication(
          "username",
          "password".toCharArray());
     }
});
URL url = new URL(null, "http://myhost:5301/myservice?wsdl", new sun.net.www.protocol.http.Handler());
QName qname = new QName("http://myhost", "myservice", XMLConstants.DEFAULT_NS_PREFIX);
MyService service = new MyService(url, qname);

The 401 is thrown at the last line (creation of the service), which does not yet make an actual call. Most other solutions mention to add the username and password to the requestcontext, but that is only applicable after you create the service-object and get a port from it.

Does anybody have any idea?

Regards,

Ramon

Edited by: Ramon on 7-jun-2013 11:44

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points