【问题标题】:How to add http-headers to all outcome jax-ws client's requests on websphere(WAS)?如何将 http-headers 添加到 websphere(WAS)上的所有结果 jax-ws 客户端请求?
【发布时间】:2015-12-03 16:53:51
【问题描述】:

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

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 绑定不起作用吗?

谢谢

【问题讨论】:

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


    【解决方案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

    【讨论】:

    • Poster 说他们无法修改代码,并且正在通过 WebSphere 绑定寻找仅配置方法。
    猜你喜欢
    • 1970-01-01
    • 2016-02-10
    • 2012-07-09
    • 1970-01-01
    • 2011-05-02
    • 2021-09-02
    • 2013-01-08
    • 2011-11-25
    • 1970-01-01
    相关资源
    最近更新 更多