我正在从事网络服务工作。我想知道如何向 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
Edit
普通类中的实际实现为
私有静态最终字符串 WS_URL = "http://localhost:9999/ws/hello?wsdl";
公共静态无效主(字符串[] args)抛出异常{
网址 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());
任何人都可以告诉如何实现这一目标。
Thanks.