How to add http-headers to all outcome jax-ws client's requests on websphere(WAS)?

I want websphere WAS to add my "Authorization:blabla" http-header to all my jax-ws client request to the service. I've read a lot of topics, but anything doesn't work. I have a jax-ws client deployed on websphere. I've created my own application poliicy set and attached on my service and created General client policy set binding with my authorization HTTP-header in custom properties of HTTP-transport. I attached my policy and binding to my client service, but it doesn't work. Every time I get the following exception:

00000023 SOAPOverHTTPS E   WSWS7263E: The following exception occured: org.apache.axis2.AxisFault: HTTP ( 401 ) Unauthorized address :
    at org.apache.axis2.engine.AxisEngine.send(
    at org.apache.axis2.description.OutInAxisOperationClient.send(
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(
    at org.apache.axis2.client.OperationClient.execute(
    at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(
    at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.doInvoke(
    at org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.invoke(
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(
    at $Proxy60.sayHello(Unknown Source)
    at com.lexa.HelloClient.doTest(
    at com.lexa.HelloClient.init(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(

My problem is that I cannot modify client to insert my header programmatically. Can somebody explain why websphere binding doesn't work?



You can use BindingProvider adding to MessageContext.HTTP_REQUEST_HEADERS what you need.

// Set up the request headers map.
Map<String, Object> requestHeaders = new HashMap<String, Object>();
requestHeaders.put("MyHeader1", "This is a string value");
requestHeaders.put("MyHeader2", new Integer(33));
requestHeaders.put("MyHeader3", new Boolean(true));

BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);

You may also use as key, it should works fine too.

See more: How request transport headers are sent by a JAX-WS Web services client application

Need Your Help

MaxHeapify call yields numbers not in the original array

c++ heap max-heap

I'm working on implementing a max-heap from pseudo code in my book and I'm getting strange results after calling the "buildMaxHeap" function. For example, an integer array intHeap with elements {20...

Android CursorAdapter drawing things in the wrong list item

android android-listview android-adapter

I’ve got a CursorAdapter that's built from a database Cursor and if a View in the first item isn't filled in, it populates the first item's Views with whatever data appears in that View in the first