axis2调用xfire开发的webservice服务接口
爱笑的眼睛 2012-05-30 02:49:12 对方使用xfire开发了带有soapheader验证的webservice:在soapheader中附带用户名和密码信息,服务端解析;现在在我这一端需要使用axis2调用webservice服务,请问如如何将用户名密码信息添加到soapheader中?我调用webservice服务的代码如下:
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:8889/axis2/services/SimpleService?wsdl");
options.setTo(targetEPR);
QName opAddEntry = new QName("http://ws.apache.org/axis2", "getMyArea");
serviceClient.invokeBlocking(opAddEntry, new Object[]{},new Class[]{String.class})。
对方服务端接受的代码:
public class AuthenticationHandler extends AbstractHandler {
public void invoke(MessageContext cfx) throws Exception {
if (cfx.getInMessage().getHeader() == null) {
throw new org.codehaus.xfire.fault.XFireFault("请求必须包含验证信息",
org.codehaus.xfire.fault.XFireFault.SENDER);
}
final Namespace TOKEN_NS = Namespace.getNamespace("",
"http://webservice.report.enation.com");
Element token = cfx.getInMessage().getHeader().getChild(
"AuthenticationToken", TOKEN_NS);
if (token == null) {
throw new org.codehaus.xfire.fault.XFireFault("请求必须包含身份验证信息",
org.codehaus.xfire.fault.XFireFault.SENDER);
}
String username = token.getChild("Username", TOKEN_NS).getValue();
String password = token.getChild("Password", TOKEN_NS).getValue();
System.out.println(username+"/"+password);
}