Author: thomas.diesler(a)jboss.com
Date: 2006-11-22 17:03:44 -0500 (Wed, 22 Nov 2006)
New Revision: 1509
Modified:
trunk/src/main/java/org/jboss/ws/soap/attachment/ImageDataContentHandler.java
Log:
[JBWS-1284] Gracefully handle invalid ImageIO mime types.
Modified: trunk/src/main/java/org/jboss/ws/soap/attachment/ImageDataContentHandler.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/soap/attachment/ImageDataContentHandler.java 2006-11-22
22:00:49 UTC (rev 1508)
+++
trunk/src/main/java/org/jboss/ws/soap/attachment/ImageDataContentHandler.java 2006-11-22
22:03:44 UTC (rev 1509)
@@ -30,6 +30,7 @@
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Iterator;
import javax.activation.ActivationDataFlavor;
@@ -39,6 +40,8 @@
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
+import org.jboss.logging.Logger;
+
/**
* <code>ImageDataContentHandler</code> is a JAF content handler that
handles
* marshalling/unmarshalling between <code>Image</code> objects and a
stream.
@@ -53,9 +56,13 @@
* an exception will be thrown indicating the lack of encoding support.
*
* @author <a href="mailto:jason@stacksmash.com">Jason T.
Greene</a>
+ * @author <a href="mailto:mageshbk@jboss.com">Magesh Kumar B</a>
*/
public class ImageDataContentHandler extends Component implements DataContentHandler
{
+ // provide logging
+ private static Logger log = Logger.getLogger(ImageDataContentHandler.class);
+
private static DataFlavor[] flavors;
static
@@ -71,11 +78,28 @@
String[] mimeTypes = ImageIO.getReaderMIMETypes();
if (mimeTypes == null)
return;
- flavors = new DataFlavor[mimeTypes.length];
+ ArrayList flavs = new ArrayList ();
+ DataFlavor flavor;
+ //flavors = new DataFlavor[mimeTypes.length];
for (int i = 0; i < mimeTypes.length; i++)
{
- flavors[i] = new ActivationDataFlavor(Image.class, mimeTypes[i],
"Image");
+ try
+ {
+ flavor = new ActivationDataFlavor(Image.class, mimeTypes[i],
"Image");
+ flavs.add(flavor);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ //This mime type is not supported
+ log.warn("Unsupported MIME Type '" + mimeTypes[i]
+"'");
+ }
}
+ int size = flavs.size();
+ flavors = new DataFlavor[size];
+ for (int i = 0; i < size; i++)
+ {
+ flavors[i] = (ActivationDataFlavor)flavs.get(i);
+ }
}
private static ImageWriter getImageWriter(String mimeType) {