如何将HTTP标头添加到JAXWS创建的代理类

时间:2015-11-20 01:48:35

标签: java web-services soap jax-ws wsimport

我在NetBeans中为SOAP Web服务创建了一组代理类。

我想在传出请求中添加HTTP标头。

Map<String, Object> requestHeaders = new HashMap<>();
requestHeaders.put("X-Header", header);
AccountManagementService service = new AccountManagementService();
AccountManagementServiceSoap soap = service.getAccountManagementServiceSoap();
GetMembershipSummaryResponse.GetMembershipSummaryResult membershipSummary = soap.getMembershipSummary("mikeb@foobar.com");

当您从服务获取单个端口时,我看到了一堆JAX-WS标头示例。有没有更简单的方法?我可以只将标题添加到服务或soap对象上的某个集合中吗?

1 个答案:

答案 0 :(得分:0)

经过一番挖掘后,我发现了这篇文章:jax-ws change Content-type to Content-Type because server is hyper sensitive

这不是一个完整的答案,所以我将在这里发布完整的答案:

   AccountManagementService service = new AccountManagementService();
   AccountManagementServiceSoap soap = service.getAccountManagementServiceSoap();

   ((BindingProvider)soap).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
    Collections.singletonMap("X-Header",Collections.singletonList(header)));
   GetMembershipSummaryResponse.GetMembershipSummaryResult membershipSummary = soap.getMembershipSummary("mikeb@foobar.com");