Author: heiko.braun(a)jboss.com
Date: 2006-10-27 09:27:04 -0400 (Fri, 27 Oct 2006)
New Revision: 1322
Modified:
branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPContentElement.java
branches/jbossws-1.0/src/main/java/org/jboss/ws/xop/JBossXBContentAdapter.java
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/samples/mtom/XOPRpcTestCase.java
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/xop/doclit/XOPBase.java
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/xop/rpclit/XOPBase.java
Log:
fixed xop samples
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPContentElement.java
===================================================================
---
branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPContentElement.java 2006-10-27
11:47:18 UTC (rev 1321)
+++
branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPContentElement.java 2006-10-27
13:27:04 UTC (rev 1322)
@@ -26,6 +26,7 @@
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
+import org.jboss.ws.soap.attachment.SwapableMemoryDataSource;
import org.jboss.ws.binding.BindingException;
import org.jboss.ws.binding.DeserializerSupport;
import org.jboss.ws.binding.SerializationContext;
@@ -40,6 +41,7 @@
import org.jboss.ws.utils.DOMUtils;
import org.jboss.ws.utils.DOMWriter;
import org.jboss.ws.utils.JavaUtils;
+import org.jboss.ws.utils.MimeUtils;
import org.jboss.ws.xop.XOPContext;
import org.w3c.dom.*;
@@ -47,8 +49,12 @@
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
import java.io.IOException;
import java.io.Writer;
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.Iterator;
@@ -279,7 +285,33 @@
if (isAssignable == false)
{
- throw new WSException("Java type '" + javaType +
"' is not assignable from: " + objType.getName());
+ // handle XOP simple types, i.e. in RPC/LIT
+ try
+ {
+ String contentType = MimeUtils.resolveMimeType(javaType);
+ log.debug("Adopt DataHandler to " + javaType +",
contentType "+ contentType);
+
+ DataSource ds = new
SwapableMemoryDataSource(((DataHandler)obj).getInputStream(), contentType);
+ DataHandler dh = new DataHandler(ds);
+ obj = dh.getContent();
+
+ // 'application/octet-stream' will return a byte[] instead
fo the stream
+ if(obj instanceof InputStream)
+ {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ dh.writeTo(bout);
+ obj = bout.toByteArray();
+ }
+ }
+ catch (IOException e)
+ {
+ throw new WSException("Failed to adopt XOP content type",
e);
+ }
+
+ if(!JavaUtils.isAssignableFrom(javaType, obj.getClass()))
+ {
+ throw new WSException("Java type '" + javaType +
"' is not assignable from: " + objType.getName());
+ }
}
}
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/xop/JBossXBContentAdapter.java
===================================================================
---
branches/jbossws-1.0/src/main/java/org/jboss/ws/xop/JBossXBContentAdapter.java 2006-10-27
11:47:18 UTC (rev 1321)
+++
branches/jbossws-1.0/src/main/java/org/jboss/ws/xop/JBossXBContentAdapter.java 2006-10-27
13:27:04 UTC (rev 1322)
@@ -110,7 +110,7 @@
Class targetClass = ctx.resolvePropertyType();
if(null==targetClass) {
- throw new WSException("Failed targte property type on "+
ctx.getParticle());
+ throw new WSException("Failed to resolve target property type on "+
ctx.getParticle());
}
boolean isRegularMessage = !XOPContext.isXOPMessage();
Modified:
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/samples/mtom/XOPRpcTestCase.java
===================================================================
---
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/samples/mtom/XOPRpcTestCase.java 2006-10-27
11:47:18 UTC (rev 1321)
+++
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/samples/mtom/XOPRpcTestCase.java 2006-10-27
13:27:04 UTC (rev 1322)
@@ -86,8 +86,7 @@
//((Stub)port)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://" +
getServerHost() + ":8081/jaxrpc-samples-mtom");
}
-
- /*public void testSimpleBinary() throws Exception
+ public void testSimpleBinary() throws Exception
{
DataHandler dh = new DataHandler(
new
FileDataSource("resources/jaxrpc/samples/mtom/disguised_jpeg.xcf")
@@ -98,28 +97,13 @@
assertTrue("Content length is different", bytesIn.length ==
bytesOut.length);
}
- public void testMTOMDisabledClientside() throws Exception
- {
- URL url = new File("resources/jaxrpc/samples/mtom/attach.jpeg").toURL();
-
- // disable MTOM
- ((Stub)port)._setProperty("org.jboss.ws.mtom.enabled", Boolean.FALSE);
-
- DataHandler dh = new DataHandler(url);
- byte[] bytesIn = IOUtils.convertToBytes(dh);
- byte[] bytesOut = port.sendOctets("MTOM disabled request", bytesIn);
- assertNotNull(bytesOut);
- assertTrue("Content length is different", bytesIn.length ==
bytesOut.length);
- assertEquals(bytesIn, bytesOut);
- }
-
public void testAbstractParameterTypes() throws Exception
{
URL url = new File("resources/jaxrpc/samples/mtom/attach.jpeg").toURL();
DataHandler value = port.sendMimeImageJPEG("Some text message", new
DataHandler(url));
assertNotNull(value);
assertTrue("Wrong return content-type returned",
value.getContentType().equals("image/jpeg"));
- }*/
+ }
public void testConcreteParameterTypes() throws Exception
{
@@ -129,7 +113,7 @@
assertEquals("Value mismatch", value, xoppart);
}
- /*public void testParameterConversion() throws Exception
+ public void testParameterConversion() throws Exception
{
FileInputStream stream = new
FileInputStream("resources/jaxrpc/samples/mtom/attach.xml");
StreamSource source = new StreamSource(stream);
@@ -147,5 +131,24 @@
DataHandler value = port.sendMimeApplicationXML("Some text message",
source);
assertNotNull(value);
assertTrue("Wrong return value content-type",
value.getContentType().equals("application/xml"));
- }*/
+ }
+
+ public void testMTOMDisabledClientside() throws Exception
+ {
+ URL url = new File("resources/jaxrpc/samples/mtom/attach.jpeg").toURL();
+
+ setMTOMEnabled(Boolean.FALSE);
+
+ DataHandler dh = new DataHandler(url);
+ byte[] bytesIn = IOUtils.convertToBytes(dh);
+ byte[] bytesOut = port.sendOctets("MTOM disabled request", bytesIn);
+ assertNotNull(bytesOut);
+ assertTrue("Content length is different", bytesIn.length ==
bytesOut.length);
+ assertEquals(bytesIn, bytesOut);
+ }
+
+ private void setMTOMEnabled(Boolean b)
+ {
+ ((Stub)port)._setProperty("org.jboss.ws.mtom.enabled", b);
+ }
}
Modified:
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/xop/doclit/XOPBase.java
===================================================================
---
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/xop/doclit/XOPBase.java 2006-10-27
11:47:18 UTC (rev 1321)
+++
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/xop/doclit/XOPBase.java 2006-10-27
13:27:04 UTC (rev 1322)
@@ -35,7 +35,7 @@
/**
* @author Heiko Braun <heiko.braun(a)jboss.com>
- * @version $Id$
+ * @version $Id:XOPBase.java 1321 2006-10-27 11:47:18Z heiko.braun(a)jboss.com $
* @since Sep 25, 2006
*/
public abstract class XOPBase extends JBossWSTest {
@@ -91,27 +91,32 @@
Image image = XOPTestSupport.createTestImage();
- // disable MTOM
- ((Stub)getPort())._setProperty(StubExt.PROPERTY_MTOM_ENABLED, Boolean.FALSE);
+ if(image!=null)
+ {
+ // disable MTOM
+ ((Stub)getPort())._setProperty(StubExt.PROPERTY_MTOM_ENABLED, Boolean.FALSE);
- PingImage pingImage = new PingImage("0|1", image);
- PingImageResponse response = getPort().pingImage(pingImage);
- assertNotNull("Return xopContent was null", response);
- assertNotNull("Return xopContent was null", response.getXopContent());
+ PingImage pingImage = new PingImage("0|1", image);
+ PingImageResponse response = getPort().pingImage(pingImage);
+ assertNotNull("Return xopContent was null", response);
+ assertNotNull("Return xopContent was null",
response.getXopContent());
+ }
}
public void testImageRequestOptimized() throws Exception {
Image image = XOPTestSupport.createTestImage();
- // enable MTOM
- ((Stub)getPort())._setProperty(StubExt.PROPERTY_MTOM_ENABLED, Boolean.TRUE);
+ if(image!=null)
+ {
+ // enable MTOM
+ ((Stub)getPort())._setProperty(StubExt.PROPERTY_MTOM_ENABLED, Boolean.TRUE);
- PingImage pingImage = new PingImage("1|0", image);
- PingImageResponse response = getPort().pingImage(pingImage);
- assertNotNull("Response was null", response);
- assertNotNull("Return xopContent was null", response.getXopContent());
-
+ PingImage pingImage = new PingImage("1|0", image);
+ PingImageResponse response = getPort().pingImage(pingImage);
+ assertNotNull("Response was null", response);
+ assertNotNull("Return xopContent was null",
response.getXopContent());
+ }
}
public void testSourceResponseOptimized() throws Exception {
Modified:
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/xop/rpclit/XOPBase.java
===================================================================
---
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/xop/rpclit/XOPBase.java 2006-10-27
11:47:18 UTC (rev 1321)
+++
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/xop/rpclit/XOPBase.java 2006-10-27
13:27:04 UTC (rev 1322)
@@ -36,7 +36,7 @@
/**
* @author Heiko Braun <heiko.braun(a)jboss.com>
- * @version $Id$
+ * @version $Id:XOPBase.java 1321 2006-10-27 11:47:18Z heiko.braun(a)jboss.com $
* @since Sep 25, 2006
*/
public abstract class XOPBase extends JBossWSTest {
@@ -105,27 +105,32 @@
Image image = XOPTestSupport.createTestImage();
- // disable MTOM
- ((Stub)getPort())._setProperty(StubExt.PROPERTY_MTOM_ENABLED, Boolean.FALSE);
+ if(image!=null)
+ {
+ // disable MTOM
+ ((Stub)getPort())._setProperty(StubExt.PROPERTY_MTOM_ENABLED, Boolean.FALSE);
- PingImage pingImage = new PingImage("0|1", image);
- PingImageResponse response = getPort().pingImage(pingImage);
- assertNotNull("Return xopContent was null", response);
- assertNotNull("Return xopContent was null", response.getXopContent());
+ PingImage pingImage = new PingImage("0|1", image);
+ PingImageResponse response = getPort().pingImage(pingImage);
+ assertNotNull("Return xopContent was null", response);
+ assertNotNull("Return xopContent was null",
response.getXopContent());
+ }
}
public void testImageRequestOptimized() throws Exception {
Image image = XOPTestSupport.createTestImage();
- // enable MTOM
- ((Stub)getPort())._setProperty(StubExt.PROPERTY_MTOM_ENABLED, Boolean.TRUE);
+ if(image!=null)
+ {
+ // enable MTOM
+ ((Stub)getPort())._setProperty(StubExt.PROPERTY_MTOM_ENABLED, Boolean.TRUE);
- PingImage pingImage = new PingImage("1|0", image);
- PingImageResponse response = getPort().pingImage(pingImage);
- assertNotNull("Response was null", response);
- assertNotNull("Return xopContent was null", response.getXopContent());
-
+ PingImage pingImage = new PingImage("1|0", image);
+ PingImageResponse response = getPort().pingImage(pingImage);
+ assertNotNull("Response was null", response);
+ assertNotNull("Return xopContent was null",
response.getXopContent());
+ }
}
public void testSourceResponseOptimized() throws Exception {