You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/08/14 07:18:23 UTC

svn commit: r232581 - in /webservices/axis/trunk/java/modules: integration/test/org/apache/axis2/mtom/ samples/src/sample/mtom/imagetransfer/client/ samples/src/sample/mtom/imagetransfer/service/ xml/src/org/apache/axis2/attachments/utils/ xml/test/org...

Author: dims
Date: Sat Aug 13 22:18:15 2005
New Revision: 232581

URL: http://svn.apache.org/viewcvs?rev=232581&view=rev
Log:
Fix for (AXIS2-146) Replace JDK13IO with MerlinIO

Get rid of the interface (make it a class) and populate it with code from Axis 1.X's MerlinIO.


Added:
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageIO.java   (with props)
Removed:
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/JDK13IO.java
Modified:
    webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
    webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
    webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/client/MTOMClientModel.java
    webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/service/MTOMService.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java
    webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java

Modified: webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java?rev=232581&r1=232580&r2=232581&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java (original)
+++ webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java Sat Aug 13 22:18:15 2005
@@ -23,7 +23,7 @@
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.attachments.utils.ImageDataSource;
-import org.apache.axis2.attachments.utils.JDK13IO;
+import org.apache.axis2.attachments.utils.ImageIO;
 import org.apache.axis2.context.ServiceContext;
 import org.apache.axis2.description.ServiceDescription;
 import org.apache.axis2.engine.Echo;
@@ -89,7 +89,7 @@
         OMElement rpcWrapEle = fac.createOMElement("echoOMElement", omNs);
         data = fac.createOMElement("data", omNs);
         Image expectedImage;
-        expectedImage = new JDK13IO()
+        expectedImage = new ImageIO()
                 .loadImage(getResourceAsStream("org/apache/axis2/mtom/test.jpg"));
 
         ImageDataSource dataSource = new ImageDataSource("test.jpg",

Modified: webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java?rev=232581&r1=232580&r2=232581&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java (original)
+++ webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java Sat Aug 13 22:18:15 2005
@@ -32,7 +32,7 @@
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.attachments.utils.ImageDataSource;
-import org.apache.axis2.attachments.utils.JDK13IO;
+import org.apache.axis2.attachments.utils.ImageIO;
 import org.apache.axis2.clientapi.AsyncResult;
 import org.apache.axis2.clientapi.Callback;
 import org.apache.axis2.context.ServiceContext;
@@ -102,7 +102,7 @@
         OMElement data = fac.createOMElement("data", omNs);
         Image expectedImage;
         expectedImage =
-                new JDK13IO()
+                new ImageIO()
                 .loadImage(getResourceAsStream("org/apache/axis2/mtom/test.jpg"));
         ImageDataSource dataSource = new ImageDataSource("test.jpg",
                 expectedImage);
@@ -182,10 +182,10 @@
         // Save the image
         DataHandler actualDH;
         actualDH = binaryNode.getDataHandler();
-        Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
+        Image actualObject = new ImageIO().loadImage(actualDH.getDataSource()
                 .getInputStream());
 //        FileOutputStream imageOutStream = new FileOutputStream("target/testout.jpg");
-//        new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
+//        new ImageIO().saveImage("image/jpeg", actualObject, imageOutStream);
 
     }
 

Modified: webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/client/MTOMClientModel.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/client/MTOMClientModel.java?rev=232581&r1=232580&r2=232581&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/client/MTOMClientModel.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/client/MTOMClientModel.java Sat Aug 13 22:18:15 2005
@@ -25,7 +25,7 @@
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.attachments.utils.ImageDataSource;
-import org.apache.axis2.attachments.utils.JDK13IO;
+import org.apache.axis2.attachments.utils.ImageIO;
 import org.apache.axis2.clientapi.Call;
 import org.apache.axis2.om.OMAbstractFactory;
 import org.apache.axis2.om.OMElement;
@@ -56,7 +56,7 @@
         OMElement data = fac.createOMElement("mtomSample", omNs);
         OMElement image = fac.createOMElement("image", omNs);
         Image expectedImage;
