40.3. Stub 코드 생성

40.3.1. 개요

비동기 호출 스타일에는 SEI에 정의된 전용 비동기 메서드에 대한 추가 스텁 코드가 필요합니다. 이 특수 스텁 코드는 기본적으로 생성되지 않습니다. 비동기 기능을 전환하고 필수 스텁 코드를 생성하려면 WSDL 2.0 사양의 매핑 사용자 지정 기능을 사용해야 합니다.

사용자 지정을 사용하면 Maven 코드 생성 플러그인에서 스텁 코드를 생성하는 방식을 수정할 수 있습니다. 특히 WSDL-to-Java 매핑을 수정하고 특정 기능을 전환할 수 있습니다. 여기에서 사용자 지정은 비동기 호출 기능을 전환하는 데 사용됩니다. 사용자 지정은 jaxws:bindings 태그를 사용하여 정의한 바인딩 선언을 사용하여 지정됩니다( jaxws 접두사가 http://java.sun.com/xml/ns/jaxws 네임스페이스와 연결되어 있음). 바인딩 선언을 지정하는 방법은 다음 두 가지가 있습니다.

외부 바인딩 선언
외부 바인딩 선언을 사용할 때 jaxws:bindings 요소는 WSDL 계약과 별도로 파일에 정의됩니다. 스텁 코드를 생성할 때 코드 생성기에 바인딩 선언 파일의 위치를 지정합니다.You specify the location of the binding declaration file to code generator when you generate the stub code.
포함된 바인딩 선언
포함된 바인딩 선언을 사용하는 경우 jaxws:bindings 요소를 WSDL 계약에서 직접 포함시켜 WSDL 확장 프로그램으로 처리합니다. 이 경우 jaxws:bindings 의 설정은 바로 부모 요소에만 적용됩니다.

40.3.2. 외부 바인딩 선언 사용

비동기 호출에서 전환하는 바인딩 선언 파일에 대한 템플릿은 예 40.2. “비동기 바인딩 선언에 대한 템플릿” 에 표시됩니다.

예 40.2. 비동기 바인딩 선언에 대한 템플릿

<bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
          wsdlLocation="AffectedWSDL"
          xmlns="http://java.sun.com/xml/ns/jaxws">
  <bindings node="AffectedNode">
    <enableAsyncMapping>true</enableAsyncMapping>
  </bindings>
</bindings>

여기서 AffectedWSDL 은 이 바인딩 선언의 영향을 받는 WSDL 계약의 URL을 지정합니다. AffectedNode 는 WSDL 계약의 노드(또는 노드)가 이 바인딩 선언의 영향을 받는 노드(또는 노드)를 지정하는 XPath 값입니다. 전체 WSDL 계약을 사용하려면 AffectedNodewsdl:definitions 로 설정할 수 있습니다. 비동기 호출 기능을 활성화하려면 jaxws:enableAsyncMapping 요소가 true 로 설정됩니다.

예를 들어 GreeterAsync 인터페이스에 대해서만 비동기 메서드를 생성하려는 경우 이전 바인딩 선언에서 <bindings node="wsdl:definitions/wsdl:portType[@name='GreeterAsync']">을 지정할 수 있습니다.

바인딩 선언이 파일에 저장된다고 가정하면 예 40.3. “소비자 코드 생성” 에 표시된 대로 POM을 설정합니다.

예 40.3. 소비자 코드 생성

<plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <version>${cxf.version}</version>
  <executions>
    <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration>
        <sourceRoot>outputDir</sourceRoot>
        <wsdlOptions>
          <wsdlOption>
            <wsdl>hello_world.wsdl</wsdl>
            <extraargs>
              <extraarg>-client</extraarg>
              <extraarg>-b async_binding.xml</extraarg>
            </extraargs>
          </wsdlOption>
        </wsdlOptions>
      </configuration>
      <goals>
        <goal>wsdl2java</goal>
      </goals>
    </execution>
  </executions>
</plugin>

b 옵션은 코드 생성기에 외부 바인딩 파일을 찾을 위치를 알려줍니다.

코드 생성기에 대한 자세한 내용은 44.2절. “cxf-codegen-plugin” 에서 참조하십시오.

40.3.3. 포함된 바인딩 선언 사용

jaxws:bindings 요소와 연결된 jaxws:enableAsynchMapping 하위를 WSDL에 직접 배치하여 서비스를 정의하는 WSDL 문서에 직접 바인딩 사용자 지정을 포함할 수도 있습니다. jaxws 접두사에 대한 네임스페이스 선언도 추가해야 합니다.

예 40.4. “비동기 매핑을 위한 임베디드 바인딩 선언이 있는 WSDL” 작업에 대한 비동기 매핑을 활성화하는 포함 바인딩 선언이 있는 WSDL 파일을 표시합니다.

예 40.4. 비동기 매핑을 위한 임베디드 바인딩 선언이 있는 WSDL

<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
                  ...
                  xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
                  ...>
  ...
  <wsdl:portType name="GreeterAsync">
    <wsdl:operation name="greetMeSometime">
      <jaxws:bindings> <jaxws:enableAsyncMapping>true</jaxws:enableAsyncMapping> </jaxws:bindings>
      <wsdl:input name="greetMeSometimeRequest"
                  message="tns:greetMeSometimeRequest"/>
      <wsdl:output name="greetMeSometimeResponse"
                   message="tns:greetMeSometimeResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  ...
</wsdl:definitions>

WSDL 문서에 바인딩 선언을 포함할 때 선언의 영향을 받는 범위를 제어할 수 있습니다.When including the binding declaration into the WSDL document, you can control the scope of the declaration by changing where you place the declaration. 선언이 wsdl:definitions 요소의 자식으로 배치되면 코드 생성기는 WSDL 문서에 정의된 모든 작업에 대해 비동기 메서드를 만듭니다. 이 요소가 wsdl:portType 요소의 자식으로 배치되면 코드 생성기는 인터페이스에 정의된 모든 작업에 대해 비동기 메서드를 만듭니다.If it is placed as a child of a wsdl:portType element the code generator creates asynchronous methods for all of the operations defined in the interface. 이 요소가 wsdl:operation 요소의 자식으로 배치되면 코드 생성기는 해당 작업에 대해서만 비동기 메서드를 만듭니다.If it is placed as a child of a wsdl:operation element the code generator creates asynchronous methods for only that operation.

포함된 선언을 사용할 때 코드 생성기에 특별한 옵션을 전달할 필요가 없습니다.It is not necessary to pass any special options to the code generator when using embedded declarations. 코드 생성기가 이를 인식하고 그에 따라 조치를 취할 것입니다.

40.3.4. 생성된 인터페이스

이러한 방식으로 스텁 코드를 생성한 후 GreeterAsync SEI(파일 GreeterAsync.java)는 예 40.5. “Asynchronous Invocations를 위한 메서드의 서비스 엔드포인트 인터페이스” 와 같이 정의됩니다.

예 40.5. Asynchronous Invocations를 위한 메서드의 서비스 엔드포인트 인터페이스

package org.apache.hello_world_async_soap_http;

import org.apache.hello_world_async_soap_http.types.GreetMeSometimeResponse;
...

public interface GreeterAsync
{
  public Future<?> greetMeSometimeAsync(
        java.lang.String requestType,
        AsyncHandler<GreetMeSometimeResponse> asyncHandler
    );

    public Response<GreetMeSometimeResponse> greetMeSometimeAsync(
        java.lang.String requestType
    );

    public java.lang.String greetMeSometime(
        java.lang.String requestType
    );
}

일반적인 동기 방법 외에도 greetMeSometime() 은 greetMeSometime 작업에 대해 두 가지 비동기 메서드도 생성됩니다.

  • 콜백 접근 방법 public future<?>greetMeSomtimeAsyncjava.lang.StringrequestTypeAsyncHandler<GreetMeSomtimeResponse>asyncHandler
  • 폴링 접근 방식 공개응답<GreetMeSomeTimeResponse>greetMeSometimeAsyncjava.lang.StringrequestType