使用axis2解析wsdl
来源:互联网 发布:nginx配置ssl双向验证 编辑:程序博客网 时间:2024/06/07 00:06
1.使用rpc方式解析远程wsdl:
优点在于:代码简单、不用繁琐的生成服务端的一大堆代码
缺点在于:需要知道要解析的wsdl的服务端部分的实体类的定义
2.使用的包的maven依赖:
<!--==============axis2 client===============-->
<!--http://blog.csdn.net/liwf_/article/details/9788789-->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>${axis2.version}</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>${axis2.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis2.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>${axis2.version}</version>
<exclusions>
<!-- We want to choose the JavaMail implementation ourselves -->
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--http://dominikdorn.com/2010/05/maven-junit-classformaterror-absent-code-attribute/-->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
3.工具类代码:
public class CallWSDLByAxis2 {
/**
* RPC调用AXIS2 webservice
*
* @param endpoint 服务地址
* 如:http://192.168.0.1:2597/aixs2/services/jqservice?wsdl
* @param localPart 方法名 如<xs:element name="Receive">
* @param opArgs 方法参数 如Object[] opArgs = new Object[] { param };
* @param namespaceURI 命名空间 如 :targetNamespace="http://server.test.com.cn">
* @param opReturnType 返回类型 如字符串:Class[] opReturnType = new Class[] {
* String[].class };
* @param timeoutSeconds
* @param username
* @param password
* @return
*/
public static Object axis2RPCInvoke(String endpoint, String localPart, Object[] opArgs, String namespaceURI, Class[] opReturnType, int timeoutSeconds, String username, String password) {
Object[] ret = null;
try {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
Authenticator authenticator = new Authenticator();
List<String> auth = new ArrayList<String>();
auth.add(Authenticator.BASIC);
authenticator.setAuthSchemes(auth);
authenticator.setUsername(username);
authenticator.setPassword(password);
authenticator.setPreemptiveAuthentication(true);
options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
options.setTimeOutInMilliSeconds(timeoutSeconds * 1000);
EndpointReference targetEPR = new EndpointReference(endpoint);
options.setTo(targetEPR);
QName opQName = new QName(namespaceURI, localPart);
ret = serviceClient.invokeBlocking(opQName, opArgs, opReturnType);
serviceClient.cleanupTransport();
} catch (Exception e) {
e.printStackTrace();
}
return ret[0];
}
/**
* 没有返回值的请求
* @param endpoint
* @param localPart
* @param opArgs
* @param namespaceURI
* @param timeoutSeconds
* @param username
* @param password
*/
public static void axis2RPCInvoke(String endpoint, String localPart, Object[] opArgs, String namespaceURI, int timeoutSeconds, String username, String password) {
try {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
Authenticator authenticator = new Authenticator();
List<String> auth = new ArrayList<String>();
auth.add(Authenticator.BASIC);
authenticator.setAuthSchemes(auth);
authenticator.setUsername(username);
authenticator.setPassword(password);
authenticator.setPreemptiveAuthentication(true);
options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
options.setProperty(HTTPConstants.CHUNKED, false);
options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_APPLICATION_ECHO_XML);
options.setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean.TRUE);
options.setTimeOutInMilliSeconds(timeoutSeconds * 1000);
EndpointReference targetEPR = new EndpointReference(endpoint);
options.setTo(targetEPR);
QName opQName = new QName(namespaceURI, localPart);
serviceClient.invokeRobust(opQName, opArgs);
serviceClient.cleanupTransport();
} catch (Exception e) {
e.printStackTrace();
}
}
}
- 使用axis2解析wsdl
- 使用axis2解析wsdl反向生成webservice客户端
- 使用axis2解析wsdl生成Webservice客户端代码
- 使用axis2解析wsdl生成Webservice客户端代码
- 使用axis2解析wsdl生成Webservice客户端代码
- 使用axis2 java2wsdl命令生成wsdl文件
- wsdl使用axis2 1.4.1 生成客户端
- CXF的WSDL2java解析Axis2的wsdl,不包含JAXBElement
- java使用soapui解析wsdl
- 使用axis2的wsdl2java把wsdl生成java文件
- 在Eclipse中使用Axis2插件自动生成WSDL文件
- 使用axis2的wsdl2java把wsdl生成java文件
- 使用axis2,根据WSDL生成java客户端代码
- 使用axis2将wsdl文件生成本地类的方法
- 在Eclipse中使用Axis2插件自动生成WSDL文件
- Java使用axis2调用wsdl形式的webservice
- 在Eclipse中使用Axis2插件自动生成WSDL文件
- 使用axis2,根据WSDL生成java客户端代码
- vim之注释插件
- Tomcat 正式环境下多个Context配置
- 32位系统2038年1月19日03:14:07BUG
- 新版QT creator下解决fcitx无法输入中文问题(QTcreatorV4.1.0)
- jeecg快捷开发工具代码资料
- 使用axis2解析wsdl
- codeforces 374C
- SQL 常用函数
- web前端-CSS 盒子模型-010
- Maven 手动添加 JAR 包到本地仓库
- unicode转汉字 java 一句话或一个方法
- AR & VR类网站
- Nginx报错及其解决方法
- Codeforces Intel Code Challenge Final Round C.Ray Tracing