基本上我想創建一個Web服務客戶端通過代理方法來發送一個MTOM SOAP消息。我已經從Web服務wsdl中創建了我的服務工件。消息已正確創建,但是,當啓用mtom並添加附件時,附件始終以內聯方式發送,而不是單獨的MIME部分。它像mtom一樣被啓用,但由於某種原因,它決定不優化消息,因此將它內聯發送。通過soapui運行相同的代碼給出正確的結果,所以我知道服務本身會接受它。JAX-WS總是發送MTOM附件內聯
這裏是我創建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*[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
我想是在結果標籤附連到與所述內嵌代碼被替換和安裝添加到SOAP消息在不同的MIME部分。例如
<result xmime:contentType='application/doc'>
<inc:Include href="cid:myid3" xmlns:inc='http://www.w3.org/2004/08/xop/include'/>
</result>
然後將以下加入到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 byte []大小的閾值。這個閾值可以在客戶端的RequestContext並在MessageContext的在服務器端使用執行特定的屬性com.sun.xml.ws.developer.JAXWSProperties.MTOM_THRESHOLD_VALUE進行修改。您在上面的代碼中將閾值設置爲3072。設置爲0,1,...似乎沒有區別。 – SteveJ