1

Spring-WS を (フレームワークによって生成された WSDL を使用して) Web サービスを実装するための基礎として使用します。WAR ファイルと同様に、私たちのビルドは、Web サービス メソッドのスキーマ生成 DTO とスタブで構成されるクライアント側 JAR (Java クライアントと独自のエンド ツー エンド機能テストで使用するため) を生成します。これらは wsimport (JAX-WS) を使用して生成されます。問題は、これが複数ステップのビルド プロセスを引き起こすことです。

  1. サーバー WAR ファイルをビルドします。
  2. Tomcat を開始します (WSDL を使用可能にするため)。
  3. クライアント側スタブを生成します (wsimport で WSDL URL を指定します)。

Web サービスを開始せずに WSDL を生成する方法はありますか? その後、1 つのステップですべてを構築できます。

4

2 に答える 2

3

このコード例は、Ant タスクの基礎に適しています。

import javax.xml.stream.XMLStreamException;
import javax.xml.transform.TransformerFactory;

import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;

....

private String generateWsdlFromSpringInfrastructure() throws Exception
{
    // We only need to specify the top-level XSD
    FileSystemResource messagesXsdResource = new FileSystemResource("C:/MyProject/xsds/my-messages.xsd");
    CommonsXsdSchemaCollection schemaCollection = new CommonsXsdSchemaCollection(new Resource[] {messagesXsdResource});
    // In-line all the included schemas into the including schema
    schemaCollection.setInline(true);
    schemaCollection.afterPropertiesSet();

    DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
    definition.setSchemaCollection(schemaCollection);
    definition.setPortTypeName(portTypeName);
    definition.setLocationUri("http://localhost:8080/myProject/services");
    definition.setTargetNamespace("http://www.acme.com/my-project/definitions");
    definition.afterPropertiesSet();

    StringResult wsdlResult = new StringResult();
    TransformerFactory.newInstance().newTransformer().transform(definition.getSource(), wsdlResult);
    return wsdlResult.toString();
}
于 2010-10-08T11:23:27.623 に答える