You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Barlotta, Michael [USA]" <ba...@bah.com> on 2007/11/02 19:02:06 UTC

Axis1/1.4 Client to MTOM WebService

Looking for some guidance on Axis1 version 1.4 help building a WS Client
that can interact with a MTOM WebService.
 
I am building the client using the Service and Call objects
The input to the service is a String and a Base64 encoded element -
looks like this
 
<arg0>
    <name>TEST</name>
    <binaryData>base64 stuff here</binaryData>
</arg0>
 
 
I have successfully called the service with null binaryData but I get
the following error when I pass actual data.
The output is the String sent back in a SOAP Fault
 
<soap:Text xml:lang ="en">Unmarshalling Error : null </soap:Text>
 
 
In this example I have a class HelloWorldMtom (JavaBean) with a String
and a DataHandler attributes that I use as input. 

	HelloWorldMtom hwMtom = new HelloWorldMtom();
	hwMtom.setName(name);
	hwMtom.setBinaryData(dh);

 
Here is the client code:

	Service service = new Service();
	Call call = (Call) service.createCall();
	call.setTargetEndpointAddress(ADDRESS);
	call.setOperationName(new QName(HELLO_NAMESPACE, "sayHello"));
	call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);
	call.setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT,
Call.ATTACHMENT_ENCAPSULATION_FORMAT_MTOM);
	call.setProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);
	call.setReturnType(org.apache.axis.Constants.XSD_STRING);
	call.setOperationStyle(Style.WRAPPED);
	call.setOperationUse(Use.LITERAL);
	QName qnameHelloMtom = new QName(HELLO_NAMESPACE, "helloMtom");
	call.registerTypeMapping(hwMtom.getClass(), qnameHelloMtom, new
HelloWorldMtomSerializerFactory(), new
BeanDeserializerFactory(hwMtom.getClass(), qnameHelloMtom));
	call.addParameter("arg0", qnameHelloMtom, ParameterMode.IN);
	String ret = (String) call.invoke( new Object[] { hwMtom } );

I built a custom Serializer as follows:
 
public class HelloWorldMtomSerializer implements Serializer {

	public void serialize(QName name, Attributes attributes, Object
value, SerializationContext context) throws IOException {

		if (value!=null){

			HelloWorldMtom data = (HelloWorldMtom)value; 
			context.startElement(new QName("arg0"), null);
			context.serialize(new QName("name"), null,
data.getName(), null, Boolean.TRUE, Boolean.FALSE);
			if (data.getBinaryData()!=null){
			Serializer jafs = new
JAFDataHandlerSerializer();
			jafs.serialize(new QName("binaryData"), null,
data.getBinaryData(), context);

		}
		else {

			context.serialize(new QName("binaryData"), null,
null, null, Boolean.TRUE, Boolean.FALSE);

		}
		context.endElement();
		}
		}

	public String getMechanismType() { return Constants.AXIS_SAX; }
	public Element writeSchema(Class javaType, Types types) throws
Exception {

		return null;

	}

}
Am I on the right track? 
Thanks for any help with this.
 
Note: 
A CXF and an Axis2 WS client have already been successfully built
against this WS (I am testing interop with different Java SOAP stacks)
 
Mike Barlotta
Associate
Booz | Allen | Hamilton
 

Re: Axis1/1.4 Client to MTOM WebService

Posted by Thilina Gunarathne <cs...@gmail.com>.
> I am assuming at this point that the error is in my client-side
> implementation of an Axis1 MTOM client.
> Is there any client-side coding practices I am not following?
> Are there issues for MTOM support in Axis1?
AFAIK MTOM is not officially supported in Axis 1.. Whatever there is a
an experimental effort...

If you need full blown MTOM support, you would need to switch to Axis2..

thanks,
Thilina

