maven配置:主要引用包及plugins
<properties>
<axis2.version>1.6.1</axis2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis2.version}</version>
</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>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.6.1</version>
<executions>
<execution>
<id>wsdl2code-client</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlFile>src/main/resources/wsdl/IXman.wsdl</wsdlFile>
<packageName>com.stub.generated</packageName>
<generateServicesXml>false</generateServicesXml>
<unpackClasses>true</unpackClasses>
</configuration>
</plugin>
</plugins>
</build>
通过wsdlFile属性指定wsdl所在文件。
如果是有多个wsdl需要生成java代码,则可以用下面的配置:
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>ws1</id>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<unpackClasses>true</unpackClasses>
<databindingName>adb</databindingName>
<packageName>org.example.*.axis2-maven</packageName>
<wsdlFile>src/main/resources/service1.wsdl</wsdlFile>
<outputDirectory>target/generated-sources</outputDirectory>
<syncMode>sync</syncMode>
</configuration>
</execution>
<execution>
<id>ws2</id>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<unpackClasses>true</unpackClasses>
<databindingName>adb</databindingName>
<packageName>org.example.*.axis2-maven</packageName>
<wsdlFile>src/main/resources/service2.wsdl</wsdlFile>
<outputDirectory>target/generated-sources</outputDirectory>
<syncMode>sync</syncMode>
</configuration>
</execution>
</executions>
</plugin>
注意,这段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());
}