使用JAX-RPC客户端从JAX-WS WebService获取附件

时间:2010-12-21 15:38:09

标签: java java-ee jax-ws attachment jax-rpc

当我们从JAX-RPC迁移到JAX-WS时,我正在尝试调用使用JAX-W / JAXB的WebService。客户端本身仍在使用JAX-RPC。 WSDL文件保持不变。

这样可以正常工作,因为没有附件。附件,它不起作用。客户说,没有。虽然可以在SOAP-Message中看到它们。

据我所知,JAX-WS确实使用MTOM将二进制数据放入消息中,而JAX-RPC使用MIME。

有可能以某种方式让它发挥作用吗?

以下是JAX-RPC消息的外观:

HTTP/1.1 200 OK
Date: Tue, 21 Dec 2010 15:24:10 GMT
Transfer-Encoding: chunked
Content-Type: multipart/related;boundary="----=_Part_6_5206227.1292945050584";type="text/xml";start="<soapPart>"
SOAPAction: "http://XXX"
X-Powered-By: Servlet/2.5 JSP/2.1

014a
------=_Part_6_5206227.1292945050584
Content-Type: text/xml; charset=utf-8
Content-Transfer-Encoding: 8bit
Content-ID: <soapPart>

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body><operationWithAttachments href="cid:operationWithAttachments"/></env:Body></env:Envelope>
0522

------=_Part_6_5206227.1292945050584
Content-Type: multipart/mixed; 
    boundary="----=_Part_5_12763436.1292945050570"
Content-ID: <operationWithAttachments>

------=_Part_5_12763436.1292945050570
Content-Type: application/pdf; name=HelloWorld.pdf
Content-Disposition: attachment; filename=HelloWorld.pdf

%PDF-1.4
%öäüß
1 0 obj
<<
/Type /Catalog
/Version /1.4
/Pages 2 0 R
>>
endobj
2 0 obj
<<
...

这里是新的JAX-WS消息:

HTTP/1.1 200 OK
Date: Tue, 21 Dec 2010 15:23:02 GMT
Transfer-Encoding: chunked
Content-Type: multipart/related;start="<rootpart*07499eba-7835-4fe0-bb07-a04801504fb5@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:07499eba-7835-4fe0-bb07-a04801504fb5";start-info="text/xml"
X-Powered-By: Servlet/2.5 JSP/2.1

02ba
--uuid:07499eba-7835-4fe0-bb07-a04801504fb5
Content-Id: <rootpart*07499eba-7835-4fe0-bb07-a04801504fb5@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns6:operationWithAttachments xmlns:ns6="XX" xmlns:ns5="XX" xmlns:ns4="XX" xmlns:ns3="XX" xmlns:ns2="XX" xmlns="XX">
00ba
<Include xmlns="http://www.w3.org/2004/08/xop/include" href="cid:9832a057-f692-4f48-ac7d-4dbd7ce76a74@example.jaxws.sun.com"/></ns6:operationWithAttachments></S:Body></S:Envelope>
0562

--uuid:07499eba-7835-4fe0-bb07-a04801504fb5
Content-Id: <9832a057-f692-4f48-ac7d-4dbd7ce76a74@example.jaxws.sun.com>
Content-Type: multipart/mixed; boundary="----=_Part_4_6279014.1292944982388"
Content-Transfer-Encoding: binary

------=_Part_4_6279014.1292944982388
Content-Type: application/pdf; name=HelloWorld.pdf
Content-Disposition: attachment; filename=HelloWorld.pdf

%PDF-1.4
%öäüß
1 0 obj
<<
/Type /Catalog
/Version /1.4
/Pages 2 0 R
>>
endobj
2 0 obj
<<
...

(我自己删除了名称空间,所以这不是问题)

这个想法是让它们变得相同。

有没有人这样做过?

非常感谢你的帮助

1 个答案:

答案 0 :(得分:2)

AFAIK你不能。 JAXRPC使用Soap With Attachments,JAXWS是更现代的MTOM。它们略有不同,不兼容。您可以禁用MTOM,但是您必须找到另一种流式传输附件(另一种服务)。