>
> Thanks,
>
> Mike Barlotta
> Associate
> Booz | Allen | Hamilton
>
> -----Original Message-----
> From: Anne Thomas Manes [mailto:atmanes@gmail.com]
> Sent: Friday, November 02, 2007 7:40 PM
> To: axis-user@ws.apache.org
> Subject: Re: Axis1/1.4 Client to MTOM WebService
>
> You could try interfacing using SwA rather than MTOM. You would have to
> convert the WSDL to one that defines the attachment explicitly.
>
> Anne
>
> On 11/2/07, Barlotta, Michael [USA] <ba...@bah.com> wrote:
> > Thanks Thilina,
> >
> > I thought I read MTOM support was added in Axis1...
> >
> > If I understand correctly I need to base64 encode the bytes that are
> > read from a file and pass that to the JAFDataHandlerSerializer. Right?
> >
> > What are my other options in Axis1 to get this to work given the WS
> > input required?
> >
> > Thanks again,
> >
> > Mike Barlotta
> > Associate
> > Booz | Allen | Hamilton
> >
> > -----Original Message-----
> > From: Thilina Gunarathne [mailto:csethil@gmail.com]
> > Sent: Friday, November 02, 2007 4:12 PM
> > To: axis-user@ws.apache.org
> > Subject: Re: Axis1/1.4 Client to MTOM WebService
> >
> > Hi,
> > I"m not sure about the level of support for MTOM in Axis 1.4.. IIRC
> > DIms added some basic support some time back..
> >
> > Looking at your code, you seems to be trying to send the binary data
> > inline only.. You need to make sure to base64 encode the binary data
> > when putting them inline...
> >
> > But this approach will only work for smaller binary data only...
> >
> > > Serializer jafs = new JAFDataHandlerSerializer(); jafs.serialize(new
>
> > > QName("binaryData"), null, data.getBinaryData(), context);
> > Make sure to base64 encode the above data...
> >
> > ~Thilina
> >
> > <REMOVED EMAIL TRAIL>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Thilina Gunarathne  - http://thilinag.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: Axis1/1.4 Client to MTOM WebService

Posted by "Barlotta, Michael [USA]" <ba...@bah.com>.
Anne:

That would require changing the service (not out of the question but not
desired).

I am assuming at this point that the error is in my client-side
implementation of an Axis1 MTOM client.
Is there any client-side coding practices I am not following?
Are there issues for MTOM support in Axis1?

Thanks,

Mike Barlotta
Associate
Booz | Allen | Hamilton

-----Original Message-----
From: Anne Thomas Manes [mailto:atmanes@gmail.com] 
Sent: Friday, November 02, 2007 7:40 PM
To: axis-user@ws.apache.org
Subject: Re: Axis1/1.4 Client to MTOM WebService

You could try interfacing using SwA rather than MTOM. You would have to
convert the WSDL to one that defines the attachment explicitly.

Anne

On 11/2/07, Barlotta, Michael [USA] <ba...@bah.com> wrote:
> Thanks Thilina,
>
> I thought I read MTOM support was added in Axis1...
>
> If I understand correctly I need to base64 encode the bytes that are 
> read from a file and pass that to the JAFDataHandlerSerializer. Right?
>
> What are my other options in Axis1 to get this to work given the WS 
> input required?
>
> Thanks again,
>
> Mike Barlotta
> Associate
> Booz | Allen | Hamilton
>
> -----Original Message-----
> From: Thilina Gunarathne [mailto:csethil@gmail.com]
> Sent: Friday, November 02, 2007 4:12 PM
> To: axis-user@ws.apache.org
> Subject: Re: Axis1/1.4 Client to MTOM WebService
>
> Hi,
> I"m not sure about the level of support for MTOM in Axis 1.4.. IIRC 
> DIms added some basic support some time back..
>
> Looking at your code, you seems to be trying to send the binary data 
> inline only.. You need to make sure to base64 encode the binary data 
> when putting them inline...
>
> But this approach will only work for smaller binary data only...
>
> > Serializer jafs = new JAFDataHandlerSerializer(); jafs.serialize(new

> > QName("binaryData"), null, data.getBinaryData(), context);
> Make sure to base64 encode the above data...
>
> ~Thilina
>
> <REMOVED EMAIL TRAIL>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Axis1/1.4 Client to MTOM WebService

Posted by Anne Thomas Manes <at...@gmail.com>.
You could try interfacing using SwA rather than MTOM. You would have
to convert the WSDL to one that defines the attachment explicitly.

Anne

