Java Metro Framework - MTOM 返回始终附件 Witi 内容类型 = "image/png"



在我的soap客户机优化示例中,我已经实现了Tomcat 7 metro (glassfish)上的一个项目,其中我得到了:

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>
<<p> WSDL/strong>
<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

问题是内容类型"image/png"是错误的,因为我期望"image/jpeg"

因为我刚刚遇到了类似的问题,所以我认为这个代码片段不会生成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" />

相关内容

  • 没有找到相关文章

最新更新