0 Replies Latest reply on Jun 7, 2013 9:45 AM by Ramon

    Basic authentication in client on WLS

      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

      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() {
           protected PasswordAuthentication getPasswordAuthentication() {
           return new PasswordAuthentication(
      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?



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