[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

MTOM not working in Axis2

I am trying to transfer content using MTOM (in Axis2). For this I have added the following entry to services.xml
<parameter name="enableMTOM">true</parameter>

In the client, I am doing the following

public static void getResumeContent(String resumeId) throws AxisFault {
            System.out.println("Resume ID is getResumeContent --"+resumeId);            
            try {
                  ResumeServiceStub rs = new ResumeServiceStub();
                  rs = new ResumeServiceStub("http://localhost:1234/axis2/services/ResumeService");
                  GetResumeContent grc = new GetResumeContent();
                  grc.setResumeId(resumeId);
                  GetResumeContentResponse grcr = rs.getResumeContent(grc);
                  DataHandler handler = grcr.getContent();
                  InputStream is = handler.getInputStream();
                  writeToFile("abc.pdf", is);
            }catch(IOException io) {
                  io.printStackTrace();
            }
           
      }

In the service, I am doing the following
public GetResumeContentResponse getResumeContent(GetResumeContent getResumeContent) {
       String resumeId = getResumeContent.getResumeId();
       System.out.println("Resume ID is --"+resumeId);
       GetResumeContentResponse grs = new GetResumeContentResponse();
       javax.activation.DataHandler dataHandler = new DataHandler(new FileDataSource("C:\\source\\LTA.pdf"));
       grs.setContent(dataHandler);
       return grs;
      }

The content transfers fine, but when I access the SOAP response, it shows the following
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 01 Apr 2010 03:34:15 GMT

2000
<?xml version='1.0' encoding='UTF-8'?>
   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <soapenv:Body>
         <ns1:getResumeContentResponse xmlns:ns1="http://www.examples.com/wsdl/ResumeService.wsdl">
            <content>JVBERi0xLjIKJWRoaTloa2xmcnAyNQpuDwUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQ
2000
AUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUhIAyTilproHGDQAoORkUtIoCgAdBS0AFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAIKWiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAMjY2MDk0IDAwMDAwIG4gCjAwMDAwMDAxMjQgMDAwMDAgbiAKMDAwMDAwMDI4MiAwMDAwMCBuIAowMDAwMDAwMzY1IDAwMDAwIG4gCjAwMDAwMDA0NTcgMDAwMDAgbiAKMDAwMDI2NjA3MiAwMDAwMCBuIAowMDAwMDAwMzgzIDAwMDAwIG4gCjAwMDAwMDA0MzkgMDAwMDAgbiAKdHJhaWxlcgo8PAovU2l6ZSAxMQovUm9vdCAyIDAgUgovSW5mbyAxIDAgUgo+PgpzdGFydHhyZWYKMjY2MTUyCiUlRU9GCg==</content>
         </ns1:getResumeContentResponse>22
      </soapenv:Body>
   </soapenv:Envelope>0

It seems that MTOM setting is not having any effect.
Pleae let me know if I am missing something in order to enable MTOM.

Thank you
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://www.examples.com/wsdl/ResumeService.wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ResumeService"
	targetNamespace="http://www.examples.com/wsdl/ResumeService.wsdl">
	<wsdl:types>
		<xsd:schema targetNamespace="http://www.examples.com/wsdl/ResumeService.wsdl">
			<xsd:element name="getResumeId">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="firstName" type="xsd:string" />
						<xsd:element name="lastName" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeIdResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="resumeId" type="xsd:string" />
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeDetails">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="resumeId" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeDetailsResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="firstName" type="xsd:string"></xsd:element>
						<xsd:element name="lastName" type="xsd:string"></xsd:element>
						<xsd:element name="address" type="tns:addressType"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>

			<xsd:complexType name="addressType">
				<xsd:sequence>
					<xsd:element name="city" type="xsd:string" />
					<xsd:element name="state" type="xsd:string" />
					<xsd:element name="country" type="xsd:string" />
					<xsd:element name="mobile" type="xsd:string" />
					<xsd:element name="email" type="xsd:string" />
				</xsd:sequence>
			</xsd:complexType>

			<xsd:element name="getAllResumeIdsResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="allResumeIds" type="xsd:string"
							maxOccurs="unbounded" />
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>

			<xsd:element name="updateResumeDetails">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="resumeId" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="updateResumeDetailsResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="updateStatus" type="xsd:boolean"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>

			<xsd:element name="getResumeContent">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="resumeId" type="xsd:string">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeContentResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="content" type="xsd:base64Binary">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>

			<xsd:element name="updateResumeContent">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="resumeId" type="xsd:string">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="updateResumeContentResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="content" type="xsd:base64Binary">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeDetails_fault">
				<xsd:complexType>
					<xsd:sequence>

						<xsd:element name="getResumeDetails_fault" type="xsd:string">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeDetailsFault" type="xsd:string"></xsd:element>
			<xsd:element name="InvalidResumeIdFault" type="xsd:string"></xsd:element>
			<xsd:element name="getResumeDetails_fault1">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="getResumeDetails_fault1" type="xsd:string">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="UnAuthorisedResumeIdFault" type="xsd:string"></xsd:element>
			<xsd:element name="getResumeDetails_fault2">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="getResumeDetails_fault2"
							type="xsd:string">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeDetails_fault3">
				<xsd:complexType>
					<xsd:sequence>

						<xsd:element name="getResumeDetails_fault"
							type="xsd:string">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeDetails_fault11">
				<xsd:complexType>
					<xsd:sequence>

						<xsd:element name="getResumeDetails_fault1"
							type="xsd:string">
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:schema>
	</wsdl:types>
	<wsdl:message name="getResumeIdRequest">
		<wsdl:part element="tns:getResumeId" name="parameters" />
	</wsdl:message>
	<wsdl:message name="getResumeIdResponse">
		<wsdl:part element="tns:getResumeIdResponse" name="parameters" />
	</wsdl:message>
	<wsdl:message name="getResumeDetailsRequest">
		<wsdl:part name="parameters" element="tns:getResumeDetails"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="getResumeDetailsResponse">
		<wsdl:part name="parameters" element="tns:getResumeDetailsResponse"></wsdl:part>
	</wsdl:message>

	<wsdl:message name="getAllResumeIdsRequest" />
	<wsdl:message name="getAllResumeIdsResponse">
		<wsdl:part name="parameters" element="tns:getAllResumeIdsResponse"></wsdl:part>
	</wsdl:message>

	<wsdl:message name="updateResumeDetailsRequest">
		<wsdl:part name="parameters" element="tns:updateResumeDetails"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="updateResumeDetailsResponse">
		<wsdl:part name="parameters" element="tns:updateResumeDetailsResponse"></wsdl:part>
	</wsdl:message>

	<wsdl:message name="getResumeContentRequest">
		<wsdl:part name="parameters" element="tns:getResumeContent"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="getResumeContentResponse">
		<wsdl:part name="parameters" element="tns:getResumeContentResponse"></wsdl:part>
	</wsdl:message>

	<wsdl:message name="updateResumeContentRequest">
		<wsdl:part name="parameters" element="tns:updateResumeContent"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="updateResumeContentResponse">
		<wsdl:part name="parameters" element="tns:updateResumeContentResponse"></wsdl:part>
	</wsdl:message>


	<wsdl:message name="getResumeDetails_fault2Msg">
		<wsdl:part name="parameters" element="tns:getResumeDetails_fault2"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="getResumeDetails_faultMsg">
		<wsdl:part name="parameters" element="tns:InvalidResumeIdFault"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="getResumeDetails_fault1Msg">
		<wsdl:part name="parameters" element="tns:UnAuthorisedResumeIdFault"></wsdl:part>
	</wsdl:message>
	<wsdl:portType name="ResumeService">
		<wsdl:operation name="getResumeId">
			<wsdl:input message="tns:getResumeIdRequest" />
			<wsdl:output message="tns:getResumeIdResponse" />
		</wsdl:operation>
		<wsdl:operation name="getResumeDetails">
			<wsdl:input message="tns:getResumeDetailsRequest"></wsdl:input>
			<wsdl:output message="tns:getResumeDetailsResponse"></wsdl:output>
            <wsdl:fault name="fault" message="tns:getResumeDetails_faultMsg"></wsdl:fault>
            <wsdl:fault name="fault1" message="tns:getResumeDetails_fault1Msg"></wsdl:fault>
        </wsdl:operation>

		<wsdl:operation name="getAllResumeIds">
			<wsdl:input message="tns:getAllResumeIdsRequest"></wsdl:input>
			<wsdl:output message="tns:getAllResumeIdsResponse"></wsdl:output>
		</wsdl:operation>

		<wsdl:operation name="updateResumeDetails">
			<wsdl:input message="tns:updateResumeDetailsRequest"></wsdl:input>
			<wsdl:output message="tns:updateResumeDetailsResponse"></wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="getResumeContent">
			<wsdl:input message="tns:getResumeContentRequest"></wsdl:input>
			<wsdl:output message="tns:getResumeContentResponse"></wsdl:output>
		</wsdl:operation>

		<wsdl:operation name="updateResumeContent">
			<wsdl:input message="tns:updateResumeContentRequest"></wsdl:input>
			<wsdl:output message="tns:updateResumeContentResponse"></wsdl:output>
		</wsdl:operation>
	</wsdl:portType>

	<wsdl:binding name="ResumeServiceSOAP" type="tns:ResumeService">

		<soap:binding style="document"
			transport="http://schemas.xmlsoap.org/soap/http" />
		<wsdl:operation name="getResumeId">

			<soap:operation
				soapAction="http://www.examples.com/wsdl/ResumeService.wsdl/getResumeId" />
			<wsdl:input>

				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>

				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="getResumeDetails">

			<soap:operation
				soapAction="http://www.examples.com/wsdl/ResumeService.wsdl/getResumeDetails" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
			<wsdl:fault name="fault">
				<soap:fault use="literal" name="fault" />
			</wsdl:fault>
			<wsdl:fault name="fault1">
				<soap:fault use="literal" name="fault1" />
			</wsdl:fault>
		</wsdl:operation>

		<wsdl:operation name="getAllResumeIds">

			<soap:operation
				soapAction="http://www.examples.com/wsdl/ResumeService.wsdl/getAllResumeIds" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>

				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="updateResumeDetails">

			<soap:operation
				soapAction="http://www.examples.com/wsdl/ResumeService.wsdl/updateResumeDetails" />
			<wsdl:input>

				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>

				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="getResumeContent">
			<soap:operation
				soapAction="http://www.examples.com/wsdl/ResumeService.wsdl/getResumeContent" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="updateResumeContent">
			<soap:operation
				soapAction="http://www.examples.com/wsdl/ResumeService.wsdl/updateResumeContent" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>

	<wsdl:service name="ResumeService">
		<wsdl:port binding="tns:ResumeServiceSOAP" name="ResumeServiceSOAP">
			<soap:address location="http://www.example.org/" />
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>

Open in new window

0
ank9
Asked:
ank9
  • 5
  • 5
1 Solution
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Oh Damn thats terrible, this not the way it is suppose to work! well let me try an example myself and get back.
0
 
ank9Author Commented:
Thank you.
Did you get an opportunity to look into this?
 
0
 
ank9Author Commented:
Tried with soapUI but with the same result.
Also, set the property

<parameter name="enableMTOM">true</parameter>

in axis2.xml in the Service.
Earlier it was there in services.xml only.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
I also tried various things but Code first MTOM is working like a charm where as WSDL first (WSDL2Java) is not enabling the base64 encoded data element, the one more addiotnal change we need to do is try adding a xmime type for that element as "application/pdf" or "appication/octect" stream.

But neither did that force WSDL2Java to generate MTOM classes.
0
 
ank9Author Commented:
Is there anything that I can try now?
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
just change the content element to this:

 <xsd:element name="content" ns1:expectedContentTypes="application/octet-stream" type="xsd:base64Binary" minOccurs="0" xmlns:ns1="http://www.w3.org/2005/05/xmlmime"/>

This must force AXIS 2 generate MTOM classes, also make sure  the enableMTOM is the xml file is set true which I believe you have done already.
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Did you try the above sugguestion, read this

"Binary data less than 5 KB will remain in line in the SOAP message and stay base64 encoded. The default threshold value of the JAX-WS 2.0 reference implementation is 1 KB. "

http://www.devx.com/xml/Article/34797/1763/page/3
0
 
ank9Author Commented:
I am getting the following in response.

Does this mean that MTOM is working?

thank you

 <soapenv:Body>
               <ns1:getResumeContentResponse xmlns:ns1="http://www.examples.com/wsdl/ResumeService.wsdl">
                  <content>
                     <xop:Include href="cid:1.urn:uuid:6A9F15C3F68D7050F41270810645962@apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include" />
                  </content>
               </ns1:getResumeContentResponse>
            </soapenv:Body>

Open in new window

0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Perfect :)
0
 
ank9Author Commented:
Thanks you so much for your help.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now