Netbeans Basic Http Auth Jax-WS

How can I access the web service through basic HTTP authentication? I use netbeans built-in to the webservice client functions. But when I try to access the web service, I get an exception with an error message with error 401 auth.

How can I pass the correct username and password?

Thanks!

+5
source share
2 answers

You can use the BindingProvider or WSBindingProvider class to access the web service through basic HTTP authentication. The code is as follows.

XxxService service = new XxxService();
Xxx port = service.getXxxPort();

Map<String, Object> reqContext = ((BindingProvider)port).getRequestContext();
reqContext.put(BindingProvider.USERNAME_PROPERTY, "username");
reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password");
+4
source

. , , WDSL HTTP-.

@WebServiceRef(wsdlLocation = "https://laka/sito?wsdl")
static XxxService service;

public static void main(String[] args) {

    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("user", "password".toCharArray());
        }
    });

    service = new XxxService();
    Xxx port = service.getXxxPort();

    // invoke webservice and print response
    XxxResponse resp = port.foo();
    System.out.println(resp.toString());

}
+3

All Articles