55 lines
2.5 KiB
HTML
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("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);
|
|
</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><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>
|
|
</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("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);
|
|
</pre>
|
|
<p>Attachments can also be returned from an operation, but only one attachment can be returned as the return parameter.</p>
|
|
|
|
</body></html>
|