On 11/2/07, Barlotta, Michael [USA] <ba...@bah.com> wrote:
> Thanks Thilina,
>
> I thought I read MTOM support was added in Axis1...
>
> If I understand correctly I need to base64 encode the bytes that are
> read from a file and pass that to the JAFDataHandlerSerializer. Right?
>
> What are my other options in Axis1 to get this to work given the WS
> input required?
>
> Thanks again,
>
> Mike Barlotta
> Associate
> Booz | Allen | Hamilton
>
> -----Original Message-----
> From: Thilina Gunarathne [mailto:csethil@gmail.com]
> Sent: Friday, November 02, 2007 4:12 PM
> To: axis-user@ws.apache.org
> Subject: Re: Axis1/1.4 Client to MTOM WebService
>
> Hi,
> I"m not sure about the level of support for MTOM in Axis 1.4.. IIRC DIms
> added some basic support some time back..
>
> Looking at your code, you seems to be trying to send the binary data
> inline only.. You need to make sure to base64 encode the binary data
> when putting them inline...
>
> But this approach will only work for smaller binary data only...
>
> > Serializer jafs = new JAFDataHandlerSerializer(); jafs.serialize(new
> > QName("binaryData"), null, data.getBinaryData(), context);
> Make sure to base64 encode the above data...
>
> ~Thilina
>
> <REMOVED EMAIL TRAIL>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: Axis1/1.4 Client to MTOM WebService

Posted by "Barlotta, Michael [USA]" <ba...@bah.com>.
I added this code to my Serializer and got the call to work...
Thanks Thilina.

                        DataHandler dh = data.getBinaryData();
                        InputStream is = dh.getInputStream();
                        ByteArrayOutputStream baos =
IOHelper.getInputStreamAsBytes(is);
                        String b64 = Base64.encode(baos.toByteArray());
                        context.serialize(new QName("binaryData"), null,
b64, null, Boolean.TRUE, Boolean.FALSE);

Mike Barlotta
Associate
Booz | Allen | Hamilton

-----Original Message-----
From: Barlotta, Michael [USA] [mailto:barlotta_michael@bah.com
<ma...@bah.com> ]
Sent: Friday, November 02, 2007 4:25 PM
To: axis-user@ws.apache.org
Subject: RE: Axis1/1.4 Client to MTOM WebService

Thanks Thilina,

I thought I read MTOM support was added in Axis1...

If I understand correctly I need to base64 encode the bytes that are
read from a file and pass that to the JAFDataHandlerSerializer. Right?

What are my other options in Axis1 to get this to work given the WS
input required?

Thanks again,

Mike Barlotta
Associate
Booz | Allen | Hamilton

-----Original Message-----
From: Thilina Gunarathne [mailto:csethil@gmail.com
<ma...@gmail.com> ]
Sent: Friday, November 02, 2007 4:12 PM
To: axis-user@ws.apache.org
Subject: Re: Axis1/1.4 Client to MTOM WebService

Hi,
I"m not sure about the level of support for MTOM in Axis 1.4.. IIRC DIms
added some basic support some time back..

Looking at your code, you seems to be trying to send the binary data
inline only.. You need to make sure to base64 encode the binary data
when putting them inline...

But this approach will only work for smaller binary data only...

> Serializer jafs = new JAFDataHandlerSerializer(); jafs.serialize(new
> QName("binaryData"), null, data.getBinaryData(), context);
Make sure to base64 encode the above data...

~Thilina

<REMOVED EMAIL TRAIL>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: Axis1/1.4 Client to MTOM WebService

Posted by "Barlotta, Michael [USA]" <ba...@bah.com>.
Thanks Thilina,

I thought I read MTOM support was added in Axis1...

If I understand correctly I need to base64 encode the bytes that are
read from a file and pass that to the JAFDataHandlerSerializer. Right?

What are my other options in Axis1 to get this to work given the WS
input required?

Thanks again,

Mike Barlotta
Associate
Booz | Allen | Hamilton

-----Original Message-----
From: Thilina Gunarathne [mailto:csethil@gmail.com] 
Sent: Friday, November 02, 2007 4:12 PM
To: axis-user@ws.apache.org
Subject: Re: Axis1/1.4 Client to MTOM WebService

Hi,
I"m not sure about the level of support for MTOM in Axis 1.4.. IIRC DIms
added some basic support some time back..

Looking at your code, you seems to be trying to send the binary data
inline only.. You need to make sure to base64 encode the binary data
when putting them inline...

But this approach will only work for smaller binary data only...

