axis2根据wsdl自动生成类和携带header参数
程序员文章站
2022-06-28 16:23:33
axis2根据wsdl自动生成类和携带header参数更改一下指向路径和包路径后直接执行就会自动生成代码package com.byttersoft.hibernate.erp;import org.apache.axis2.wsdl.WSDL2Java;import java.util.ArrayList;import java.util.List;public class ClientMain {public static void main(String[] args) thr...
axis2根据wsdl自动生成类和携带header参数
更改一下指向路径和包路径后直接执行就会自动生成代码
package com.byttersoft.hibernate.erp;
import org.apache.axis2.wsdl.WSDL2Java;
import java.util.ArrayList;
import java.util.List;
public class ClientMain {
public static void main(String[] args) throws Exception {
List<String> list=new ArrayList<String>();
list.add("-uri");
//指向你的wsdl文件
list.add("D:\\payment.wsdl");
list.add("-o");
list.add("src");
list.add("-p");
//需要生成到那个包路径下面
list.add("com.byttersoft.hibernate.erp");
//????????
list.add("-t");
WSDL2Java.main(list.toArray(new String[0]));
}
}
这里记录一下携带header参数的方式,只贴出主题代码,因为文件生成的类都不一样,大家有个思路和方向就行
主要代码: headers.add(new Header(param.getKey(),param.getValue().toString()));
PaymentServiceImplServiceStub.PushPaymentResult pushPaymentStub = new PaymentServiceImplServiceStub.PushPaymentResult();
PaymentServiceImplServiceStub stub=null;
try {
stub= new PaymentServiceImplServiceStub();
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
PaymentServiceImplServiceStub.PushPaymentResultResponse pushPaymentResponse = null;
//组装xml值(传输你要传递的参数)
pushPaymentStub = paymentStubService.strPushPaymentXml(reslutJson);
//设置Header的数据信息(这里就是要传递的值,我这里是以key、value的Map去封装)
Map<String,Object> headerParams = util.setHeaderMap(reslutJson,log);
//添加Header参数对象(开始)
Options options = stub._getServiceClient().getOptions();
List<Header> headers = (List<Header>) options
.getProperty(HTTPConstants.HTTP_HEADERS);
if (headers == null) {
headers = new ArrayList<Header>();
}
headers.add(new Header("Content-Type", "application/json"));
options.setProperty(HTTPConstants.HTTP_HEADERS, headers);
for (Map.Entry<String, Object> param : headerParams.entrySet()) {
//循环Map把需要传递的Header参数名(key)和值(value)添加到Header中
headers.add(new Header(param.getKey(),param.getValue().toString()));
}
//结束
String message ="";
if(null!=pushPaymentStub){
try {
//推送数据
pushPaymentResponse = stub.pushPaymentResult(pushPaymentStub);
} catch (RemoteException e) {
e.printStackTrace();
log.info("推送数据失败!");
}
//返回信息
message = pushPaymentResponse.get_return();
}
本文地址:https://blog.csdn.net/qq_37928228/article/details/112018488