【问题标题】:How can HTTP headers be added to JAX-WS requests in WebSphere 8.5?如何在 WebSphere 8.5 中将 HTTP 标头添加到 JAX-WS 请求中?
【发布时间】:2016-02-10 15:50:26
【问题描述】:

我正在尝试在 WebSphere 8.5.5.2 上使用 JAX-WS 在出站 SOAP 请求上设置自定义标头。下面方法中的 BindingProvider 是通过 JNDI 为使用 @ServiceRef 注解声明的服务获取的。

void setHeader(BindingProvider provider, String name, String value) {
    Map<String, Object> context = provider.getRequestContext();
    Map<String, List<String>> headers = null;

    if (context.containsKey(MessageContext.HTTP_REQUEST_HEADERS)) {
        headers = (Map<String, List<String>>)
                   context.get(MessageContext.HTTP_REQUEST_HEADERS);
    }

    if (headers == null) {
        headers = new HashMap<String, List<String>>();
        context.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
    }

    headers.put(name, Arrays.asList(value));
}

我认为,它们在这里的关键与 WebSphere 有关。如果我将 HTTP 标头放入特定于 IBM 的上下文条目中:

com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES

标头已正确放置到 SOAP HTTP 请求中。请注意,以防万一,该值未包装在 List 实例中。

有没有人在 WebSphere 上使用MessageContext.HTTP_REQUEST_HEADERS成功实现了这个解决方案?

【问题讨论】:

    标签: java websphere jax-ws websphere-8


    【解决方案1】:

    请点击以下链接,它有样品:

    http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/twbs_cookiejaxws.html?lang=en

    请点击上面的链接,它有示例。

    【讨论】:

    • 感谢您的反馈。但是,该页面上的示例使用来自 com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES 的 IBM 值。我想避免这种情况并尽可能使用MessageContext.HTTP_REQUEST_HEADERS
    猜你喜欢
    • 2016-09-29
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 2011-01-20
    相关资源
    最近更新 更多