Results 1 to 2 of 2
Thread: Spring-WS with MTOM Hello World
- 07-03-2012, 07:52 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
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="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); }
I would like the response to include the file as an attachement similar to the following response:
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: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--
As you can see, the payload is not an attachment. Here is how i have configured my application: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="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
ws-config.xmlJava Code:<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>
downloadMessageRequest.xsd schema fileJava Code:<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>
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.Java Code:<?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>
What am i missing?
- 07-03-2012, 08:58 PM #2
Similar Threads
-
Java world generator-real world with people and stuff
By conker5295 in forum Jobs OfferedReplies: 2Last Post: 02-23-2012, 01:22 PM -
web service mtom
By fiqueudrue in forum NetBeansReplies: 0Last Post: 02-10-2009, 09:16 AM -
from c# to java web service with pictures (MTOM)
By fiqueudrue in forum New To JavaReplies: 0Last Post: 02-10-2009, 06:50 AM -
How to send MTOM attachments through SOAPMessage by using SAAJ 1.3
By Anji in forum Advanced JavaReplies: 0Last Post: 01-19-2009, 03:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks