SOAP messages with attachments - Passing attachments to WSIF

 

Example

The following code fragment can invoke the service described by the example WSDL in the topic writing the WSDL extensions:

import javax.activation.DataHandler;
. . .
DataHandler dh = new DataHandler(new FileDataSource("myimage.jpg"));
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service = factory.getService("my.wsdl",null,null,"http://mynamespace","abc");
WSIFOperation op = service.getPort().createOperation("MyOperation");
WSIFMessage in = op.createInputMessage();
in.setObjectPart("attch",dh);
op.executeInputOnlyOperation(in);

The associated type mapping in the DeploymentDescriptor.xml file depends upon your SOAP server. For example if you use Tomcat with SOAP 2.3, then the DeploymentDescriptor.xml file contains the following type mapping:

<isd:mappings>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:x="http://mynamespace"
 qname="x:datahandler"
 javaType="javax.activation.DataHandler"
 java2XMLClassName="org.apache.soap.encoding.soapenc.MimePartSerializer"
 xml2JavaClassName="org.apache.soap.encoding.soapenc.MimePartSerializer" />
</isd:mappings> 

In this case, the backend service is invoked with the following signature:

public void MyOperation(DataHandler dh);

You can also use stubs to pass attachments into the Web Services Invocation Framework (WSIF):

DataHandler dh = new DataHandler(new FileDataSource("myimage.jpg"));
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service = factory.getService("my.wsdl",null,null,"http://mynamespace","abc");
MyInterface stub = (MyInterface)service.getStub(MyInterface.class);
stub.MyOperation(dh);

Attachments can also be returned from an operation, but at present only one attachment can be returned as the return parameter.


 

Related Tasks


SOAP messages with attachments - Writing the WSDL extensions
SOAP messages with attachments - Working with types and type mappings