如何在JAX-WS客户端中设置SOAP标头

时间:2016-12-01 13:32:39

标签: java web-services soap jax-ws

我试图关注this example,目标是设置SOAP标头。

到目前为止,我的代码看起来像这样:

SomethingPortType portType = service.getPort(SomethingPortType.class);

Map<String, Object> requestHeaders = new HashMap<String, Object>();
requestHeaders.put("MyHeader1", "This is a string value");
requestHeaders.put("MyHeader2", "This is a string value2");

// Set the Map as a property on the RequestContext.
BindingProvider bp = (BindingProvider) portType;
bp.getRequestContext().put("???", requestHeaders);

我没有使用任何应用程序服务器,如何弄清楚我应该代替什么? (或来自示例的com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES)正确设置SOAP Header?

1 个答案:

答案 0 :(得分:1)

简而言之,我错过了这一行:

bp.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);