mtom返回总是附件witi content-type =" image / png"

时间:2015-06-03 09:04:22

标签: java-metro-framework mtom

在我的soap mtom优化示例中,我已经实现了Tomcat 7上的一个项目,地铁(玻璃鱼)我已经获得了:

XSD

<xs:element name="retrievePicture" type="tns:retrievePicture"/>
<xs:complexType name="retrievePicture">
  <xs:sequence>
    <xs:element name="inImageNumber" type="xs:int"/>
  </xs:sequence>
</xs:complexType>

<xs:element name="retrievePictureResponse" type="tns:JPEGPictureType"/>
<xs:simpleType name="JPEGPictureType"
    xmime:expectedContentTypes="image/jpeg">
    <xs:restriction base="xs:base64Binary" />
</xs:simpleType>

WSDL

<definitions ... >
    <wsp:Policy
        wsu:Id="PictureManagerPortBinding_MTOM_Policy-PictureManagerPortBinding_MTOM_Policy">
        <ns1:OptimizedMimeSerialization
            xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"
            wsp:Optional="true" />
    </wsp:Policy>
    <types>
        <xsd:schema>
            <xsd:import namespace="http://service.ivan.com/" schemaLocation="PictureManagerService_schema1.xsd"/>
        </xsd:schema>
    </types>
    <message name="retrievePicture">
        <part name="parameters" element="tns:retrievePicture" />
    </message>
    <message name="retrievePictureResponse">
        <part name="parameters" element="tns:retrievePictureResponse" />
    </message>
    <portType name="PictureManager">
        <operation name="retrievePicture">
            <input
                wsam:Action="http://service.ivan.com/PictureManager/retrievePictureRequest"
                message="tns:retrievePicture" />
            <output
                wsam:Action="http://service.ivan.com/PictureManager/retrievePictureResponse"
                message="tns:retrievePictureResponse" />
        </operation>
    </portType>
    <binding name="PictureManagerPortBinding" type="tns:PictureManager">
        <wsp:PolicyReference
            URI="#PictureManagerPortBinding_MTOM_Policy-PictureManagerPortBinding_MTOM_Policy" />
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
            style="document" />
        <operation name="retrievePicture">
        ...
        </operation>
    </binding>
    <service name="PictureManagerService">
        ...
    </service>
</definitions>

SEI

@WebService(wsdlLocation="WEB-INF/wsdl/PictureManagerService.wsdl")
@MTOM
public class PictureManager {
    ....
    @WebMethod(operationName = "retrievePicture")
    public Image retrievePicture(
            @WebParam(name = "inImageNumber") final int inImageNumber) {
        java.awt.Image theImage = null;
        //logic for return Image according request
        return theImage;
    }
}

我的项目包括根据要求下载JPEG图像。 在Soapui,我得到以下原始回复:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: multipart/related; start="<rootpart*c069e1e8-2a0a-4ef7-8270-19bda938c27d@example.jaxws.sun.com>"; type="application/xop+xml"; boundary="uuid:c069e1e8-2a0a-4ef7-8270-19bda938c27d"; start-info="text/xml"
Transfer-Encoding: chunked
Date: Wed, 03 Jun 2015 08:03:55 GMT

--uuid:c069e1e8-2a0a-4ef7-8270-19bda938c27d
Content-Id: <rootpart*c069e1e8-2a0a-4ef7-8270-19bda938c27d@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><ns2:retrievePictureResponse xmlns:ns2="http://service.ivan.com/"><return><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:deba19db-0a7f-4367-82c3-b466e22f31fd@example.jaxws.sun.com"/></return></ns2:retrievePictureResponse></S:Body></S:Envelope>
--uuid:c069e1e8-2a0a-4ef7-8270-19bda938c27d
Content-Id: <deba19db-0a7f-4367-82c3-b466e22f31fd@example.jaxws.sun.com>
Content-Type: image/png
Content-Transfer-Encoding: binary

问题是内容类型&#34; image / png&#34;是错误的,因为我预期&#34; image / jpeg&#34;

1 个答案:

答案 0 :(得分:0)

由于我遇到了类似的问题,我不认为此代码段会生成DataHandler

<xs:simpleType name="JPEGPictureType"
    xmime:expectedContentTypes="image/jpeg">
    <xs:restriction base="xs:base64Binary" />
</xs:simpleType>

我仍在努力找出原因,但与此同时你也可以像我一样,我认为这对你也有帮助。只需直接使用元素retrievePictureResponse而不是使用xs:simpleType,即可使用此代码:

<xs:element name="retrievePictureResponse" type="xs:base64Binary" 
    xmime:expectedContentTypes="image/jpeg" />