> Serializer jafs = new JAFDataHandlerSerializer(); jafs.serialize(new 
> QName("binaryData"), null, data.getBinaryData(), context);
Make sure to base64 encode the above data...

~Thilina

<REMOVED EMAIL TRAIL>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Axis1/1.4 Client to MTOM WebService

Posted by Thilina Gunarathne <cs...@gmail.com>.
Hi,
I"m not sure about the level of support for MTOM in Axis 1.4.. IIRC
DIms added some basic support some time back..

Looking at your code, you seems to be trying to send the binary data
inline only.. You need to make sure to base64 encode the binary data
when putting them inline...

But this approach will only work for smaller binary data only...

> Serializer jafs = new JAFDataHandlerSerializer();
> jafs.serialize(new QName("binaryData"), null, data.getBinaryData(),
> context);
Make sure to base64 encode the above data...

~Thilina

On 11/2/07, Barlotta, Michael [USA] <ba...@bah.com> wrote:
>
>
> Looking for some guidance on Axis1 version 1.4 help building a WS Client
> that can interact with a MTOM WebService.
>
> I am building the client using the Service and Call objects
> The input to the service is a String and a Base64 encoded element - looks
> like this
>
> <arg0>
>     <name>TEST</name>
>     <binaryData>base64 stuff here</binaryData>
> </arg0>
>
>
> I have successfully called the service with null binaryData but I get the
> following error when I pass actual data.
>
> The output is the String sent back in a SOAP Fault
>
> <soap:Text xml:lang ="en">Unmarshalling Error : null </soap:Text>
>
>
> In this example I have a class HelloWorldMtom (JavaBean) with a String and a
> DataHandler attributes that I use as input.
> HelloWorldMtom hwMtom = new HelloWorldMtom();
> hwMtom.setName(name);
> hwMtom.setBinaryData(dh);
>
>
> Here is the client code:
> Service service = new Service();
> Call call = (Call) service.createCall();
> call.setTargetEndpointAddress(ADDRESS);
> call.setOperationName(new QName(HELLO_NAMESPACE, "sayHello"));
> call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);
> call.setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT,
> Call.ATTACHMENT_ENCAPSULATION_FORMAT_MTOM);
> call.setProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);
> call.setReturnType(org.apache.axis.Constants.XSD_STRING);
> call.setOperationStyle(Style.WRAPPED);
> call.setOperationUse(Use.LITERAL);
> QName qnameHelloMtom = new QName(HELLO_NAMESPACE, "helloMtom");
> call.registerTypeMapping(hwMtom.getClass(), qnameHelloMtom, new
> HelloWorldMtomSerializerFactory(), new
> BeanDeserializerFactory(hwMtom.getClass(), qnameHelloMtom));
> call.addParameter("arg0", qnameHelloMtom, ParameterMode.IN);
> String ret = (String) call.invoke( new Object[] { hwMtom } );
>
> I built a custom Serializer as follows:
>  public class HelloWorldMtomSerializer implements Serializer {
>
> public void serialize(QName name, Attributes attributes, Object value,
> SerializationContext context) throws IOException {
>
> if (value!=null){
>
> HelloWorldMtom data = (HelloWorldMtom)value;
> context.startElement(new QName("arg0"), null);
> context.serialize(new QName("name"), null, data.getName(), null,
> Boolean.TRUE, Boolean.FALSE);
> if (data.getBinaryData()!=null){
> Serializer jafs = new JAFDataHandlerSerializer();
> jafs.serialize(new QName("binaryData"), null, data.getBinaryData(),
> context);
> }
> else {
>
> context.serialize(new QName("binaryData"), null, null, null, Boolean.TRUE,
> Boolean.FALSE);
> }
> context.endElement();
> }
> }
> public String getMechanismType() { return Constants.AXIS_SAX; }
> public Element writeSchema(Class javaType, Types types) throws Exception {
>
> return null;
> }
> }
>
> Am I on the right track?
>
> Thanks for any help with this.
>
> Note:
> A CXF and an Axis2 WS client have already been successfully built against
> this WS (I am testing interop with different Java SOAP stacks)
>
> Mike Barlotta
> Associate
> Booz | Allen | Hamilton
>


-- 
Thilina Gunarathne  - http://thilinag.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org