Web Services 使用Maven和Axis生成客户端Web服务

l7wslrjt  于 2022-11-15  发布在  Maven
关注(0)|答案(1)|浏览(202)

当Maven使用Axis生成客户端Web服务的源代码时,我遇到了一个问题。
我需要使用其他公司公开的url中的wsdl。例如,这是url http://127.0.0.1:8080/ESBService/Example?wsdl中的wsdl内容

<wsdl:definitions xmlns:ns0="http://www.davivienda.com/xml/Example" xmlns:wsp200607="http://www.w3.org/2006/07/ws-policy" xmlns:wsp200409="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap11="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.davivienda.com/xml/Example">
    <wsdl:types xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:schema>
            <xsd:import schemaLocation="MySchema.xsd1.xsd" namespace="http://www.davivienda.com/xml/Example"/>
            <xsd:import schemaLocation="MySchema.xsd2.xsd" namespace="http://www.davivienda.com/xml/Example"/>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="Example_in">
        <wsdl:part xmlns:xsns="http://www.davivienda.com/xml/Example" name="Example" element="xsns:Example"/>
    </wsdl:message>
    <wsdl:message name="Example_out">
        <wsdl:part xmlns:xsns="http://www.davivienda.com/xml/Example" name="ExampleResponse" element="xsns:ExampleResponse"/>
    </wsdl:message>
    <wsdl:portType name="ExamplePortType">
        <wsdl:operation name="Example">
            <wsdl:input name="Example_Input" message="ns0:Example_in"/>
            <wsdl:output name="Example_Output" message="ns0:Example_out"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="ExampleExampleSOAP_HTTP_Binding" type="ns0:ExamplePortType">
        <soap11:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="Example">
            <soap11:operation soapAction="" style="document"/>
            <wsdl:input name="Example_Input">
                <soap11:body parts="Example" use="literal"/>
            </wsdl:input>
            <wsdl:output name="Example_Output">
                <soap11:body parts="ExampleResponse" use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="ExampleExample_HTTP_Service">
        <wsdl:port name="ExampleExample_HTTP_Port" binding="ns0:ExampleExampleSOAP_HTTP_Binding">
            <soap11:address location="http://127.0.0.1:8080/ESBService/Example"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

这是我的pom文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.axis</groupId>
    <artifactId>client</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <name>client</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>org.codehaus.mojo</id>
            <name>org.codehaus.mojo</name>
            <url>http://repository.codehaus.org/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxrpc-api</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>axistools-maven-plugin</artifactId>
                                        <versionRange>[1.4,)</versionRange>
                                        <goals>
                                            <goal>wsdl2java</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>axistools-maven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <urls>
                        <url>http://127.0.0.1:8080/ESBService/Example?wsdl</url>
                    </urls>
                    <packageSpace>com.example.axis.client</packageSpace>
                    <outputDirectory>${project.build.directory}/generated-sources/wsdl2java</outputDirectory>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>javax.mail</groupId>
                        <artifactId>mail</artifactId>
                        <version>1.4.1</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.activation</groupId>
                        <artifactId>activation</artifactId>
                        <version>1.1</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

当我在eclipse中执行Run As-〉-generated source时,Axis插件无法从url读取架构,并抛出以下错误:

[ERROR] Failed to execute goal org.codehaus.mojo:axistools-maven-plugin:1.4:wsdl2java (default) on project client: Error generating Java code from WSDL. Error running Axis: WSDLException (at /wsdl:definitions/wsdl:types/xsd:schema): faultCode=OTHER_ERROR: An error occurred trying to resolve schema referenced at 'MySchema.xsd1.xsd', relative to 'file:/E:/IDE/sts-bundle/workspaces/java/hermes-webapplet/client/target/axistools/wsdl2java/urlDownloads/http---127.0.0.1-ESBService-Example-wsdl.wsdl'.: This file was not found: file:/E:/IDE/sts-bundle/workspaces/java/hermes-webapplet/client/target/axistools/wsdl2java/urlDownloads/MySchema.xsd1.xsd -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:axistools-maven-plugin:1.4:wsdl2java (default) on project client: Error generating Java code from WSDL.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
h22fl7wq

h22fl7wq1#

您的问题与XSDMap有关。请尝试将wsdl和XSD下载到您的工作区并生成Java类:

<configuration>
    <packageSpace>com.xyz</packageSpace>
    <sourceDirectory>${basedir}/src/wsdl/rpc</sourceDirectory>
    <outputDirectory>${basedir}/src/wsdl/rpc</outputDirectory>
</configuration

相关问题