Topic
  • 1 reply
  • Latest Post - ‏2012-02-28T18:24:58Z by GHS9_Michael_Lee
GHS9_Michael_Lee
GHS9_Michael_Lee
2 Posts

Pinned topic IBM JAX-WS Standalonoe Client Adding HTTP HEADER for Basic Authentication

‏2012-02-28T15:59:23Z |
Hi,

I am looking for a help to figure out how to set HTTP Header for a basic authentication with IBM JAX-WS.
Now the current Axis2 client is using HTTPAuthenticator to add "Authorization: Basic cml3ZXJab7NrOnRlc9Q5OQ=="
I have tried to do the same thing using IBM JAX-WS as following, but no luck so far.

Alternative #1:
Map<String, Object> aHttpHeader = new HashMap<String, Object>();
aHttpHeader.put("Username", "abcd");
aHttpHeader.put("Password", "abcd123");
aProxy._getDescriptor().getDispatch().getRequestContext().put(
com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES, aHttpHeader);

Alternative #2:
myService service = new myService();
myServicePortType proxy = (service.getmyServicePort());
((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "userfoo");
((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "passbar");

Alternatvie #3:
Map<String, List<String>> bHttpHeader = new HashMap<String, List<String>>();
bHttpHeader.put("Username", Collections.singletonList("userfoo"));
bHttpHeader.put("Password", Collections.singletonList("passbar"));

aProxy._getDescriptor().getDispatch().getRequestContext().put(
MessageContext.HTTP_REQUEST_HEADERS, bHttpHeader);

These three options did not work at all.
It is a standalone JAX-WS client using IBM jaxws thinclient v7.0.0.

Please help this to migrate from Axis2 to IBM JAX-WS.

Best regards,

Michael
Updated on 2012-02-28T18:24:58Z at 2012-02-28T18:24:58Z by GHS9_Michael_Lee
  • GHS9_Michael_Lee
    GHS9_Michael_Lee
    2 Posts

    Re: IBM JAX-WS Standalonoe Client Adding HTTP HEADER for Basic Authentication

    ‏2012-02-28T18:24:58Z  
    I just figured out. It should get BindingProvier to set new properties in the request context.

    myServicePortType aPortType = aProxy._getDescriptor().getProxy();
    ((BindingProvider)aPortType ).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "abc");
    ((BindingProvider)aPortType ).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "abc99");

    Now I can see the basic authentication header.