2015-06-03 41 views
0

在我的肥皂MTOM優化的例子,我已經意識到在Tomcat 7,地鐵(GlassFish的)的項目中,我有:MTOM回報總是附件維提內容類型=「圖像/ PNG」

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*[email protected]>"; 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*[email protected]> 
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:[email protected]"/></return></ns2:retrievePictureResponse></S:Body></S:Envelope> 
--uuid:c069e1e8-2a0a-4ef7-8270-19bda938c27d 
Content-Id: <[email protected]> 
Content-Type: image/png 
Content-Transfer-Encoding: binary 

的問題是內容類型「圖像/ PNG」是錯誤的,因爲我本來期望「圖像/ JPEG」

回答

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" />