如何在websphere(WAS)上为所有结果jax-ws客户端的请求添加http-headers?

时间:2015-12-03 16:53:51

标签: java http-headers websphere jax-ws ibm-was

我希望websphere WAS 8.0.0.5将我的“Authorization:blabla”http-header添加到我对服务的所有jax-ws客户端请求中。我已经阅读了很多主题,但任何事都行不通。我在websphere上部署了一个jax-ws客户端。我已经创建了自己的应用程序poliicy集并附加到我的服务上,并在HTTP-transport的自定义属性中使用我的授权HTTP-header创建了常规客户端策略集绑定。我将我的策略和绑定附加到我的客户端服务,但它不起作用。每次我收到以下异常:

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)

我的问题是我无法修改客户端以编程方式插入我的标头。有人可以解释为什么websphere绑定不起作用吗?

由于

1 个答案:

答案 0 :(得分:-1)

您可以BindingProvider使用MessageContext.HTTP_REQUEST_HEADERS添加所需内容。

// 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);

您也可以使用com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES作为密钥,它也可以正常工作。

查看更多内容: How request transport headers are sent by a JAX-WS Web services client application