如何将HTTP标头添加到JAXWS创建的代理类 [英] How do I add HTTP headers to JAXWS created proxy classes

查看:83
本文介绍了如何将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");

这篇关于如何将HTTP标头添加到JAXWS创建的代理类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