Về cơ bản tôi muốn tạo một ứng dụng khách dịch vụ web để gửi thông điệp xà phòng mtom thông qua phương thức proxy. Tôi đã tạo các tạo phẩm dịch vụ của tôi tốt từ wsdl dịch vụ web. Thông báo được tạo chính xác, tuy nhiên khi tôi bật mtom và thêm tệp đính kèm, tệp đính kèm luôn được gửi nội tuyến chứ không phải trong phần mime riêng biệt. Của nó như mtom được kích hoạt nhưng đối với một số lý do nó quyết định không để tối ưu hóa tin nhắn và do đó gửi nó nội tuyến. Chạy cùng một mã thông qua soapui cho kết quả chính xác vì vậy tôi biết bản thân dịch vụ sẽ chấp nhận nó.JAX-WS luôn gửi các tệp đính kèm MTOM nội tuyến
Đây là mã cơ bản của tôi để tạo yêu cầu xà phòng và gửi đi. Tôi bật tính năng mtomfeature nhưng cũng đã thử thực hiện với soapBinding.setMTOMEnabled(true);
Đối với cả hai phương pháp tôi đã sửa lỗi với ((SOAPBinding) binding).isMTOMEnabled()
để kiểm tra xem nó có được đặt thành bật hay không.
// 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);
Điều tôi nhận được là tệp đính kèm của tôi được gửi nội tuyến như được thấy bên dưới. (Chụp bằng 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
Những gì tôi muốn là dành cho tập tin đính kèm trong thẻ kết quả được thay thế bằng các thẻ inline và tập tin đính kèm thêm vào thông điệp xà phòng trong một phần kịch câm khác nhau. ví dụ
<result xmime:contentType='application/doc'>
<inc:Include href="cid:myid3" xmlns:inc='http://www.w3.org/2004/08/xop/include'/>
</result>
Và rồi sau đây bổ sung vào thông điệp xà phòng
------=_Part_10_28027205.1314348995670
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-ID: cid:myid3
Content-Disposition: attachment; name="mypdf.pdf"
JVBERi0xLjQKJaqrrK0KNCAwIG9iago8
Bạn đã giải quyết vấn đề này chưa? Tôi có chung vấn đề đó. Tài liệu JAX-WS cũng nói điều này: 'Như được định nghĩa bởi đặc tả JAXB 2.0 xs: base64Binary và xs: hexBinary mapping tới java là byte []. Triển khai JAX-WS đã thiết lập ngưỡng 1KB byte []. Ngưỡng này có thể được sửa đổi bằng cách sử dụng thuộc tính cụ thể thực hiện com.sun.xml.ws.developer.JAXWSProperties.MTOM_THRESHOLD_VALUE trong RequestContext ở phía máy khách và trong MessageContext ở phía máy chủ. Bạn đang đặt ngưỡng thành 3072 trong mã của mình ở trên. Đặt giá trị này thành 0,1, ... dường như không tạo ra sự khác biệt nào. – SteveJ