검색

9.2. MTOM을 사용하도록 데이터 유형 주석

download PDF

9.2.1. 개요

WSDL에서 이미지 파일 또는 사운드 파일과 같은 바이너리 데이터 블록을 전달하는 데이터 유형을 정의할 때 xsd:base64Binary 유형의 데이터가 될 요소를 정의합니다. 기본적으로 xsd:base64Binary 형식의 모든 요소가 MTOM을 사용하여 직렬화될 수 있는 byte[] 가 생성됩니다. 그러나 코드 생성기의 기본 동작은 직렬화를 최대한 활용하지 않습니다.However, the default behavior of the code generators does not take full advantage of the serialization.

MTOM을 완전히 활용하려면 서비스의 WSDL 문서 또는 바이너리 데이터 구조를 구현하는 JAXB 클래스에 주석을 추가해야 합니다. WSDL 문서에 주석을 추가하면 코드 생성기가 바이너리 데이터에 대한 스트리밍 데이터 처리기를 생성하도록 강제 적용합니다. JAXB 클래스에 주석을 달려면 적절한 콘텐츠 유형을 지정해야 하며 바이너리 데이터가 포함된 필드의 유형 사양을 변경해야 할 수도 있습니다.

9.2.2. WSDL 첫 번째

예 9.1. “MTOM에 대한 메시지” 하나의 문자열 필드, 하나의 정수 필드 및 바이너리 필드를 포함하는 메시지를 사용하는 웹 서비스의 WSDL 문서를 보여줍니다. 바이너리 필드는 큰 이미지 파일을 전송하기 위한 것이므로 일반 SOAP 메시지의 일부로 보내는 것은 적절하지 않습니다.

예 9.1. MTOM에 대한 메시지

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="XrayStorage"
    targetNamespace="http://mediStor.org/x-rays"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://mediStor.org/x-rays"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:xsd1="http://mediStor.org/types/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <types>
    <schema targetNamespace="http://mediStor.org/types/"
            xmlns="http://www.w3.org/2001/XMLSchema">
      <complexType name="xRayType">
        <sequence>
          <element name="patientName" type="xsd:string" />
          <element name="patientNumber" type="xsd:int" />
          <element name="imageData" type="xsd:base64Binary" />
        </sequence>
      </complexType>
      <element name="xRay" type="xsd1:xRayType" />
    </schema>
  </types>

  <message name="storRequest">
    <part name="record" element="xsd1:xRay"/>
  </message>
  <message name="storResponse">
    <part name="success" type="xsd:boolean"/>
  </message>

  <portType name="xRayStorage">
    <operation name="store">
      <input message="tns:storRequest" name="storRequest"/>
      <output message="tns:storResponse" name="storResponse"/>
    </operation>
  </portType>

  <binding name="xRayStorageSOAPBinding" type="tns:xRayStorage">
    <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="store">
      <soap12:operation soapAction="" style="document"/>
      <input name="storRequest">
        <soap12:body use="literal"/>
      </input>
      <output name="storResponse">
        <soap12:body use="literal"/>
      </output>
    </operation>
  </binding>
  ...
</definitions>

MTOM을 사용하여 메시지의 바이너리 부분을 최적화된 첨부 파일로 보내려면 바이너리 데이터가 포함된 요소에 xmime:expectedContentTypes 속성을 추가해야 합니다. 이 속성은 http://www.w3.org/2005/05/xmlmime 네임스페이스에 정의되어 있으며 요소가 포함할 것으로 예상되는 MIME 유형을 지정합니다. MIME 유형의 쉼표로 구분된 목록을 지정할 수 있습니다. 이 속성의 설정은 코드 생성기가 데이터에 대한 JAXB 클래스를 만드는 방법을 변경합니다. 대부분의 MIME 유형의 경우 코드 생성기는 DataHandler를 생성합니다. 이미지용과 같은 일부 MIME 유형에는 매핑이 정의되어 있습니다.

참고

대부분의 경우 application/octet-stream 을 지정합니다.

예 9.2. “MTOM용 바이너리 데이터” MTOM 사용을 위해 예 9.1. “MTOM에 대한 메시지” 에서 xRayType 을 수정하는 방법을 보여줍니다.

예 9.2. MTOM용 바이너리 데이터

...
  <types>
    <schema targetNamespace="http://mediStor.org/types/"
            xmlns="http://www.w3.org/2001/XMLSchema"
            xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
      <complexType name="xRayType">
        <sequence>
          <element name="patientName" type="xsd:string" />
          <element name="patientNumber" type="xsd:int" />
          <element name="imageData" type="xsd:base64Binary"
                   xmime:expectedContentTypes="application/octet-stream"/>
        </sequence>
      </complexType>
      <element name="xRay" type="xsd1:xRayType" />
    </schema>
  </types>
...

xRayType 에 대해 생성된 JAXB 클래스에는 더 이상 바이트[] 가 포함되어 있지 않습니다. 대신 코드 생성기가 xmime:expectedContentTypes 특성을 확인하고 imageData 필드에 대한 DataHandler를 생성합니다.

참고

MTOM을 사용하기 위해 바인딩 요소를 변경할 필요가 없습니다. 런타임은 데이터가 전송될 때 적절한 변경을 수행합니다.

9.2.3. Java 첫 번째

Java 첫 개발을 수행하는 경우 다음을 수행하여 JAXB 클래스 MTOM을 준비시킬 수 있습니다.

  1. 바이너리 데이터를 보유한 필드가 DataHandler인지 확인합니다.
  2. 스트리밍하려는 데이터가 MTOM 첨부 파일로 포함된 필드에 @XmlMimeType() 주석을 추가합니다.

예 9.3. “MTOM용 JAXB 클래스” MTOM 사용에 대한 주석이 있는 JAXB 클래스를 표시합니다.

예 9.3. MTOM용 JAXB 클래스

@XmlType
public class XRayType {
    protected String patientName;
    protected int patientNumber;
    @XmlMimeType("application/octet-stream")
    protected DataHandler imageData;
  ...
}
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.