package client;
/**
* power by mxcode 2015.10.05
*/
import java.net.URL;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.lang.StringUtils;
public class axis1CallPIWebservice {
private static Call call = null;
public static void main(String[] args) {
//PI webservice地址
String webServiceAddr = "http://10.114.20.14:50000/XISOAPAdapter/MessageServlet?channel=:BS_OA:CC_PORTAL_OA_NoticeInfo_OUT&version=3.0&Sender.Service=BS_OA&Interface=urn%3Aportal%3Aoa%3Aorgperappinf%5EMI_PORTAL_OA_NoticeInfo_OUT";
//调用方法名
String webServiceMethod = "addNoticeInfo";
//传入参数名
String[] inputNames = {"xml"};
//传入参数类型
String[] inputXmlTypes = {"Constants.XSD_STRING"};
//命名空间
String targetNamespace = "http://webservice.smsplatform.haiyisoft.com";
//传入值
Object[] inputValues = { "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ParamsXml><Params><AgentID>GDDX</AgentID><DepartureAirport>CAN</DepartureAirport><ArriveAirport>PEK</ArriveAirport><DepartureDate>2014-01-18</DepartureDate><CarrierCode>CZ</CarrierCode><FS>D</FS></Params></ParamsXml>" };
//返回值类型
Class<?>[] returnJavaTypes = {String.class};
//验证用户名
String username = "test";
//密码
String password = "2015test";
//无特殊含义
String soapActionURI ="http://10.114.20.14:50000";
//调用
Object geObjectByAxis2RPCClient = getObjectByAxisCallClient(webServiceAddr, webServiceMethod,soapActionURI, targetNamespace, inputValues,inputNames,inputXmlTypes, returnJavaTypes, username, password);
System.out.println(geObjectByAxis2RPCClient);
}
public static Object getObjectByAxisCallClient(String webServiceAddr, String webServiceMethod, String soapActionURI,
String targetNamespace, Object[] inputValues, String[] inputNames, String[] inputXmlTypes, Class<?>[] inputJavaTypes,
String username, String password) {
Object resObj = null;
try {
if (call == null) {
Service service = new Service();
call = (Call) service.createCall();
}
// 设置wsdl
call.setTargetEndpointAddress(new URL(webServiceAddr));
// 定义参数对象
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI + webServiceMethod);
// 设置访问的方法名
// call.setOperationName(webServiceMethod);
call.setOperationName(new QName(targetNamespace, webServiceMethod));//call是axis1产生的Call对象,namespaceURI应该是http://util.stat2,methodName应该是调用的方法名称
call.addParameter(new QName(targetNamespace, inputNames[0]),org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setTimeout(30000);
// 访问权限验证.
if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
call.setUsername(username);
call.setPassword(password);
}
resObj = call.invoke(inputValues);
} catch (Exception e) {
// TODO Auto/generated catch block
// String message = messageFormat(“使用AxisCallClient调用WebService地址{{0}}方法{{1}}出现错误!”, webServiceAddr, webServiceMethod);
// logger.error(message, e);
// throw new InterfaceException(message);
e.printStackTrace();
}
return resObj;
}
}