Author: darran.lofthouse(a)jboss.com
Date: 2009-07-21 12:46:23 -0400 (Tue, 21 Jul 2009)
New Revision: 10369
Modified:
stack/native/branches/dlofthouse/JBWS-2706/src/main/java/org/jboss/ws/core/EndpointInvocation.java
stack/native/branches/dlofthouse/JBWS-2706/src/main/java/org/jboss/ws/core/utils/MimeUtils.java
Log:
Prototype fix
Modified:
stack/native/branches/dlofthouse/JBWS-2706/src/main/java/org/jboss/ws/core/EndpointInvocation.java
===================================================================
---
stack/native/branches/dlofthouse/JBWS-2706/src/main/java/org/jboss/ws/core/EndpointInvocation.java 2009-07-21
16:44:12 UTC (rev 10368)
+++
stack/native/branches/dlofthouse/JBWS-2706/src/main/java/org/jboss/ws/core/EndpointInvocation.java 2009-07-21
16:46:23 UTC (rev 10369)
@@ -23,6 +23,7 @@
// $Id$
+import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
@@ -43,6 +44,7 @@
import org.jboss.ws.core.soap.SOAPContentElement;
import org.jboss.ws.core.utils.HolderUtils;
import org.jboss.ws.core.utils.MimeUtils;
+import org.jboss.ws.core.utils.MimeUtils.ByteArrayConverter;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.ws.metadata.umdm.ParameterMetaData;
import org.jboss.ws.metadata.umdm.WrappedParameter;
@@ -247,7 +249,17 @@
{
Class valueType = retValue.getClass();
if (JavaUtils.isAssignableFrom(javaType, valueType) == false)
- throw new SOAPException("javaType [" + javaType.getName() +
"] is not assignable from attachment content: " + valueType.getName());
+ {
+ if (retValue instanceof InputStream)
+ {
+ ByteArrayConverter converter =
MimeUtils.getConverterForJavaType(javaType);
+ retValue = converter.readFrom((InputStream)retValue);
+ }
+ else
+ {
+ throw new SOAPException("javaType [" + javaType.getName()
+ "] is not assignable from attachment content: " + valueType.getName());
+ }
+ }
}
}
}
Modified:
stack/native/branches/dlofthouse/JBWS-2706/src/main/java/org/jboss/ws/core/utils/MimeUtils.java
===================================================================
---
stack/native/branches/dlofthouse/JBWS-2706/src/main/java/org/jboss/ws/core/utils/MimeUtils.java 2009-07-21
16:44:12 UTC (rev 10368)
+++
stack/native/branches/dlofthouse/JBWS-2706/src/main/java/org/jboss/ws/core/utils/MimeUtils.java 2009-07-21
16:46:23 UTC (rev 10369)
@@ -27,6 +27,7 @@
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -190,7 +191,9 @@
converter = new StringConverter();
else if (JavaUtils.isAssignableFrom(java.io.InputStream.class, targetClazz))
converter = new StreamConverter();
-
+ else if (JavaUtils.isAssignableFrom(byte[].class, targetClazz))
+ converter = new RealByteArrayConverter();
+
if(null == converter)
throw new WSException("No ByteArrayConverter for class: " +
targetClazz.getName());
@@ -330,6 +333,49 @@
}
}
+ public static class RealByteArrayConverter implements ByteArrayConverter
+ {
+ public Object readFrom(InputStream in)
+ {
+ Object converted = null;
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IOUtils.copyStream(baos, in);
+
+ in.close();
+
+ converted = baos.toByteArray();
+ }
+ catch (IOException e)
+ {
+ throw new WSException("Failed to convert byte[]");
+ }
+
+ return converted;
+ }
+
+ public void writeTo(Object obj, OutputStream out)
+ {
+ if (obj instanceof byte[])
+ {
+ byte[] bytes = (byte[])obj;
+ try
+ {
+ out.write(bytes);
+ }
+ catch (IOException e)
+ {
+ throw new WSException("Failed to convert " + obj.getClass());
+ }
+ }
+ else
+ {
+ throw new WSException("Unable to convert " + obj.getClass());
+ }
+ }
+ }
+
public static class StreamConverter implements ByteArrayConverter
{
public Object readFrom(InputStream in) {
Show replies by date