You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by wh...@apache.org on 2002/10/29 12:13:10 UTC
cvs commit: xml-axis-wsif/java/test/proposals/mime WSIFFrame.java axis.jpg MimeTest.java DeploymentDescriptor.xml Mime.wsdl MimeImpl.java Mime.java WSIFOperation_ApacheAxis.java
whitlock 2002/10/29 03:13:10
Modified: java/test/proposals/mime MimeTest.java
DeploymentDescriptor.xml Mime.wsdl MimeImpl.java
Mime.java WSIFOperation_ApacheAxis.java
Added: java/test/proposals/mime WSIFFrame.java axis.jpg
Log:
Fixes for images
Revision Changes Path
1.6 +47 -35 xml-axis-wsif/java/test/proposals/mime/MimeTest.java
Index: MimeTest.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/MimeTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MimeTest.java 23 Oct 2002 15:23:56 -0000 1.5
+++ MimeTest.java 29 Oct 2002 11:13:10 -0000 1.6
@@ -57,6 +57,9 @@
package proposals.mime;
+import java.awt.Canvas;
+import java.awt.Frame;
+import java.awt.Graphics;
import java.awt.Image;
import java.io.BufferedInputStream;
import java.io.File;
@@ -69,6 +72,7 @@
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.internet.MimeMultipart;
+import javax.swing.ImageIcon;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import junit.framework.Test;
@@ -100,13 +104,16 @@
public class MimeTest extends TestCase {
String wsdlLocation =
TestUtilities.getWsdlPath("java\\test\\proposals\\mime") + "Mime.wsdl";
+ String imageLocation =
+ TestUtilities.getWsdlPath("java\\test\\proposals\\mime") + "axis.jpg";
+ private final static String flatfileLocation =
+ TestUtilities.getWsdlPath("java\\test\\proposals\\mime") + "test.txt";
private final static String SEND_DH = "SEND-DH";
private final static String RECEIVE_DH = "RECEIVE-DH";
private final static String SEND_PLAINTEXT = "SEND-PLAINTEXT";
private final static String RECEIVE_PLAINTEXT = "RECEIVE-PLAINTEXT";
- private final static String SEND_IMAGE = "SEND-IMAGE";
- private final static String RECEIVE_IMAGE = "RECEIVE-IMAGE";
+ private final static String BOUNCE_IMAGE = "BOUNCE-IMAGE";
private final static String SEND_SOURCE = "SEND-SOURCE";
private final static String RECEIVE_SOURCE = "RECEIVE-SOURCE";
private final static String SEND_MIMEMULTIPART = "SEND-MIMEMULTIPART";
@@ -116,11 +123,6 @@
{ "The owl and the pussy cat went to sea in a beautiful pea-green boat,",
"They took some honey and plenty of money wrapped up in a five pound note" };
- private final static String flatfilename =
- TestUtilities.getWsdlPath("java\\test\\proposals\\mime") + "test.txt";
- private final static String imagefilename =
- TestUtilities.getWsdlPath("java\\test\\proposals\\mime") + "test.img";
-
private final boolean SYNC = true;
private final boolean ASYNC = false;
@@ -158,13 +160,9 @@
// doit("SOAPPort", RECEIVE_PLAINTEXT, SYNC);
// }
//
-// public void testAxisSendImageSync() {
-// doit("SOAPPort", SEND_IMAGE, SYNC);
-// }
-//
-// public void testAxisReceiveImageSync() {
-// doit("SOAPPort", RECEIVE_IMAGE, SYNC);
-// }
+ public void testAxisBounceImageSync() {
+ doit("SOAPPort", BOUNCE_IMAGE, SYNC);
+ }
//
// public void testAxisSendSourceSync() {
// doit("SOAPPort", SEND_SOURCE, SYNC);
@@ -241,10 +239,8 @@
send_plaintext(service,stub);
else if (cmd.equals(RECEIVE_PLAINTEXT))
receive_plaintext(service,stub);
- else if (cmd.equals(SEND_IMAGE))
- send_image(service,stub);
- else if (cmd.equals(RECEIVE_IMAGE))
- receive_image(service,stub);
+ else if (cmd.equals(BOUNCE_IMAGE))
+ bounce_image(service,stub);
else if (cmd.equals(SEND_SOURCE))
send_source(service,stub);
else if (cmd.equals(RECEIVE_SOURCE))
@@ -265,14 +261,16 @@
WSIFPluggableProviders.overrideDefaultProvider(
"http://schemas.xmlsoap.org/wsdl/soap/",
null);
+
+ WSIFFrame.close();
}
}
private void send_dh(WSIFService service, Mime stub) throws Exception {
- DataHandler dh = new DataHandler(new FileDataSource(flatfilename));
+ DataHandler dh = new DataHandler(new FileDataSource(flatfileLocation));
String buff = stub.dataHandlerToString(dh);
- compareFiles(flatfilename, buff);
+ compareFiles(flatfileLocation, buff);
}
private void receive_dh(WSIFService service, Mime stub) throws Exception {
@@ -280,29 +278,42 @@
compareFiles(dh,rhyme[0]);
}
- private void send_plaintext(WSIFService service, Mime stub) throws Exception {
- service.mapType(
- new QName("http://proposals.mime/", "plaintext"),
- String.class);
+ private void send_plaintext(WSIFService service, Mime stub)
+ throws Exception {
+ service.mapType(
+ new QName("http://proposals.mime/", "plaintext"),
+ String.class);
String buff = stub.plainTextToString(rhyme[0]);
assertTrue(rhyme[0].equals(buff));
}
- private void receive_plaintext(WSIFService service, Mime stub) throws Exception {
- service.mapType(
- new QName("http://proposals.mime/", "plaintext"),
- String.class);
+ private void receive_plaintext(WSIFService service, Mime stub)
+ throws Exception {
+ service.mapType(
+ new QName("http://proposals.mime/", "plaintext"),
+ String.class);
String buff = stub.stringToPlainText(rhyme[1]);
assertTrue(rhyme[1].equals(buff));
}
- private void send_image(WSIFService service, Mime stub) throws Exception {
- service.mapType(
- new QName("http://proposals.mime/", "image"),
- Image.class);
-// Image i = new Image(imagefilename);
-// String buff = stub.imageToString(i);
-// assertTrue(rhyme[0].equals(buff));
+ private void bounce_image(WSIFService service, Mime stub) throws Exception {
+ service.mapType(
+ new QName("http://proposals.mime/", "image"),
+ Image.class);
+
+ // This blocks until the image is loaded.
+ Image im1 = new ImageIcon(imageLocation).getImage();
+ WSIFFrame.display(im1,"Original image");
+
+ // Could use Image image2 = Toolkit.getDefaultToolkit().getImage("image.gif");
+ // which loads the image in the background.
+
+ Image im2 = stub.bounceImage(im1);
+ WSIFFrame.display(im2,"Bounced image");
+
+ System.out.println("Sleeping");
+ Thread.sleep(10000);
+ System.out.println("Woken up");
}
private void receive_image(WSIFService service, Mime stub) throws Exception {
@@ -394,4 +405,5 @@
return false;
return true;
}
+
}
1.4 +1 -1 xml-axis-wsif/java/test/proposals/mime/DeploymentDescriptor.xml
Index: DeploymentDescriptor.xml
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/DeploymentDescriptor.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DeploymentDescriptor.xml 23 Oct 2002 15:23:56 -0000 1.3
+++ DeploymentDescriptor.xml 29 Oct 2002 11:13:10 -0000 1.4
@@ -2,7 +2,7 @@
id="http://proposals.mime/">
<isd:provider type="java"
scope="Application"
- methods="dataHandlerToString stringToDataHandler plainTextToString stringToPlainText">
+ methods="dataHandlerToString stringToDataHandler plainTextToString stringToPlainText bounceImage">
<isd:java class="proposals.mime.MimeImpl" static="false"/>
</isd:provider>
1.4 +35 -0 xml-axis-wsif/java/test/proposals/mime/Mime.wsdl
Index: Mime.wsdl
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/Mime.wsdl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Mime.wsdl 23 Oct 2002 15:23:56 -0000 1.3
+++ Mime.wsdl 29 Oct 2002 11:13:10 -0000 1.4
@@ -18,6 +18,14 @@
<part name="plaintext" type="tns:plaintext"/>
</message>
+ <message name="Image1Message">
+ <part name="image1" type="tns:image"/>
+ </message>
+
+ <message name="Image2Message">
+ <part name="image2" type="tns:image"/>
+ </message>
+
<message name="StringMessage">
<part name="buff" type="xsd:string"/>
</message>
@@ -40,6 +48,10 @@
<input message="tns:StringMessage"/>
<output message="tns:PlainTextMessage"/>
</operation>
+ <operation name="bounceImage">
+ <input message="tns:Image1Message"/>
+ <output message="tns:Image2Message"/>
+ </operation>
</portType>
<!-- binding declns -->
@@ -111,6 +123,29 @@
<mime:multipartRelated>
<mime:part>
<mime:content part="plaintext" type="text/plain"/>
+ <soap:body use="encoded"
+ namespace="http://proposals.mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </mime:part>
+ </mime:multipartRelated>
+ </output>
+ </operation>
+ <operation name="bounceImage">
+ <soap:operation soapAction=""/>
+ <input>
+ <mime:multipartRelated>
+ <mime:part>
+ <mime:content part="image1" type="image/jpeg"/>
+ <soap:body use="encoded"
+ namespace="http://proposals.mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </mime:part>
+ </mime:multipartRelated>
+ </input>
+ <output>
+ <mime:multipartRelated>
+ <mime:part>
+ <mime:content part="image2" type="image/jpeg"/>
<soap:body use="encoded"
namespace="http://proposals.mime/"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
1.5 +24 -1 xml-axis-wsif/java/test/proposals/mime/MimeImpl.java
Index: MimeImpl.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/MimeImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MimeImpl.java 23 Oct 2002 15:23:56 -0000 1.4
+++ MimeImpl.java 29 Oct 2002 11:13:10 -0000 1.5
@@ -57,13 +57,15 @@
package proposals.mime;
+import java.awt.Image;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.activation.DataHandler;
-import javax.activation.DataSource;
import javax.activation.FileDataSource;
+import javax.swing.ImageIcon;
/**
* Mime service used by MimeTest
@@ -117,6 +119,27 @@
} catch (IOException ioe) {
ioe.printStackTrace();
return null;
+ }
+ }
+
+ public DataHandler bounceImage(DataHandler ds) {
+ try {
+ InputStream is = ds.getInputStream();
+ byte[] bBuff = new byte[is.available()];
+ is.read(bBuff);
+
+ Image im = new ImageIcon(bBuff).getImage();
+ WSIFFrame.display(im, "Backend image");
+ Thread.sleep(10000);
+
+ FileDataSource fds = getTempFile();
+ fds.getOutputStream().write(bBuff);
+ return new DataHandler(fds);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ } finally {
+ WSIFFrame.close();
}
}
1.4 +4 -4 xml-axis-wsif/java/test/proposals/mime/Mime.java
Index: Mime.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/Mime.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Mime.java 23 Oct 2002 15:23:56 -0000 1.3
+++ Mime.java 29 Oct 2002 11:13:10 -0000 1.4
@@ -57,8 +57,9 @@
package proposals.mime;
+import java.awt.Image;
+
import javax.activation.DataHandler;
-import javax.activation.DataSource;
public interface Mime {
public String dataHandlerToString(DataHandler dh);
@@ -67,9 +68,8 @@
public String plainTextToString(String s);
public String stringToPlainText(String buff);
-// public String dataSourceToString(DataSource ds);
-// public DataSource stringToDataSource(String buff);
-//
+ public Image bounceImage(Image im);
+
// public String dataSourceToString(DataSource ds);
// public DataSource stringToDataSource(String buff);
//
1.5 +59 -30 xml-axis-wsif/java/test/proposals/mime/WSIFOperation_ApacheAxis.java
Index: WSIFOperation_ApacheAxis.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/WSIFOperation_ApacheAxis.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WSIFOperation_ApacheAxis.java 23 Oct 2002 15:23:56 -0000 1.4
+++ WSIFOperation_ApacheAxis.java 29 Oct 2002 11:13:10 -0000 1.5
@@ -58,6 +58,8 @@
package proposals.mime;
import java.awt.Image;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -67,9 +69,9 @@
import java.util.Vector;
import javax.activation.DataHandler;
-import javax.activation.DataSource;
import javax.jms.TextMessage;
import javax.mail.internet.MimeMultipart;
+import javax.swing.ImageIcon;
import javax.wsdl.Definition;
import javax.wsdl.Input;
import javax.wsdl.Operation;
@@ -83,10 +85,6 @@
import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
-import org.apache.axis.attachments.ImageDataSource;
-import org.apache.axis.attachments.MimeMultipartDataSource;
-import org.apache.axis.attachments.PlainTextDataSource;
-import org.apache.axis.attachments.SourceDataSource;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.client.Transport;
@@ -573,35 +571,66 @@
throws WSIFException {
Trc.entry(null, msg, name, value, type);
- if (DataHandler.class.equals(type)
- && AttachmentPart.class.isAssignableFrom(value.getClass())) {
- AttachmentPart ap = (AttachmentPart) value;
- try {
+ try {
+ if (DataHandler.class.equals(type)
+ && AttachmentPart.class.isAssignableFrom(value.getClass())) {
+ AttachmentPart ap = (AttachmentPart) value;
DataHandler dh = ap.getDataHandler();
msg.setObjectPart(name, dh);
- } catch (SOAPException se) {
- Trc.exception(se);
+ } else if (
+ (String.class.equals(type)
+ || Image.class.equals(type)
+ || Source.class.equals(type)
+ || MimeMultipart.class.equals(type))
+ && AttachmentPart.class.isAssignableFrom(value.getClass())) {
+
+ AttachmentPart ap = (AttachmentPart) value;
+ InputStream is = ap.getDataHandler().getInputStream();
+ byte[] bBuff = new byte[is.available()];
+ is.read(bBuff);
+
+ if (String.class.equals(type))
+ msg.setObjectPart(name, new String(bBuff));
+ else if (Image.class.equals(type))
+ msg.setObjectPart(
+ name,
+ new ImageIcon(bBuff).getImage());
+// else if (Source.class.equals(type))
+// msg.setObjectPart(name, new Source(bBuff));
+// else if (MimeMultipart.class.equals(type))
+// msg.setObjectPart(name, new MimeMultipart(bBuff));
+ } else if (
+ type != null // will be null for async responses
+ && !type.isPrimitive()
+ && !(type.isAssignableFrom(value.getClass()))) {
throw new WSIFException(
- "WSIFOperation_ApacheAxis.setMessagePart messageName="
- + (msg.getName() == null ? "null" : msg.getName())
- + " partName="
- + name
- + " caught "
- + se);
- }
- } else if (
- type != null // will be null for async responses
- && !type.isPrimitive()
- && !(type.isAssignableFrom(value.getClass()))) {
+ "return value "
+ + value
+ + " has unexpected type "
+ + value.getClass()
+ + " instead of "
+ + type);
+ } else
+ msg.setObjectPart(name, value);
+ } catch (SOAPException se) {
+ Trc.exception(se);
throw new WSIFException(
- "return value "
- + value
- + " has unexpected type "
- + value.getClass()
- + " instead of "
- + type);
- } else
- msg.setObjectPart(name, value);
+ "WSIFOperation_ApacheAxis.setMessagePart messageName="
+ + (msg.getName() == null ? "null" : msg.getName())
+ + " partName="
+ + name
+ + " caught "
+ + se);
+ } catch (IOException ioe) {
+ Trc.exception(ioe);
+ throw new WSIFException(
+ "WSIFOperation_ApacheAxis.setMessagePart messageName="
+ + (msg.getName() == null ? "null" : msg.getName())
+ + " partName="
+ + name
+ + " caught "
+ + ioe);
+ }
Trc.exit();
}
1.1 xml-axis-wsif/java/test/proposals/mime/WSIFFrame.java
Index: WSIFFrame.java
===================================================================
package proposals.mime;
import java.awt.Canvas;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
public class WSIFFrame extends Frame {
private static Frame[] frames = new Frame[2];
private static int frameIndex = 0;
private Image im = null;
public static void display(Image im, String title) throws Exception {
Frame f = new WSIFFrame(im,title);
frames[frameIndex] = f;
frameIndex++;
f.pack();
f.show();
}
public WSIFFrame(Image im, String title) {
super(title);
this.im = im;
}
public void paint(Graphics g) {
g.drawImage(im, 0, 0, new Canvas());
}
public static void close() {
for (int i = 0; i < frameIndex; i++) {
frames[i].dispose();
frames[i] = null;
}
frameIndex=0;
}
public void finalize() throws Throwable {
for (int i = 0; i < frameIndex; i++) {
frames[i].dispose();
frames[i] = null;
}
frameIndex=0;
}
}
1.1 xml-axis-wsif/java/test/proposals/mime/axis.jpg
<<Binary file>>