3

Axis を使用して Java で Web サービスにアクセスする方法を理解しようとしています。

私が理解している限り、これが私がしなければならないことです:

  1. WSDL ファイル + 軸ツールを使用して Java ファイルを生成します。
  2. 生成された Java ファイルをコンパイルおよびパッケージ化し、これらの接続メソッドを使用してそれらのオブジェクトを使用します。

これをやろうとして、ここで私は立ち往生しています:

http://www.service-repository.com/からランダムな Web サービスを選択し ました。次の方法で axistools-maven-plugin を使用しました。

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>axistools-maven-plugin</artifactId>
            <configuration>
                <urls>
                    <!--<url>http://soap.amazon.com/schemas2/AmazonWebServices.wsdl</url>-->
                    <!--<url>http://ws.xwebservices.com/XWebEmailValidation/V2/XWebEmailValidation.wsdl</url>-->
                    <url>http://mathertel.de/AJAXEngine/S02_AJAXCoreSamples/OrteLookup.asmx?WSDL</url>
                </urls>
                <!--<sourceDirectory>${project.build.sourceDirectory}/wsdl</sourceDirectory>-->
                <packageSpace>com.company.wsdl</packageSpace>
                <testCases>true</testCases>
                <serverSide>true</serverSide>
                <subPackageByFileName>true</subPackageByFileName>
                <outputDirectory>${project.build.directory}/src/generated-sources</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

問題は次のとおりです。

mvn generate-sources を正常に実行でき、Java ファイルが生成されます。しかし、これらの Java ファイルをコンパイルできないようです。mvn clean install を実行すると、一連のコンパイル エラーが発生します。どのステップが欠けていますか?

4

1 に答える 1

2

私のコメントの1つに対するあなたの回答に基づいて、私の提案は、Java6に含まれているJAX-WSRIまたはApacheCXFのようなJAX -WS実装を使用することです(どちらも古いAxisよりもはるかに優れたWSスタックです) 。

JAX-WSRIとそのjaxws-maven-pluginに基づく例を次に示します。

<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.stackoverflow</groupId>
  <artifactId>Q3479139</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>Q3479139</name>
  <url>http://maven.apache.org</url>
  <repositories>
    <repository>
      <id>maven2-repository.dev.java.net</id>
      <name>Java.net Repository for Maven 2</name>
      <url>http://download.java.net/maven/2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>maven2-repository.dev.java.net</id>
      <url>http://download.java.net/maven/2</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>jaxws-rt</artifactId>
      <version>2.2.1</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>1.12</version>
        <executions>
          <execution>
            <goals>
              <goal>wsimport</goal>
            </goals>
            <configuration>
              <wsdlUrls>
                <wsdlUrl>http://ws.xwebservices.com/XWebEmailValidation/V2/XWebEmailValidation.wsdl</wsdlUrl>
              </wsdlUrls>
              <!-- The name of your generated source package -->
              <packageName>com.example.myschema</packageName>
              <!-- generate artifacts that run with JAX-WS 2.0 runtime -->
              <target>2.0</target>
              <!-- Specify where to place generated source files -->
              <sourceDestDir>${project.build.directory}/generated-sources/wsimport</sourceDestDir>
            </configuration>
          </execution>
        </executions>
        <!-- if you want to use a specific version of JAX-WS, you can do so like this -->
        <dependencies>
          <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-tools</artifactId>
            <version>2.2.1</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

そして、これは非常に基本的なテストケース(Mavenプロジェクトの一部)であり、生成されたクラスを使用したWebサービスの呼び出しを示しています。

package com.example.myschema;

import junit.framework.TestCase;

public class EmailValidationTest extends TestCase {

    XWebEmailValidationInterface service = new EmailValidation().getEmailValidation();
    ValidateEmailRequest request = new ValidateEmailRequest();
    ValidateEmailResponse response = null;

    public void testEmails() {
        request.setEmail("foo@bar.com");
        response = service.validateEmail(request);
        assertEquals("EMAIL_SERVER_NOT_FOUND", response.getStatus());

        request.setEmail("foo@gmail.com");
        response = service.validateEmail(request);
        assertEquals("NOT_VALID", response.getStatus());
    }
}
于 2010-08-13T21:17:21.630 に答える