Axis1.4客户端调用,Soap消息头设置

提交了辞职信,工作交接中,闲来无事访问apache的网站,想起来曾一时让我很头疼的webservice,随手写了几行代码,就当练手吧!接下来学习axis2,奔着那个方向去。
这段代码是我在调用电信的服务时的客户端代码,实现下发手机短信的部分代码。重点1.stub方式ws的应用。2.怎么设置soap头。还是那句老话,从知道到不知道是一个很艰苦的过程。

public static void main(String[] args) throws InterruptedException
{
Test test = new Test();
try
{
//URL 调用webservice地址
SendSmsBindingStub service = (SendSmsBindingStub) new SendSmsServiceLocator().getSendSms(new URL("http://1.1.1.1:8080/SendSmsService"));
SOAPHeaderElement header = new SOAPHeaderElement("http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1","RequestSOAPHeader");
SOAPElement soap = null;

soap = header.addChildElement("password");
soap.addTextNode(test.getPassword().toUpperCase());

soap = header.addChildElement("productId");
Node node = doc.selectSingleNode("//cctc/projects/productid[@busiid='"+ busiid +"']");
if(node != null)
soap.addTextNode(node.getText());
else
soap.addTextNode("");
//....................

//设置头
service.setHeader(header);
//因设置不群发,所以去URL的第一个元素
String result = service.sendSms(new URI[0], "senderName", new ChargingInformation(), "message", new SimpleReference());

System.out.println(result);
}
catch (Exception e)
{
e.printStackTrace();
}
}

private String getPassword()
{
//密码为接入网关号+接入密码+10为时间戳后MD5加密
String password = "xxxxxxx" + "yyyyyy" + getTimetemp();
MessageDigest md5 = getMD5();
md5.update(password.getBytes());
byte[] result = md5.digest();
StringBuffer strBuffer = new StringBuffer();
for(int i = 0; i < result.length; i++)
{
String temp = Integer.toHexString(result[i] & 0xff);
if(temp.length() == 1)
strBuffer.append("0");
strBuffer.append(temp);
}
return strBuffer.toString();
}
private SimpleDateFormat sdf = null;
private String getTimetemp()
{
if(sdf == null)
sdf = new SimpleDateFormat("MMddHHmmss");
return sdf.format(new Date(System.currentTimeMillis()));
}

private static MessageDigest getMD5()
{
MessageDigest md5 = null;
try
{
if(md5 == null)
md5 = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
return md5;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值