在soap标头中添加wsse:UsernameToken [英] Add wsse:UsernameToken in soap header
本文介绍了在soap标头中添加wsse:UsernameToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究SOAP客户端。我的WSDL URL是 http:// localhost:8080 / soap / getMessage?wsdl
。
I am working on SOAP client. My WSDL URL is http://localhost:8080/soap/getMessage?wsdl
.
这需要以下标题指定用户名和密码。
This requires the the following header to specify the username and password.
<wsdl:Envelope xmlns:soap="..."
xmlns:wsse="..." >
<wsdl:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>admin</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</wsdl:Header>
</wsdl:Envelope>
我必须为它编写一个程序。
I have to write a program for it.
有人可以帮助我。
谢谢。
推荐答案
这是我过去的肥皂计划。我已将其修改为您的情况。
here is my past program for soap. I already modified it to your case.
//create SOAP
SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
SOAPElement Header = soapBody.addBodyElement(new QName("Header"));
//attribute
SOAPElement Security= Header.addChildElement(new QName("Security"));
SOAPElement UsernameToken= Security.addChildElement(new QName("UsernameToken"));
SOAPElement Username= UsernameToken.addChildElement(new QName("Username"));
SOAPElement Password= UsernameToken.addChildElement(new QName("Password"));
//enter the username and password
Username.addTextNode("username");
Password.addTextNode("password");
//send the soap and print out the result
URL endpoint = "http://localhost:8080/soap/getMessage?wsdl";
SOAPMessage response = connection.call(soapMessage, endpoint);
ByteArrayOutputStream out = new ByteArrayOutputStream();
String xml = "";
try {
response.writeTo(out);
xml = out.toString("UTF-8");
} catch (Exception e)
{
System.out.println(""+e);
//log.error(e.getMessage(),e);
}
System.out.println(""+xml);
有关详细信息,您可以在谷歌搜索使用JDK 1.6中的SOAP
for further information you can search the google for using SOAP in JDK 1.6
这篇关于在soap标头中添加wsse:UsernameToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文