接着来写客户端代码:
package com.unicom.vac.bossagent.soap;
import java.rmi.Remote;
import org.apache.axis.client.Stub;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.apache.ws.security.message.token.UsernameToken;
import com.unicom.vac.bossagent.soap.sample.PWCallback;
import com.unicom.vac.bossagent.soap.sync.req.OrderRelationUpdateNotifyRequest;
import com.unicom.vac.bossagent.soap.sync.rsp.OrderRelationUpdateNotifyResponse;
/**
* Description:
* Copyright: Copyright (c)2010
* Company: LJ
* @author: LiuJian
* @version: 1.0
* Create at: 2011-4-8 下午06:08:09
*/
public class WebServiceClient {
private SyncNotifySPServiceServiceLocator locator=null;
private SyncNotifySPServiceService serviceService=null;
private OrderRelationUpdateNotifyResponse response=null;
public com.unicom.vac.bossagent.soap.sync.rsp.OrderRelationUpdateNotifyResponse setRequest(){
try{
System.out.println(this.getClass().getClassLoader().getResource(".").getPath());
OrderRelationUpdateNotifyRequest orunr=new OrderRelationUpdateNotifyRequest();
locator=new SyncNotifySPServiceServiceLocator();
PWCallback pwCallback=new PWCallback();
Remote remote = locator.getPort(SyncNotifySPService.class);
/*************设置用户名和密码校验头信息*********************/
Stub axisPort = (Stub)remote;
axisPort._setProperty(UsernameToken.PASSWORD_TYPE, WSConstants.PASSWORD_DIGEST);
axisPort._setProperty(WSHandlerConstants.USER, "wss4j");
axisPort._setProperty(WSHandlerConstants.PW_CALLBACK_REF, pwCallback);
/***********************************************************/
locator.setEndpointAddress("SyncNotifySP", "http://localhost:8080/VacSyncService_WSS4J/services/SyncNotifySP");
serviceService=locator;
SyncNotifySPService ser=serviceService.getSyncNotifySP();
orunr.setContent("1");
orunr.setEffectiveDate("2");
orunr.setEncodeStr("3");
orunr.setExpireDate("4");
orunr.setLinkId("5");
orunr.setProductId("6");
orunr.setRecordSequenceId("7");
orunr.setServiceType("8");
orunr.setSpId("9");
orunr.setTime_stamp("10");
orunr.setUpdateTime("11");
orunr.setUpdateDesc("12");
orunr.setUpdateType(13);
orunr.setUserId("14");
orunr.setUserIdType(15);
response=ser.orderRelationUpdateNotify(orunr);
if(response!=null){
System.out.println(response.getRecordSequenceId());
}else{
System.out.println("response is null!");
}
}catch(Exception ex){
ex.printStackTrace();
}
return response;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebServiceClient wc=new WebServiceClient();
wc.setRequest();
}
}
此测试通过完成,username:wss4j password:security 可以验证通过。
到此通过用户名和密码的验证方式已经学习过了。接下来我们将学习给WebService的XML加密的安全机制。