How do I add HTTP headers to JAXWS created proxy classes

喜欢而已 提交于 2019-12-24 12:02:38

问题


I've created a set of proxy classes in NetBeans for a SOAP web service.

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");

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?


回答1:


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");


来源:https://stackoverflow.com/questions/33817644/how-do-i-add-http-headers-to-jaxws-created-proxy-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!