Element token=mc.getInMessage().getHeader().getChild("AuthenticationToken");
if (token == null) {
throw new org.codehaus.xfire.fault.XFireFault("请求必须包含身份验证信息", org.codehaus.xfire.fault.XFireFault.SENDER);
}
if(token.getChild("CurrentUserId")!=null && token.getChild("CurrentUserId").getValue()!=null && !token.getChild("CurrentUserId").getValue().trim().equals("") ) {
return token.getChild("CurrentUserId").getValue();
}
throw new org.codehaus.xfire.fault.XFireFault("请求必须包含当前操作用户Id", org.codehaus.xfire.fault.XFireFault.SENDER);
package test;
import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.handler.AbstractHandler;
import org.jdom.Element;
public class ClientAuthenticationHandler extends AbstractHandler {
private String username = null;
private String password = null;
public ClientAuthenticationHandler() {
}
public ClientAuthenticationHandler(String username,String password) {
this.username = username;
this.password = password;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void invoke(MessageContext context) throws Exception {
//为SOAP Header构造验证信息
Element el = new Element("header");
context.getOutMessage().setHeader(el);
Element auth = new Element("AuthenticationToken");
Element username_el = new Element("Username");
username_el.addContent(username);
Element password_el = new Element("Password");
password_el.addContent(password);
auth.addContent(username_el);
auth.addContent(password_el);
el.addContent(auth);
}
}