ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatz_5.4.0.1/51/webserv/wswsifattpass.htm

55 lines
2.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Pass attachments to WSIF</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h5><A NAME="wswsifattpass"></A>Pass attachments to WSIF</h5>
<p>The following code fragment can call the service
described by the example WSDL given in <a href="wswsifattwsdl.htm">SOAP messages with attachments - writing the WSDL extensions</a>:</p>
<pre>import javax.activation.DataHandler;
. . .
DataHandler dh = new DataHandler(new FileDataSource(&quot;myimage.jpg&quot;));
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service = factory.getService(&quot;my.wsdl&quot;,null,null,&quot;http://mynamespace&quot;,&quot;abc&quot;);
WSIFOperation op = service.getPort().createOperation(&quot;MyOperation&quot;);
WSIFMessage in = op.createInputMessage();
in.setObjectPart(&quot;attch&quot;,dh);
op.executeInputOnlyOperation(in);
</pre>
<p>The associated type mapping in the <tt>DeploymentDescriptor.xml</tt> file
depends upon your SOAP server. For example if you use Tomcat with SOAP 2.3,
then <tt>DeploymentDescriptor.xml</tt> contains the following type mapping:</p>
<pre>&lt;isd:mappings&gt;
&lt;isd:map encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;
xmlns:x=&quot;http://mynamespace&quot;
qname=&quot;x:datahandler&quot;
javaType=&quot;javax.activation.DataHandler&quot;
java2XMLClassName=&quot;org.apache.soap.encoding.soapenc.MimePartSerializer&quot;
xml2JavaClassName=&quot;org.apache.soap.encoding.soapenc.MimePartSerializer&quot; /&gt;
&lt;/isd:mappings&gt;
</pre>
<p>In this case, the backend service is called with the following signature:</p>
<pre>public void MyOperation(DataHandler dh);</pre>
<p>Attachments can also be passed in to WSIF using stubs:</p>
<pre>DataHandler dh = new DataHandler(new FileDataSource(&quot;myimage.jpg&quot;));
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service = factory.getService(&quot;my.wsdl&quot;,null,null,&quot;http://mynamespace&quot;,&quot;abc&quot;);
MyInterface stub = (MyInterface)service.getStub(MyInterface.class);
stub.MyOperation(dh);
</pre>
<p>Attachments can also be returned from an operation, but only one attachment can be returned as the return parameter.</p>
</body></html>