package test;
import java.io.File;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.junit.Test;
public class Test {
@Test
public void test(){
String url ="http://127.0.0.1:7001/services/XXWebService?wsdl";
RPCServiceClient serviceClient;
try {
serviceClient=new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(url);
options.setTransportInProtocol("SOAP");
options.setAction("doService");
options.setTo(targetEPR);
options.setManageSession(true);
options.setProperty(HTTPConstants.CHUNKED,"false");
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
options.setTimeOutInMilliSeconds(60000);
QName opAddEntry = new QName("http://impl.service.xxx","doService");//服务端包名的反序
String xml = createXml();
Object[] objects=new Object[]{xml};
Class[] classes=new Class[]{String.class};
Object obj = serviceClient.invokeBlocking(opAddEntry, objects,classes)[0];
System.out.println(obj);
serviceClient.cleanupTransport();
serviceClient.cleanup();
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private String createXml() {
// TODO Auto-generated method stub
SAXReader saxReader = new SAXReader();
Document doc=null;
try {
doc= saxReader.read(new File("E:\\request.xml"));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return doc.asXML();
}
}
来源:CSDN
作者:phs999
链接:https://blog.csdn.net/phs999/article/details/104373652