Jaxws和MTOM似乎没有用

时间:2015-04-28 06:26:32

标签: web-services wsdl jax-ws soapui mtom

我想使用MTOM通过Webservice(jaxws)发送docx文档。

以下是我的wsdl的摘录:

<xsd:element name="createDocumentResponse">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="docContent" type="xsd:base64Binary" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

我想使用MTOM,所以我用@MTOM

注释web服务
@WebService(endpointInterface = "de.xy.crm.services.ws...")
@MTOM(enabled = true, threshold = 1024)
public class MyWebservice....

文档的内容设置如下:

byte[] convertedDocument = convert(docx);
CreateDocumentResponse response = new CreateDocumentResponse();
response.setDocContent(convertedDocument);

现在,当我使用SOAP UI测试它时,似乎已启用MTOM,但实际内容不是作为附件发送而是内联:

HTTP/1.1 200 OK
Content-Type: multipart/related;start="<rootpart*5544634d-146f-42e7-9c76-    38efd118acfc@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:5544634d-146f-42e7-9c76-38efd118acfc";start-info="text/xml"
Transfer-Encoding: chunked
Server: Jetty(8.1.3.v20120522)

--uuid:5544634d-146f-42e7-9c76-38efd118acfc
Content-Id: <rootpart*5544634d-146f-42e7-9c76-   38efd118acfc@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:Header><version   xmlns="http://ws.services.crm.vkb.de/BSIWebService/">2015.2.0.qualifier</version ></S:Header><S:Body><ns2:createDocumentResponse  xmlns:ns2="http://ws.services.crm.vkb.de/BsiWebService/"> <docContent>UEsDBBQACAAIABVDnEYAAAAAAAAAAAAAAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbLWV y27CMBBFfyXytiKGLqqqIrDoY9kilUrdGm...

我的错在哪里?

1 个答案:

答案 0 :(得分:2)

在JAX-WS webService中使用@MTOM注释和@WebService注释应该足以启用MTOM并将字节作为附件从服务器发送到客户端。< / p>

但是您正在使用@MTOM(enabled = true, threshold = 1024)。在java documentation says中,阈值参数具有以下描述:

  

MTOM阈值的属性。启用MTOM时,二进制数据   超过此大小(以字节为单位)将进行XOP编码或作为附件发送。   此属性的值必须始终为&gt; = 0.默认值为0.

因此,我认为唯一可能错误的是您发送的文件大小不超过1024.尝试发送更大的文档,或删除threshold @MTOM参数注释由于它的默认值为0,每个文档将作为附件发送。

希望这有帮助,