基本的には、Webサービスクライアントを作成して、プロキシメソッド経由でmtom soapメッセージを送信します。 Webサービスwsdlからサービス成果物を作成しました。メッセージは正しく作成されますが、mtomを有効にして添付ファイルを追加すると、添付ファイルは常にインラインで送信され、別のMIME部分ではなく送信されます。そのようなmtomは有効になっていますが、なんらかの理由でメッセージを最適化しないように決定し、インラインで送信します。 soapuiで同じコードを実行すると正しい結果が得られるので、サービス自体がそれを受け入れることがわかります。JAX-WSは常にMTOM添付ファイルをインラインで送信します
ここに私の石鹸要求を作成して送信するための私の基本的なコードです。 私は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*[email protected]>";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*[email protected]>
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>
そして、物事の数は、MTOM添付ファイルが実際使用しているかどうかに影響を与えることができ、SOAPメッセージ
------=_Part_10_28027205.1314348995670
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-ID: cid:myid3
Content-Disposition: attachment; name="mypdf.pdf"
JVBERi0xLjQKJaqrrK0KNCAwIG9iago8
これを解決しましたか?私はまったく同じ問題を抱えています。 JAX-WSのドキュメントでは、「JAXB 2.0仕様で定義されているように、xs:base64Binaryとxs:hexBinaryからjavaへのマッピングはbyte []です。 JAX-WSの実装では、バイト[]サイズの1KBのしきい値が設定されています。このしきい値は、クライアント側のRequestContextとサーバー側のMessageContextの実装固有のプロパティcom.sun.xml.ws.developer.JAXWSProperties.MTOM_THRESHOLD_VALUEを使用して変更できます。上記のコードでは、しきい値を3072に設定しています。これを0,1に設定すると、違いはありません。 – SteveJ