Spring -Веб-сервис WS с вложением MTOM -Тест Hello world

Я пытаюсь создать простой веб-сервис Spring, который при вызове возвращает вложение файла как часть ответа SOAP. Класс Enpoint показан ниже:

И, наконец, конечная точка

@PayloadRoot(namespace="http://ws.mypackage.com", localPart="downloadMessageRequest")
    @ResponsePayload
    public JAXBElement<DownloadResponseType> invoke(@RequestPayload DownloadMessageRequest req) throws Exception  {

        DownloadResponseType response = new DownloadResponseType();
        DownloadResponseType.PayLoad payload = new DownloadResponseType.PayLoad();          

        javax.activation.DataHandler dataHandler = new javax.activation.DataHandler(new FileDataSource("c:\\temp\\maven-feather.png"));
        payload.setMessagePayLoad(dataHandler);
        response.setPayLoad(payload);

        return objectFactory.createDownloadMessageResponse(response);

    }

Я хотел бы, чтобы ответ включал файл в виде вложения, аналогичного следующему ответу:

Content-Type: multipart/related; boundary=MIMEBoundary4A7AE55984E7438034;
                         type="application/xop+xml"; start="<0.09BC7F4BE2E4D3EF1B@apache.org>";
                         start-info="text/xml; charset=utf-8"

--MIMEBoundary4A7AE55984E7438034
content-type: application/xop+xml; charset=utf-8; type="application/soap+xml;"
content-transfer-encoding: binary
content-id: <0.09BC7F4BE2E4D3EF1B@apache.org>

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="...."....>
 ........
         <xop:Include href="cid:1.A91D6D2E3D7AC4D580@apache.org" 
                        xmlns:xop="http://www.w3.org/2004/08/xop/include">
         </xop:Include>
 ........

</soapenv:Envelope>
--MIMEBoundary4A7AE55984E7438034
content-type: application/octet-stream
content-transfer-encoding: binary
content-id: <1.A91D6D2E3D7AC4D580@apache.org>

Binary Data.....
--MIMEBoundary4A7AE55984E7438034--

Я пытался следовать документации и образцу кода в весенних -примерах ws, и по какой-то причине результат, который я получаю, всегда такой (, т.е. данные base64 не являются вложением.

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: text/xml;charset=utf-8
Content-Length: 4750
Date: Tue, 03 Jul 2012 17:05:21 GMT

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:downloadMessageResponse xmlns:ns2="http://ws.mypackage.com"><ns2:payLoad><ns2:messagePayLoad>....iVBORw0KGgoAAAANSUhEUgAAAFoAAAAeCyAAAAAElFTkSuQmCC....</ns2:messagePayLoad></ns2:payLoad></ns2:downloadMessageResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

Как видите, полезная нагрузка не является вложением. Вот как я настроил свое приложение:

web.xml

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        /WEB-INF/app-config.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>webservice</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/ws-config.xml</param-value>
        </init-param>
    </servlet>

ws -config.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ws="http://www.springframework.org/schema/web-services"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/web-services 
    http://www.springframework.org/schema/web-services/web-services-2.0.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.mypackage"/>

    <ws:annotation-driven/>


    <ws:dynamic-wsdl id="serviceDefinition" portTypeName="myService"
                     locationUri="http://localhost:8080/springWsTest/webservice">
        <ws:xsd location="/WEB-INF/schemas/downloadMessageRequest.xsd"/>
    </ws:dynamic-wsdl>

    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="contextPath" value="com.mypackage.ws"/>
        <property name="mtomEnabled" value="true"/>
    </bean> 
</beans>

файл схемы downloadMessageRequest.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:m="http://ws.mypackage.com" 
xmlns:xmime="http://www.w3.org/2005/05/xmlmime" elementFormDefault="qualified"
targetNamespace="http://ws.mypackage.com" 
attributeFormDefault="unqualified"> 

    <xs:element name="downloadMessageRequest">
        <xs:complexType/>
    </xs:element>

    <xs:element name="downloadMessageResponse" type="m:downloadResponseType" />

    <xs:complexType name="downloadResponseType">
            <xs:sequence>
                <xs:element name="requestName" type="xs:string"/>
                <xs:element name="payLoad">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="messagePayLoad" type="xs:base64Binary" xmime:expectedContentTypes="application/octet-stream"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
     </xs:complexType>


     <xs:element name="localDTMRequest">
        <xs:complexType/>
    </xs:element>

    <xs:element name="localDTMResponse">
        <xs:complexType>        
            <xs:sequence>
                <xs:element name="localDTM" type="xs:dateTime"/>
            </xs:sequence>          
        </xs:complexType>
    </xs:element>


</xs:schema>

Файл конвертируется в base64binary. Классы JAXB генерируются правильно. Конечная точка работает, но не включает файл в качестве вложения. Он включает его как часть тега XML, хотя я установил mtomEnabled=true.

Что мне не хватает?

8
задан Cœur 29 April 2017 в 13:24
поделиться