1.添加pom依赖
<!--axis2 statrt WebService -->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb-codegen</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.2</version>
</dependency>
2、调用工具类
package com.picc.job.utils;
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;
public class WebServiceUtil {
/**
*
* @Desc: webservice 接口请求
* @param url 接口地址
* @param methodName 方法名称
* @param xmlParam 请求参数 请求报文
* @return
* @throws Exception
*/
public static String webSweviceMethod(String url, String methodName, String param) throws AxisFault {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setTimeOutInMilliSeconds(600*1000);
options.setProperty(HTTPConstants.SO_TIMEOUT,600*1000);
EndpointReference targetEPR = new EndpointReference(url);
options.setTo(targetEPR);
QName opAddEntry = new QName(url, methodName);
Object[] opAddEntryArgs = new Object[] { param };
@SuppressWarnings("rawtypes")
Class[] classes = new Class[] { String.class };
return (String) serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0];
}
}