package test;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;
public class CCBWebServiceClient {
//静态变量
private static EndpointReference EPR = new EndpointReference("http://WSDL的URL");
private static OMFactory fac = OMAbstractFactory.getOMFactory();
private static OMNamespace omNs = fac.createOMNamespace("http://oracle.com/CM_TEST_XAI.xsd", "xsd");//wsdl中的namespace
public static void main(String args[]) throws AxisFault{
ServiceClient sender = new ServiceClient();
/****************************CM_TEST_XAI方法,如果有其他方法,以此类推**************************************/
sender.setOptions(buildOptions("http://ouaf.oracle.com/spl/XAIXapp/xaiserver/CM_TEST_XAI"));//注意“CM_TEST_XAI”是方法名
OMElement result = sender.sendReceive(buildParam("CM_TEST_XAI",new String[]{"参"},new String[]{"值"}));
//传递多个参数:OMElement result = sender.sendReceive(buildParam("方法名",new String[]{"参数名1","参数名2"},new String[]{"值1","值2"}));
//空参:OMElement result = sender.sendReceive(null);
/************************************************************************************************/
System.out.println(result);
}
/**
* 传参函数
*/
public static OMElement buildParam(String method,String[] arg,String[] val) {
OMElement data = fac.createOMElement(method,omNs);
for(int i=0;i<arg.length;i++){
OMElement inner = fac.createOMElement(arg[i], omNs);
inner.setText(val[i]);
data.addChild(inner);
}
return data;
}
/**
* @see 设置连接属性
* @return
* @throws AxisFault
*/
public static Options buildOptions(String action) throws AxisFault{
Options options = new Options();
options.setTo(EPR);
options.setProperty(HTTPConstants.CHUNKED, "false");//设置长度不受限制.
// options.setProperty(HTTPConstants.PROXY, buildProxy());//打开即用代理
/****************************添加账号密码*******************************************************/
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername("账号");
auth.setPassword("密码");
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,auth);
/*******************************************************************************************/
options.setAction(action);//此处根据报错情况决定是否注释
return options;
}
/**
* 设置代理
*/
public static ProxyProperties buildProxy(){
ProxyProperties proxyProperties=new ProxyProperties();
proxyProperties.setProxyName("代理地址");
proxyProperties.setProxyPort(8080);
return proxyProperties;
}
}
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;
public class CCBWebServiceClient {
//静态变量
private static EndpointReference EPR = new EndpointReference("http://WSDL的URL");
private static OMFactory fac = OMAbstractFactory.getOMFactory();
private static OMNamespace omNs = fac.createOMNamespace("http://oracle.com/CM_TEST_XAI.xsd", "xsd");//wsdl中的namespace
public static void main(String args[]) throws AxisFault{
ServiceClient sender = new ServiceClient();
/****************************CM_TEST_XAI方法,如果有其他方法,以此类推**************************************/
sender.setOptions(buildOptions("http://ouaf.oracle.com/spl/XAIXapp/xaiserver/CM_TEST_XAI"));//注意“CM_TEST_XAI”是方法名
OMElement result = sender.sendReceive(buildParam("CM_TEST_XAI",new String[]{"参"},new String[]{"值"}));
//传递多个参数:OMElement result = sender.sendReceive(buildParam("方法名",new String[]{"参数名1","参数名2"},new String[]{"值1","值2"}));
//空参:OMElement result = sender.sendReceive(null);
/************************************************************************************************/
System.out.println(result);
}
/**
* 传参函数
*/
public static OMElement buildParam(String method,String[] arg,String[] val) {
OMElement data = fac.createOMElement(method,omNs);
for(int i=0;i<arg.length;i++){
OMElement inner = fac.createOMElement(arg[i], omNs);
inner.setText(val[i]);
data.addChild(inner);
}
return data;
}
/**
* @see 设置连接属性
* @return
* @throws AxisFault
*/
public static Options buildOptions(String action) throws AxisFault{
Options options = new Options();
options.setTo(EPR);
options.setProperty(HTTPConstants.CHUNKED, "false");//设置长度不受限制.
// options.setProperty(HTTPConstants.PROXY, buildProxy());//打开即用代理
/****************************添加账号密码*******************************************************/
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername("账号");
auth.setPassword("密码");
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,auth);
/*******************************************************************************************/
options.setAction(action);//此处根据报错情况决定是否注释
return options;
}
/**
* 设置代理
*/
public static ProxyProperties buildProxy(){
ProxyProperties proxyProperties=new ProxyProperties();
proxyProperties.setProxyName("代理地址");
proxyProperties.setProxyPort(8080);
return proxyProperties;
}
}