-        expectedImage = new JDK13IO()
+        expectedImage = new ImageIO()
                 .loadImage(new FileInputStream(inputFile));
 
         ImageDataSource dataSource = new ImageDataSource("test.jpg",

Modified: webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/service/MTOMService.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/service/MTOMService.java?rev=232581&r1=232580&r2=232581&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/service/MTOMService.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/mtom/imagetransfer/service/MTOMService.java Sat Aug 13 22:18:15 2005
@@ -15,7 +15,7 @@
  */
 package sample.mtom.imagetransfer.service;
 
-import org.apache.axis2.attachments.utils.JDK13IO;
+import org.apache.axis2.attachments.utils.ImageIO;
 import org.apache.axis2.om.*;
 
 import javax.activation.DataHandler;
@@ -35,10 +35,10 @@
         //Extracting the data and saving
         DataHandler actualDH;
         actualDH = binaryNode.getDataHandler();
-        Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
+        Image actualObject = new ImageIO().loadImage(actualDH.getDataSource()
                 .getInputStream());
         FileOutputStream imageOutStream = new FileOutputStream(fileName);
-        new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
+        new ImageIO().saveImage("image/jpeg", actualObject, imageOutStream);
         //setting response
         OMFactory fac = OMAbstractFactory.getOMFactory();
         OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns");

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java?rev=232581&r1=232580&r2=232581&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java Sat Aug 13 22:18:15 2005
@@ -41,7 +41,7 @@
         os = new ByteArrayOutputStream();
         try {
             if (data != null) {
-                new JDK13IO().saveImage(this.contentType, data, os);
+                new ImageIO().saveImage(this.contentType, data, os);
             }
         } catch (Exception e) {
             // log.error(Messages.getMessage("exception00"), e);

Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageIO.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageIO.java?rev=232581&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageIO.java (added)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageIO.java Sat Aug 13 22:18:15 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.attachments.utils;
+
+
+import sun.awt.image.codec.JPEGImageEncoderImpl;
+
+import javax.imageio.IIOImage;
+import javax.imageio.ImageWriter;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+/**
+ * JDK1.4 based Image I/O
+ */
+public class ImageIO extends Component {
+    /**
+     * Save an image.
+     *
+     * @param mimeType the mime-type of the format to save the image
+     * @param image    the image to save
+     * @param os       the stream to write to
+     * @throws Exception if an error prevents image encoding
+     */
+    public void saveImage(String mimeType, Image image, OutputStream os)
+            throws Exception {
+
+        ImageWriter writer = null;
+        Iterator iter = javax.imageio.ImageIO.getImageWritersByMIMEType(mimeType);
+        if (iter.hasNext()) {
+            writer = (ImageWriter) iter.next();
+        }
+        writer.setOutput(javax.imageio.ImageIO.createImageOutputStream(os));
+        BufferedImage rendImage = null;
+        if (image instanceof BufferedImage) {
+            rendImage = (BufferedImage) image;
+        } else {
+            MediaTracker tracker = new MediaTracker(this);
+            tracker.addImage(image, 0);
+            tracker.waitForAll();
+            rendImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 1);
+            Graphics g = rendImage.createGraphics();
+            g.drawImage(image, 0, 0, null);
+        }
+        writer.write(new IIOImage(rendImage, null, null));
+        writer.dispose();
+    } // saveImage
+
+    /**
+     * Load an Image.
+     *
+     * @param in the stream to load the image
+     * @return the Image
+     */
+    public Image loadImage(InputStream in) throws Exception {
+        return javax.imageio.ImageIO.read(in);
+    } // loadImage
+}
+

Propchange: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageIO.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java?rev=232581&r1=232580&r2=232581&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java (original)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java Sat Aug 13 22:18:15 2005
@@ -17,7 +17,7 @@
 package org.apache.axis2.attachments;
 
 import org.apache.axis2.attachments.utils.ImageDataSource;
-import org.apache.axis2.attachments.utils.JDK13IO;
+import org.apache.axis2.attachments.utils.ImageIO;
 import org.apache.axis2.om.AbstractTestCase;
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMText;
@@ -89,7 +89,7 @@
         OMElement data = new OMElementImpl("data", dataName);
 
         expectedImage =
-                new JDK13IO().loadImage(
+                new ImageIO().loadImage(
                         new FileInputStream(
                                 getTestResourceFile(imageInFileName)));
         ImageDataSource dataSource = new ImageDataSource("WaterLilies.jpg",
@@ -132,11 +132,11 @@
 
         DataHandler actualDH;
         actualDH = blob.getDataHandler();
-        Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
+        Image actualObject = new ImageIO().loadImage(actualDH.getDataSource()
                 .getInputStream());
         FileOutputStream imageOutStream = new FileOutputStream(
                 new File(imageOutFileName));
-        new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
+        new ImageIO().saveImage("image/jpeg", actualObject, imageOutStream);
 
     }