I’m trying to insert user credentials into an HTTP request header which is then sent via https to a web service, which in turn reads them for authorization purposes…
Client and Service are both written in Java.
On the client side I do the following:
ExampleImplService service = new ExampleImplService();
Example port = service.getExampleImplPort();
Map<String, Object> reqContext = ((BindingProvider) port).getRequestContext();
Map<String, List<String>> reqHeader = new HashMap<String, List<String>>();
reqHeader.put("Username", Collections.singletonList("user"));
reqHeader.put("Password", Collections.singletonList("password"));
reqContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeader);
System.out.println(port.somemethod());
If I dump the reqContext after my additions programmatically I see the added headers. But via tcpmon, I can see, that they are not send to the web service… Naturally I can’t find them anywhere in the web service either.
Any idea what I’m doing wrong?
I believe you are using jax-ws for web service consumption so my answer will be oriented to it
You can set the username and password properties like this
If that doesn’t work, you may need an Authenticator ( Doesn’t work with Axis2 )
copied from here