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 2006/04/20 06:49:52 UTC
svn commit: r395480 - in
/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom:
EchoRawMTOMStreamingTest.java EchoService2.java
Author: dims
Date: Wed Apr 19 21:49:50 2006
New Revision: 395480
URL: http://svn.apache.org/viewcvs?rev=395480&view=rev
Log:
testcase for streaming attachments
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMStreamingTest.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService2.java
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMStreamingTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMStreamingTest.java?rev=395480&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMStreamingTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMStreamingTest.java Wed Apr 19 21:49:50 2006
@@ -0,0 +1,124 @@
+package org.apache.axis2.mtom;
+
+import org.apache.axis2.integration.UtilServerBasedTestCase;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.util.Utils;
+import org.apache.axis2.description.AxisService;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axiom.attachments.utils.ImageIO;
+import org.apache.axiom.attachments.utils.ImageDataSource;
+import org.apache.axiom.attachments.ByteArrayDataSource;
+import org.apache.axiom.soap.SOAP12Constants;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import java.awt.*;
+import java.io.InputStream;
+
+public class EchoRawMTOMStreamingTest extends UtilServerBasedTestCase implements TestConstants {
+
+ public static final EndpointReference targetEPR = new EndpointReference(
+ "http://127.0.0.1:" + (UtilServer.TESTING_PORT)
+// "http://127.0.0.1:" + 5556
+ + "/axis2/services/EchoService2/mtomSample");
+
+ private QName serviceName = new QName("EchoService2");
+
+ private QName operationName = new QName("mtomSample");
+
+ private OMElement data;
+
+ public EchoRawMTOMStreamingTest() {
+ super(EchoRawMTOMStreamingTest.class.getName());
+ }
+
+ public EchoRawMTOMStreamingTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return getTestSetup2(new TestSuite(EchoRawMTOMStreamingTest.class),
+ Constants.TESTING_PATH + "MTOM-enabledRepository");
+ }
+
+ protected void setUp() throws Exception {
+ AxisService service = Utils.createSimpleService(serviceName, EchoService2.class.getName(),
+ operationName);
+ UtilServer.deployService(service);
+ }
+
+ protected void tearDown() throws Exception {
+ UtilServer.unDeployService(serviceName);
+ }
+
+ private OMElement createEnvelope() throws Exception {
+
+ DataHandler expectedDH;
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+ OMElement rpcWrapEle = fac.createOMElement("mtomSample", omNs);
+ data = fac.createOMElement("data", omNs);
+ expectedDH = new DataHandler(new ByteArrayDataSource(new byte[]{13, 56, 65, 32, 12, 12, 7, -3, -2, -1,
+ 98}));
+ OMElement subData = fac.createOMElement("subData", omNs);
+ OMText textData = new OMTextImpl(expectedDH, fac);
+ subData.addChild(textData);
+ data.addChild(subData);
+ rpcWrapEle.addChild(data);
+ return rpcWrapEle;
+
+ }
+
+ public void testEchoXMLSync() throws Exception {
+
+ OMElement payload = createEnvelope();
+
+ Options options = new Options();
+ options.setTo(targetEPR);
+ options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+ options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+ options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+
+ ConfigurationContext configContext =
+ ConfigurationContextFactory.createConfigurationContextFromFileSystem(
+ Constants.TESTING_PATH + "commons-http-enabledRepository", null);
+ ServiceClient sender = new ServiceClient(configContext, null);
+ sender.setOptions(options);
+ options.setTo(targetEPR);
+
+ OMElement result = sender.sendReceive(payload);
+ this.campareWithCreatedOMElement(result);
+
+ }
+
+ private InputStream getResourceAsStream(String path) {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return cl.getResourceAsStream(path);
+ }
+
+ private void campareWithCreatedOMElement(OMElement element) {
+ OMElement firstChild = element.getFirstElement();
+ TestCase.assertNotNull(firstChild);
+ String originalTextValue = data.getFirstElement().getText();
+ String returnedTextValue = firstChild.getText();
+ TestCase.assertEquals(returnedTextValue, originalTextValue);
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService2.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService2.java?rev=395480&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService2.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService2.java Wed Apr 19 21:49:50 2006
@@ -0,0 +1,61 @@
+package org.apache.axis2.mtom;
+
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.attachments.IncomingAttachmentInputStream;
+import org.apache.axiom.attachments.IncomingAttachmentStreams;
+import org.apache.axiom.attachments.MIMEHelper;
+import org.apache.axiom.attachments.utils.IOUtils;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.util.Base64;
+import org.apache.axiom.om.impl.MTOMConstants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.wsdl.WSDLConstants;
+
+public class EchoService2 {
+
+ OperationContext oprCtx;
+
+ public void setOperationContext(OperationContext oprCtx) {
+ this.oprCtx = oprCtx;
+ }
+
+ public OMElement mtomSample(OMElement element) throws Exception {
+
+ MIMEHelper mimeHelper = null;
+
+ if (this.oprCtx != null) {
+ mimeHelper = (MIMEHelper) this.oprCtx.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE).getProperty(MTOMConstants.ATTACHMENTS);
+ } else {
+ throw new AxisFault("Message context not set/MIMEHelper not set");
+ }
+
+ // Get image data
+ IncomingAttachmentStreams streams = mimeHelper.getIncomingAttachmentStreams();
+ IncomingAttachmentInputStream stream = streams.getNextStream();
+
+ byte[] data = IOUtils.getStreamAsByteArray(stream);
+
+ //setting response
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns");
+ OMElement response, elem;
+
+ response = fac.createOMElement("response", ns);
+
+ elem = fac.createOMElement("data", ns);
+ elem.setText(Base64.encode(data));
+ response.addChild(elem);
+
+ return response;
+ }
+}