메인 컨텐츠로 가기

developerWorks 이용 약관에 동의하시는 경우 제출을 클릭하십시오. 이용 약관 보기.

developerWorks에 처음 로그인하면 developerWorks프로파일이 생성됩니다.귀하의 프로파일에서 동의하신 내용이 공개되지만 이 사항은 언제든지 변경 가능합니다. 귀하의 성명(숨김으로 체크되어 있어도 표시됩니다)과 디스플레이 이름은 게시한 컨텐츠나 사이트 엑세스시 표시됩니다.

모든 정보가 안전하게 전송되었습니다.

  • 닫기 [x]

처음 developerWorks에 로그인할 때 프로파일이 작성되므로, 이를 위해 디스플레이 이름을 선택해야 합니다. 선택하신 디스플레이 이름은 developerWorks에 게시한 컨텐츠에 표시됩니다.

3글자 이상 31글자 이하의 길이로 사용 가능합니다. dW커뮤니티 내에서는 보안상 이메일주소를 제외한 다른 이름을 지정하셔야 합니다.

developerWorks 이용 약관에 동의하시는 경우 제출을 클릭하십시오. 이용 약관 보기.

모든 정보가 안전하게 전송되었습니다.

  • 닫기 [x]

WSS4J/Axis2 API 사용하기, Part 2: WS-Signed 및 Encrypted MTOM(Message Transmission Optimization Mechanism)/XOP(XML-binary Optimized Packaging) 첨부를 Axis2/Rampart 웹 서비스에 전송하기

Vikas Kumar, Lead Developer, Marlabs, Inc.
Vikas Kumar
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.

요약:  WSS4J 및 AXIS2 API를 사용하여 WS-Signed 및 WS-Encrypted SOAP 메시지를 전송하는 방법에 대해 설명한 이 기사 시리즈의 Part 1에 이어 시리즈의 이 마지막 기사에서는 WSS4J/AXIS2 API를 사용하여 MTOM(Message Transmission Optimization Mechanism)/XOP(XML-binary Optimized Packaging) 지원 WS-Signed /WS-Encrypted SOAP 메시지를 전송하는 방법에 대해 집중적으로 다룹니다.

이 연재 자세히 보기

원문 게재일:  2010 년 6 월 29 일 번역 게재일:   2010 년 9 월 27 일
난이도:  중급 영어로:  보기 PDF:  A4 and Letter (33KB | 7 pages)Get Adobe® Reader®
페이지뷰:  2777 회
의견:  


MTOM/XOP를 사용하여 첨부 전송하기

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 지원 대 비MTOM 연결 형식

MTOM/XOP 접근방식을 사용하면 첨부는 실제로 SOAP 엔벨로프 외부에 있는 동안 <xop:Include> 태그를 사용하여 SOAP 엔벨로프에 논리적으로 계속 남아있다.

MTOM 지원 메시지:

<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" 뒤에 있는 첨부에 연관시킨다.


Axis2의 클라이언트 API

다음 코드 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


WS-Signature 및 WS-Encryption

다음으로 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>


참고자료

교육

제품 및 기술 얻기

  • 자신에게 가장한 적합한 방법으로 IBM 제품을 평가해 보자. 시험판 제품을 다운로드하거나, 온라인으로 제품을 사용해 보거나, 클라우드 환경에서 제품을 사용하거나, SOA Sandbox에서 SOA(Service Oriented Architecture)를 효과적으로 구현하는 방법을 배울 수 있다.

토론

  • My developerWorks 커뮤니티에 참여하자. 개발자가 이끌고 있는 블로그, 포럼, 그룹 및 wiki를 살펴보면서 다른 developerWorks 사용자와 의견을 나눌 수 있다.

필자소개

Vikas Kumar

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.

잘못된 도움말 신고

부정사용 신고

감사합니다. 이 항목은 운영자가 관심을 표시했습니다.


잘못된 도움말 신고

부정사용 신고

제출실패 신고. 나중에 다시 실행해주세요.


디벨로퍼웍스 로그인


IBM ID가 필요하세요?
IBM ID를 잊으셨습니까?


비밀번호를 잊으셨습니까?
비밀번호 변경

developerWorks 이용 약관에 동의하시는 경우 제출을 클릭하십시오. 이용 약관.

 


developerWorks에 처음 로그인하면 developerWorks프로파일이 생성됩니다.귀하의 프로파일에서 동의하신 내용이 공개되지만 이 사항은 언제든지 변경 가능합니다. 귀하의 성명(숨김으로 체크되어 있어도 표시됩니다)과 디스플레이 이름은 게시한 컨텐츠나 사이트 엑세스시 표시됩니다.

화면상에 보여지는 닉네임을 정하세요.

처음 developerWorks에 로그인할 때 프로파일이 작성되므로, 이를 위해 디스플레이 이름을 선택해야 합니다. 선택하신 디스플레이 이름은 developerWorks에 게시한 컨텐츠에 표시됩니다.

3글자 이상 31글자 이하의 길이로 사용 가능합니다. dW커뮤니티 내에서는 보안상 이메일주소를 제외한 다른 이름을 지정하셔야 합니다.

3개의 &이나 대쉬를 포함해주시고 31글자내로 제한해주세요.


developerWorks 이용 약관에 동의하시는 경우 제출을 클릭하십시오. 이용 약관.

 


아티클 순위

의견

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=20
Zone=SOA와 웹서비스
ArticleID=548084
ArticleTitle=WSS4J/Axis2 API 사용하기, Part 2: WS-Signed 및 Encrypted MTOM(Message Transmission Optimization Mechanism)/XOP(XML-binary Optimized Packaging) 첨부를 Axis2/Rampart 웹 서비스에 전송하기
publish-date=06292010
author1-email=vikas.arora@marlabsglobal.com
author1-email-cc=

태그

Help
검색 필드를 사용하여 My developerWorks 내에서 해당 태그가 사용된 모든 종류의 컨텐츠를 검색하십시오.

태그를 더 많이 보거나 적게 보기 위해 슬라이더 막대를 사용하십시오.

인기 태그는 특정 컨텐츠 존(예를 들어, 자바, 리눅스, WebSphere)의 최고 인기 태그를 보여줍니다.

내 태그는 특정 컨텐츠 존(예를 들어, 자바, 리눅스, WebSphere)의 귀하의 태그를 보여줍니다.

검색 필드를 사용하여 My developerWorks 내에서 해당 태그가 사용된 모든 종류의 컨텐츠를 검색하십시오. 인기 태그는 특정 컨텐츠 존(예를 들어, 자바, 리눅스, WebSphere)의 최고 인기 태그를 보여줍니다. 내 태그는 특정 컨텐츠 존(예를 들어, 자바, 리눅스, WebSphere)의 귀하의 태그를 보여줍니다.