axis2 调用webservice
maven配置:主要引用包及plugins
<properties> <axis2.version>1.6.1axis2.version> properties> <dependencies> <dependency> <groupId>org.apache.axis2groupId> <artifactId>axis2-kernelartifactId> <version>${axis2.version}version> dependency> <dependency> <groupId>org.apache.axis2groupId> <artifactId>axis2-adbartifactId> <version>${axis2.version}version> dependency> <dependency> <groupId>org.apache.axis2groupId> <artifactId>axis2-transport-httpartifactId> <version>${axis2.version}version> dependency> <dependency> <groupId>org.apache.axis2groupId> <artifactId>axis2-transport-localartifactId> <version>${axis2.version}version> dependency> dependencies> <build> <plugins> <plugin> <groupId>org.apache.axis2groupId> <artifactId>axis2-wsdl2code-maven-pluginartifactId> <version>1.6.1version> <executions> <execution> <id>wsdl2code-clientid> <phase>generate-sourcesphase> <goals> <goal>wsdl2codegoal> goals> execution> executions> <configuration> <wsdlFile>src/main/resources/wsdl/IXman.wsdlwsdlFile> <packageName>com.stub.generatedpackageName> <generateServicesXml>falsegenerateServicesXml> <unpackClasses>trueunpackClasses> configuration> plugin> plugins> build>
通过wsdlFile属性指定wsdl所在文件。
如果是有多个wsdl需要生成java代码,则可以用下面的配置:
org.apache.axis2 axis2-wsdl2code-maven-plugin 1.6.0 ws1 wsdl2code true adb org.example.stackoverflow.axis2-maven src/main/resources/service1.wsdl target/generated-sources sync ws2 wsdl2code true adb org.example.stackoverflow.axis2-maven src/main/resources/service2.wsdl target/generated-sources sync
注意,这段xml配置,如果使用axis2-wsdl2code:wsdl2code命令去生成会报错,但使用install者可以生成成功。
之后通过中间代码调用即可。
@Test public void testWs() throws Exception{ AIServiceStub aiServiceStub=new AIServiceStub(); AIRequest aiRequest=new AIRequest(); aiRequest.setMsgHeader("test"); aiRequest.setMsgBody("test"); AIResponse response= aiServiceStub.aIService_visit(aiRequest); System.out.println(response.getRes()); }