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

I want websphere WAS 8.0.0.5 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 : http://192.168.32.120:8280/hello/1/1
    at com.ibm.ws.websvcs.transport.http.SOAPOverHTTPSender.processStatusCode(SOAPOverHTTPSender.java:3659)
    at com.ibm.ws.websvcs.transport.http.SOAPOverHTTPSender.send(SOAPOverHTTPSender.java:595)
    at com.ibm.ws.websvcs.transport.http.HTTPTransportSender.invoke(HTTPTransportSender.java:366)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:544)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
    at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:578)
    at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.doInvoke(AxisInvocationController.java:127)
    at org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.invoke(InvocationControllerImpl.java:93)
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:390)
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:188)
    at $Proxy60.sayHello(Unknown Source)
    at com.lexa.HelloClient.doTest(HelloClient.java:36)
    at com.lexa.HelloClient.init(HelloClient.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)

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

Thanks

Answers


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 com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES 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