I have a Web Service developed with JAX-WS. I have secured the web service with BASIC authentication configured in Tomcat.
When I try to access the web service using a Java client, I first need to create the port, and then specify the credentials, as follows:
CustomerServiceClient customerServiceClient = new CustomerServiceBottomUpService(); //1
CustomerService customer = customerServiceClient.getCustomerServicePort(); //2
Map<String, Object> context = ((BindingProvider) customer).getRequestContext(); //3
context.put(BindingProvider.USERNAME_PROPERTY, "kermit"); //4
context.put(BindingProvider.PASSWORD_PROPERTY, "thefrog"); //5
The problem I have is that, after line 1, I get an Authorization error (HTTP 401) as I obviously haven't provided the server with the credentials yet.
I am creating the client artifacts from a server WSDL, hence the authentication problem when creating the service, and don't want my clients to store the WSDL locally as it's just annoying for them. How can I get around this problem?