Results 1 to 2 of 2
  1. #1
    ziggy is offline Member
    Join Date
    Nov 2008
    Rep Power

    Default Spring-WS with MTOM Hello World

    I am trying to create a simple Spring webservice which when called returns a file attachement as part of the SOAP response. The Enpoint class is shown below:

    And finally the endpoint

    Java Code:
        @PayloadRoot(namespace="", localPart="downloadMessageRequest")
        	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"));
        		return objectFactory.createDownloadMessageResponse(response);

    I would like the response to include the file as an attachement similar to the following response:

    Java Code:
        Content-Type: multipart/related; boundary=MIMEBoundary4A7AE55984E7438034;
                                 type="application/xop+xml"; start="<>";
                                 start-info="text/xml; charset=utf-8"
        content-type: application/xop+xml; charset=utf-8; type="application/soap+xml;"
        content-transfer-encoding: binary
        content-id: <>
        <?xml version='1.0' encoding='utf-8'?>
        <soapenv:Envelope xmlns:soapenv="...."....>
                 <xop:Include href="" 
        content-type: application/octet-stream
        content-transfer-encoding: binary
        content-id: <>
        Binary Data.....
    I have tried to follow the documentation and the sample code in the spring-ws samples and for some reason the output i am getting is always this (i.e. the base64 data is not an attachement.

    Java Code:
        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=""><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:downloadMessageResponse xmlns:ns2=""><ns2:payLoad><ns2:messagePayLoad>....iVBORw0KGgoAAAANSUhEUgAAAFoAAAAeCyAAAAAElFTkSuQmCC....</ns2:messagePayLoad></ns2:payLoad></ns2:downloadMessageResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
    As you can see, the payload is not an attachment. Here is how i have configured my application:

    Java Code:

    Java Code:
        <beans xmlns=""

        	<context:component-scan base-package="com.mypackage"/>
        	<ws:dynamic-wsdl id="serviceDefinition" portTypeName="myService"
        		<ws:xsd location="/WEB-INF/schemas/downloadMessageRequest.xsd"/>
        	<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
                <property name="contextPath" value=""/>
                <property name="mtomEnabled" value="true"/>
    downloadMessageRequest.xsd schema file

    Java Code:
       <?xml version="1.0" encoding="UTF-8"?>
        <xs:schema xmlns:xs="" 
        xmlns:xmime="" elementFormDefault="qualified"
        	<xs:element name="downloadMessageRequest">
        	<xs:element name="downloadMessageResponse" type="m:downloadResponseType" />
        	<xs:complexType name="downloadResponseType">
        				<xs:element name="requestName" type="xs:string"/>
        				<xs:element name="payLoad">
        							<xs:element name="messagePayLoad" type="xs:base64Binary" xmime:expectedContentTypes="application/octet-stream"/>
        	 <xs:element name="localDTMRequest">
        	<xs:element name="localDTMResponse">
        				<xs:element name="localDTM" type="xs:dateTime"/>
    The file does get converted to base64binary. The JAXB clases are generated correctly. The Endpoint works but it is not including the file as an attachement. It is including it as part of the XML tag even though i have set mtomEnabled=true.

    What am i missing?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Spring-WS with MTOM Hello World

    Moved from Advanced Java

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Java world generator-real world with people and stuff
    By conker5295 in forum Jobs Offered
    Replies: 2
    Last Post: 02-23-2012, 02:22 PM
  2. web service mtom
    By fiqueudrue in forum NetBeans
    Replies: 0
    Last Post: 02-10-2009, 10:16 AM
  3. from c# to java web service with pictures (MTOM)
    By fiqueudrue in forum New To Java
    Replies: 0
    Last Post: 02-10-2009, 07:50 AM
  4. Replies: 0
    Last Post: 01-19-2009, 04:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts