如何将HTTP标头添加到JAXWS创建的代理类
问题描述:
我已经在NetBeans中为SOAP Web服务创建了一组代理类.
I've created a set of proxy classes in NetBeans for a SOAP web service.
我想将HTTP标头添加到传出请求中.
I'd like to add an HTTP header to the outgoing request.
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对象上的某个集合中吗?
I saw a bunch of JAX-WS header examples for when you are getting the individual port from the service. Is there an easier way? Can I just add the header to some collection on service or soap object?
答
after some digging I found this post: jax-ws change Content-type to Content-Type because server is hyper sensitive
这并不是真正的完整答案,因此我将在此处发布完整答案:
which isn't really a full answer, so I am going to post the full answer here:
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");