【发布时间】:2012-12-23 09:52:29
【问题描述】:
我正在开发网络服务。我想知道如何在 JAX-WS 类型的 Web 服务中向 SOAP 请求添加标头。
像这样考虑我的标题。
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Username", Collections.singletonList("aaaa"));
headers.put("Password", Collections.singletonList("aaaa"));
我的客户端类中有存根对象。我使用的是 Apache Axis 2。所有的类都是自动生成的。
SimpleSTub stub = new Simplestub();
我想在客户端添加这个头信息。
MessageContext.HTTP_REQUEST_HEADERS, headers
编辑
普通类中的实际实现为
私有静态最终字符串 WS_URL = "http://localhost:9999/ws/hello?wsdl";
public static void main(String[] args) 抛出异常 {
URL url = 新 URL(WS_URL); QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
/*******************UserName & Password ******************************/
Map<String, Object> req_ctx = ((BindingProvider)hello).getRequestContext();
req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Username", Collections.singletonList("mkyong"));
headers.put("Password", Collections.singletonList("password"));
req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
/**********************************************************************/
System.out.println(hello.getHelloWorldAsString());
谁能告诉我如何做到这一点。
谢谢。
【问题讨论】:
标签: java web-services jax-ws axis2 webservice-client