MTOM(Message Transmission Optimization Mechanism)/XOP(XML-binary Optimized Packaging)는 W3C(World Wide Web Consortium)에서 XML 정보 세트는 유지하면서 SOAP의 전송/연결 형식을 최적화하는 표준 방식이다. 다음과 같은 MTOM/XOP 접근방식의 장점 중 일부는 다음과 같다.
첨부를 허용하는 매우 단순한 웹 서비스의 경우(Axis2는 byte[]를 첨부의 인수로 지원함):
public class WSAttachmentService {
public void sendAttachments(String customerId, byte[] attachment){
try{
System.out.println(" attachment 0 "+new String(attachment));
}catch(Exception ex){
ex.printStackTrace();
}
}
}
|
위의 샘플 코드에서는 런타임에서 시스템 인쇄 명령문을 인쇄하면 첨부 매개변수가 초기화되며 그 결과 Axis2의 MessageContext API를 사용하여 첨부를 가져오지 않아도 된다. 이는 MTOM/XOP의 경우에나 MTOM을 사용하지 않는 경우에도 적용되지만 위에서 언급했듯이 MTOM/XOP 지원 접근방식을 사용할 수 있는 장점이 있다.
아래의 코드 목록에서는 MTOM/XOP 지원 메시지의 연결 형식과 신속한 참조를 위한 비MTOM 메시지 사이의 차이점을 강조한다.
MTOM/XOP 접근방식을 사용하면 첨부는 실제로 SOAP 엔벨로프 외부에
있는 동안 <xop:Include> 태그를
사용하여 SOAP 엔벨로프에 논리적으로 계속 남아있다.
<attachment>
<xop:Include
href="cid:1.urn:uuid:CDA722FAE92D8929D81261259412433@apache.org"
xmlns:xop="http://www.w3.org/2004/08/xop/include" />
</attachment>
--MIMEBoundaryurn_uuid_CDA722FAE92D8929D81261259411181
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-ID: <1.urn:uuid:CDA722FAE92D8929D81261259412433@apache.org>
...binary content...
|
MTOM을 사용하지 않으면 다음과 같은 인라인 바이너리 컨텐츠가 됨:
<attachment>
...binary content...
</attachment>
|
MTOM 지원 SOAP 메시지를 사용하면 서비스가 첨부를 투명하게 확보할 수 있다.
Axis2 런타임은 Content-Type이 "Content-Type: multipart/related;"이고 유형(Content-Type에서만)이 "type="application/xop+xml";"인 것으로 MTOM/XOP 지원 여부를 판단한다.
POST /IdMWSAttachment/services/WSAttachmentService HTTP/1.1
Content-Type: multipart/related;
boundary=MIMEBoundaryurn_uuid_CDA722FAE92D8929D81261259411181;
type="application/xop+xml";
start="<0.urn:uuid:CDA722FAE92D8929D81261259411182@apache.org>";
start-info="text/xml"
SOAPAction: "urn:anonOutInOp"
User-Agent: Axis2
Host: localhost:8181
Transfer-Encoding: chunked
1ecf
--MIMEBoundaryurn_uuid_CDA722FAE92D8929D81261259411181
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:CDA722FAE92D8929D81261259411182@apache.org>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body><impl:sendAttachments xmlns:impl="http://attachment.ws.idm.sample.com">
<customerId>Vikas</customerId>
<attachment>
<xop:Include
href="cid:1.urn:uuid:CDA722FAE92D8929D81261259412433@apache.org"
xmlns:xop="http://www.w3.org/2004/08/xop/include" />
</attachment>
</impl:sendAttachments></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_CDA722FAE92D8929D81261259411181
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-ID: <1.urn:uuid:CDA722FAE92D8929D81261259412433@apache.org>
...binary...
|
이 런타임에서는 "href" attribute's value <xop:Include>(위 예제의 경우 cid:1.urn:uuid:CDA722FAE92D8929D81261259412433@apache.org임)를 사용하며 "cid" 값을 사용하여 이를 SOAP 메시지에서 "--MIMEBoundaryurn_uuid_CDA722FAE92D8929D81261259411181" 뒤에 있는 첨부에 연관시킨다.
다음 코드 Listing에서는 Axis2를 사용하여 MTOM 지원 메시지를 전송하는 방법을 보여 준다.
opts.setProperty(Constants.Configuration.ENABLE_MTOM,Constants.VALUE_TRUE); |
또한 첨부 요소를 빌드하기 위해 OMElement를 사용할 때 매우 중요한 점은 아래에 표시된 것과 같이 SOAPFactory에서 메소드 호출에 "true"를 사용한다는 것이다.
createOMText(new DataHandler(fileDataSource), true);
// Start, Use with MTOM
FileDataSource fileDataSource = new FileDataSource("c:/dev2_aud.txt");
OMText data = fac.createOMText(new DataHandler(fileDataSource),
true); // parameter "true" is crucial
attachmentOM.addChild(data);
// End, Use with MTOM
|
다음으로 MTOM/XOP 지원 첨부를 사용할 때 WS-Signature 및 WS-Encrypted를 생성한다.
public OperationClient createSOAPRequestMsg(){
OperationClient operationClient = null;
String serverEPR =
"http://localhost:8181/IdMWSAttachment/services/WSAttachmentService";
try{
ServiceClient client = new ServiceClient();
operationClient = client.createClient(ServiceClient.ANON_OUT_IN_OP);
MessageContext outMsgCtx = new MessageContext();
Options opts = outMsgCtx.getOptions();
opts.setTo(new EndpointReference(serverEPR));
//opts.setProperty(Constants.Configuration.ENABLE_SWA,Constants.VALUE_TRUE);
opts.setProperty(Constants.Configuration.ENABLE_MTOM,Constants.VALUE_TRUE);
SOAPEnvelope envelope = creatSOAPEnvelopeAndReturnDocument();
// Now as the WSS4J API takes W3C Document object to work with, so now we have to cre
// W3C document using the above "envelope" (which is Axis2's API).
ByteArrayOutputStream baos = new ByteArrayOutputStream();
envelope.serialize(baos);
byte[] byts = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(byts);
// Here JAXP API
DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance();
docFac.setValidating(false);
docFac.setNamespaceAware(true);
DocumentBuilder builder = docFac.newDocumentBuilder();
Document document = builder.newDocument();
// Here now we would get the W3C document Object.
document = builder.parse(bais);
document = signSOAPEnvelopeMTOM(document);
outMsgCtx.setEnvelope(soapEnvelope);
// Next we convert the above W3C document object back to SOAPEnvelope
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
OutputFormat of = new OutputFormat("XML","UTF-8",true);
of.setIndenting(true);
XMLSerializer serializer = new XMLSerializer(baos1,of);
serializer.asDOMSerializer();
serializer.serialize(document.getDocumentElement());
StringReader sr = new StringReader(baos1.toString());
OMXMLParserWrapper omBuilder = getOMBuilderStringReader(sr);
SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
// very important step
outMsgCtx.setEnvelope(soapEnvelope);
//outMsgCtx.setEnvelope(envelope); // Non-Signed
operationClient.addMessageContext(outMsgCtx);
}catch(Exception ex){
ex.printStackTrace();
}
return operationClient;
}
|
WS-Signature 및 WS-Encrypted를 생성하는 방법
이 기사 시리즈의 Part 1에서는 WS-Signature 및 WS-Encrypted 메시지를 생성하는 방법에 대해 자세히 설명한다. 코드 샘플은 다음과 같다.
signSOAPEnvelopeMTOM(document); |
MTOM/XOP를 사용한 샘플 WS-Signature SOAP 메시지
POST /IdMWSAttachment/services/WSAttachmentService HTTP/1.1
Content-Type: multipart/related;
boundary=MIMEBoundaryurn_uuid_AD3F29B8C627E2FE371261519053021; type="application/xop+xml";
start="<0.urn:uuid:AD3F29B8C627E2FE371261519053022@apache.org>"; start-info="text/xml"
SOAPAction: "urn:anonOutInOp"
User-Agent: Axis2
Host: localhost:8181
Transfer-Encoding: chunked
20e5
--MIMEBoundaryurn_uuid_AD3F29B8C627E2FE371261519053021
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:AD3F29B8C627E2FE371261519053022@apache.org>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security
xmlns:wsse=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
soapenv:mustUnderstand="1">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#id-1">
<ds:Transforms>
<ds:Transform
Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>ufKMxezZOs7P68NINmvWCRN3hYE=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
mW5oBhMCiH9RU0+VFcBWy+Ce7RjmwjubQic7eE2z9OcHpcBkpGJc9QDliVtaaStmAUBWFbHPvG56
ZcAxXoQB0tJ+QS8Du+lvyKoKQ41AfEe91chOK5K0dz1x71ttaplRB3oGveETq6RAPPeBAAjh1PK3
IAsqg/R7QI4YZyQhkRM=
</ds:SignatureValue>
<ds:KeyInfo Id="KeyId-3AE1F9051C9DBDD6C812615190528592">
<wsse:SecurityTokenReference
xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="STRId-3AE1F9051C9DBDD6C812615190528593">
<wsse:KeyIdentifier
EncodingType=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0
#Base64Binary"
ValueType=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">
MIICKDCCAZECBEspM08wDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAklMMRIwEAY
DVQQHEwlXb29kIERhbGUxDjAMBgNVBAoTBURlVnJ5MQswCQYDVQQLEwJJVDEOMAwGA1UEAxMFVmlrYXMwHh
cNMDkxMjE2MTkyMTUxWhcNMTAwMzE2MTkyMTUxWjBbMQswCQYDVQQGEwJVUzELMAkGA1UECBMCSUwxEjAQB
gNVBAcTCVdvb2QgRGFsZTEOMAwGA1UEChMFRGVWcnkxCzAJBgNVBAsTAklUMQ4wDAYDVQQDEwVWaWthczCB
nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEArQFF9a+2DmMW2mWlSo3OA722ejV1cq+XDOc4iEaLEdPni8w
GBv1VX/WGKXmem6Xjp6UfqMF3UPKk8qOV/vThzZPJVO+HVfrTqZ2cFAxEgFwgrYFFirrKgoGlyIuiMD7Xrn
0A2vl2o2dBY4LUDQSrJ2YoBSs/K9QVj0lfGKn5gksCAwEAATANBgkqhkiG9w0BAQQFAAOBgQAhx8EN8Riea
1mg0wJCalkcMc5U60HlBQb2BDNMh+e6qUGGJey6ry6GM1RKBH5ewW5Cx7ZxLxSTUiHUvc7vDJz6PfxNQ
GuKESlwK7IrThuHamJo7nsAXpj8obsCjoGVDIR8yTTVEwFYfbvVZ54koyAJWKYA7SkCzJf8ouJNc3ZtLA==
</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
</wsse:Security>
</soapenv:Header>
<soapenv:Body
xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="id-1">
<impl:sendAttachments xmlns:impl="http://attachment.ws.idm.sample.com">
<customerId>Vikas</customerId>
<attachment>
...Q0UgIlhYRFZfSURNIiA7...
</attachment>
</impl:sendAttachments>
</soapenv:Body>
</soapenv:Envelope>
|
교육
- 메시지 전송 최적화 메커니즘에 대해 자세히 살펴보자.
- developerWorks의 SOA 및 웹 영역에서 기술을 향상시키는 데 필요한 참고자료를 얻을 수 있다.
- developerWorks
기술 행사 및 웹 캐스트를 통해 다양한 IBM 제품 및 IT 산업 주제에 대한 최신 정보를 얻을 수 있다.
- 무료 developerWorks Live!
briefing을 통해 최신 IBM 제품 및 도구에 대한 정보뿐만 아니라 IT 업계의 최신 경향까지도 빠르게 확인할 수 있다.
- Twitter의 developerWorks 페이지를 살펴보자.
- developerWorks
on-demand demos에서는 입문자를 위한 제품 설치 및 설정부터 숙련된 개발자를 위한 고급 기능까지 망라된 다양한 데모를 제공한다.
제품 및 기술 얻기
-
자신에게 가장한 적합한 방법으로 IBM
제품을 평가해 보자. 시험판 제품을 다운로드하거나, 온라인으로 제품을 사용해 보거나, 클라우드 환경에서 제품을 사용하거나,
SOA Sandbox에서
SOA(Service Oriented Architecture)를 효과적으로 구현하는 방법을 배울 수 있다.
토론
- My developerWorks 커뮤니티에 참여하자.
개발자가 이끌고 있는 블로그, 포럼, 그룹 및 wiki를 살펴보면서 다른 developerWorks 사용자와 의견을 나눌 수 있다.

Vikas has extensive experience working with J2EE, WebSphere Application Server 5.1/6.0/7.0, WebSphere MQ 5.3/6.0, WebSphere ESB, Mule ESB, Oracle, ORM Tools, Spring for the past 10 years. Vikas was also the Sr Developer for WebSphere Partner Gateway Express 6.0/ Enterprise 6.0 at IBM, India. Interests include J2EE, Web Services Architectures including Security, TX, Address, WebSphere App Server/ESB/MQ, Mule ESB, and exploring more innovative ways for solving different things using languages/scripts like Java, Perl, C. Currently exploring the features of SAXON XSLT parser for it's Java extensibilities.