10

基本的に、プロキシ メソッドを介して mtom soap メッセージを送信する Web サービス クライアントを作成したいと考えています。Web サービス wsdl からサービス アーティファクトを作成しました。メッセージは正しく作成されますが、mtom を有効にして添付ファイルを追加すると、添付ファイルは常にインラインで送信され、別の MIME 部分では送信されません。そのような mtom が有効になっていますが、何らかの理由でメッセージを最適化しないことを決定し、インラインで送信します。同じコードを soapui で実行すると正しい結果が得られるので、サービス自体がそれを受け入れることがわかります。

SOAP リクエストを作成して送信するための基本的なコードを次に示します。mtomfeature を有効にしますが、soapBinding.setMTOMEnabled(true); 両方の方法でデバッグして((SOAPBinding) binding).isMTOMEnabled()、有効に設定されていることを確認しました。

// initiate services....

// create service and enable mtom
WebServiceBlah service = new WebServiceBlah(new URL(wsdlURL), SERVICE_NAME);
WebServiceBlahPort port = service.getWebServiceBlahPort(new MTOMFeature(true, 3072));

// load file
File file = new File("/home/mypdf.pdf");
FileInputStream fileinputstream = new FileInputStream(file);
int numberBytes = fileinputstream.available();
byte bytearray[] = new byte[numberBytes];
fileinputstream.read(bytearray);
fileinputstream.close();

// create uploadResult
UploadResult request = new UploadResult();

// create attachment
AttachmentType attachment = new AttachmentType();
attachment.setContentType("application/doc");
attachment.setValue(bytearray);

// create result and add attachment to it
RenderedResult result = new RenderedResult();
result.setResult(attachment);
result.setResultContentType("pdf");
result.setResultName("a pdf file");

// add result to request
request.getResult().add(result);

// send request
port.UploadResults(request);

以下に示すように、添付ファイルがインラインで送信されます。(Wireshark でキャプチャ)

POST /blah/ws/ HTTP/1.1
Content-type: multipart/related;start="<rootpart*15c3ee3b-60c7-4726-a52c-8080965e4536@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:15c3ee3b-60c7-4726-a52c-8080965e4536";start-info="text/xml"
Soapaction: ""
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
User-Agent: JAX-WS RI 2.1.6 in JDK 6
Host: 123.123.123.123
Connection: keep-alive
Content-Length: 12372

--uuid:15c3ee3b-60c7-4726-a52c-8080965e4536    
Content-Id: <rootpart*15c3ee3b-60c7-4726-a52c-8080965e4536@example.jaxws.sun.com>    
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"    
Content-Transfer-Encoding: binary

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header></S:Header>
<S:Body>
<ns2:uploadResult xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
    <renderedResult>
        <result xmime:contentType="application/doc">JVBERi0xLjQKJaqrrK0KNCAwIG9iago8</result>
        <resultContentType>pdf</resultContentType>
        <resultName>a pdf file</resultName>
    </renderedResult>
</ns2:uploadResult>
</S:Body>
</S:Envelope>
--uuid:15c3ee3b-60c7-4726-a52c-8080965e4536

私が望むのは、結果タグの添付ファイルをインライン タグに置き換え、添付ファイルを別の MIME 部分の SOAP メッセージに追加することです。例えば

<result xmime:contentType='application/doc'>
    <inc:Include href="cid:myid3" xmlns:inc='http://www.w3.org/2004/08/xop/include'/>
</result>

そして、以下が石鹸メッセージに追加されました

------=_Part_10_28027205.1314348995670
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-ID: cid:myid3
Content-Disposition: attachment; name="mypdf.pdf"
JVBERi0xLjQKJaqrrK0KNCAwIG9iago8
4

2 に答える 2

1

MTOM 添付ファイルが実際に使用されるかどうかに影響を与える可能性があるものは多数あります。

@MTOMサーバーでは、まず明らかなことです。サービスの実装に注釈があることを確認してください。プロパティを使用して、この注釈からしきい値を調整することもできます (SteveJ が既に述べたように) threshold()

サーバー上のハンドラーが、MTOM 添付ファイルが使用されているかどうかに干渉することがあります。SOAP メッセージを文字列またはバイト配列にシリアル化するすべてのハンドラー (メッセージ コンテンツをログに書き込むスタイル ハンドラーのデバッグで一般的) は、MTOM 添付ファイルの使用を妨げます。可能であれば、ハンドラー チェーンを無効にして、その後 MTOM 添付ファイルが届くかどうかを確認してください。

于 2013-05-03T05:32:12.367 に答える