当前位置: 代码迷 >> Web前端 >> WebService 添 Token 到header中
  详细解决方案

WebService 添 Token 到header中

热度:1346   发布时间:2012-12-21 12:03:49.0
WebService 加 Token 到header中

Axis WebService的客户端调WebService, 但是现在需要加一个UserNameToken.就是需要在Soap包里面加上一个头.需要加的内容如下(应该是用wss4j这个包来完成的):

??<soapenv:Header>

?? ?<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

?? ? ?<wsse:UsernameToken>

?? ? ? ?<wsse:Username>aaa</wsse:Username>

?? ? ? ?<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">aaaaa</wsse:Password>

?? ? ?</wsse:UsernameToken>

?? ?</wsse:Security>

??</soapenv:Header>

?

public void setSoapHeader(){

?? ? try{

?? ? ? ? ? ?org.apache.axis.message.SOAPHeaderElement soapHeaderElement; ??

?? ? ?soapHeaderElement = new org.apache.axis.message.SOAPHeaderElement("wsse","Security");

?? ? ?soapHeaderElement.setMustUnderstand(true);

?? ? ?soapHeaderElement.setNamespaceURI("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

?? ? ?SOAPElement token = soapHeaderElement.addChildElement("UsernameToken");

?? ? ?SOAPElement userName = token.addChildElement("Username","wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

?? ? ?userName.setValue("username");

?? ? ?SOAPElement password = token.addChildElement("Password","wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

?? ? ?password.setValue("password");

?? ? ?_call.addHeader(soapHeaderElement);

?? ? }catch(Exception err){

?? ? ?err.printStackTrace();

?? ? }

?? ?}

  相关解决方案