You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by th...@apache.org on 2005/07/03 11:05:15 UTC

svn commit: r208899 - in /webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom: ./ EchoRawMTOMLoadTest.java EchoRawMTOMTest.java EchoRawMTOMToBase64Test.java test.jpg

Author: thilina
Date: Sun Jul  3 02:05:15 2005
New Revision: 208899

URL: http://svn.apache.org/viewcvs?rev=208899&view=rev
Log:
Moving MTOM samples to a seperate package

Added:
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/test.jpg   (with props)

Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java?rev=208899&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java (added)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java Sun Jul  3 02:05:15 2005
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2004,2005 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.mtom;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.attachments.ByteArrayDataSource;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.om.impl.llom.OMTextImpl;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class EchoRawMTOMLoadTest extends TestCase {
+	private EndpointReference targetEPR = new EndpointReference(
+			AddressingConstants.WSA_TO, "http://127.0.0.1:"
+					+ (UtilServer.TESTING_PORT)
+					+ "/axis/services/EchoXMLService/echoOMElement");
+
+	private Log log = LogFactory.getLog(getClass());
+
+	private QName serviceName = new QName("EchoXMLService");
+
+	private QName operationName = new QName("echoOMElement");
+
+	private QName transportName = new QName("http://localhost/my",
+			"NullTransport");
+
+	private AxisConfiguration engineRegistry;
+
+	private MessageContext mc;
+
+	private ServiceContext serviceContext;
+
+	private ServiceDescription service;
+
+	private boolean finish = false;
+
+	public EchoRawMTOMLoadTest() {
+		super(EchoRawMTOMLoadTest.class.getName());
+	}
+
+	public EchoRawMTOMLoadTest(String testName) {
+		super(testName);
+	}
+
+	protected void setUp() throws Exception {
+		UtilServer.start(Constants.TESTING_PATH + "MTOM-enabledRepository");
+		service = Utils.createSimpleService(serviceName, Echo.class.getName(),
+				operationName);
+		UtilServer.deployService(service);
+		serviceContext = UtilServer.getConfigurationContext()
+				.createServiceContext(service.getName());
+	}
+
+	protected void tearDown() throws Exception {
+		UtilServer.unDeployService(serviceName);
+		UtilServer.stop();
+	}
+
+	private OMElement createEnvelope() {
+
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+		OMElement rpcWrapEle = fac.createOMElement("echoOMElement", omNs);
+		OMElement data = fac.createOMElement("data", omNs);
+		byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1,
+				98 };
+		for (int i = 0; i <1; i++) {
+			OMElement subData = fac.createOMElement("subData", omNs);
+			DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(
+					byteArray));
+			OMText textData = new OMTextImpl(dataHandler, true);
+			//OMText textData = new OMTextImpl("Thilina Gunarathne");
+			subData.addChild(textData);
+			data.addChild(subData);
+			System.out.println("Creating blobs "+i);
+		}
+		
+		rpcWrapEle.addChild(data);
+		return rpcWrapEle;
+	}
+
+	public void testEchoXMLSync() throws Exception {
+		for (int i = 0; i < 10; i++) {
+			SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+
+			OMElement payload = createEnvelope();
+
+			org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call();
+			call.setTo(targetEPR);
+			call.set(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+			call.setTransportInfo(Constants.TRANSPORT_HTTP,
+					Constants.TRANSPORT_HTTP, false);
+
+			OMElement result = (OMElement) call.invokeBlocking(operationName
+					.getLocalPart(), payload);
+			OMElement ele = (OMElement) result.getFirstChild();
+			OMElement ele1 = (OMElement)ele.getFirstChild();
+			OMText binaryNode = (OMText) ele1.getFirstChild();
+			System.out.println(i);
+		}
+	}
+
+}
\ No newline at end of file

Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java?rev=208899&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java (added)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java Sun Jul  3 02:05:15 2005
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2004,2005 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.mtom;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+import java.awt.Image;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.attachments.ImageDataSource;
+import org.apache.axis2.attachments.JDK13IO;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.om.impl.llom.OMTextImpl;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class EchoRawMTOMTest extends TestCase {
+	private EndpointReference targetEPR = new EndpointReference(
+			AddressingConstants.WSA_TO, "http://127.0.0.1:"
+					+ (UtilServer.TESTING_PORT)
+					+ "/axis/services/EchoXMLService/echoOMElement");
+
+	private Log log = LogFactory.getLog(getClass());
+
+	private QName serviceName = new QName("EchoXMLService");
+
+	private QName operationName = new QName("echoOMElement");
+
+	private QName transportName = new QName("http://localhost/my",
+			"NullTransport");
+
+	private String imageInFileName = "img/test.jpg";
+
+	private String imageOutFileName = "mtom/img/testOut.jpg";
+
+	private AxisConfiguration engineRegistry;
+
+	private MessageContext mc;
+
+	private ServiceContext serviceContext;
+
+	private ServiceDescription service;
+
+	private boolean finish = false;
+
+	public EchoRawMTOMTest() {
+		super(EchoRawMTOMTest.class.getName());
+	}
+
+	public EchoRawMTOMTest(String testName) {
+		super(testName);
+	}
+
+	protected void setUp() throws Exception {
+		UtilServer.start(Constants.TESTING_PATH + "MTOM-enabledRepository");
+		service = Utils.createSimpleService(serviceName, Echo.class.getName(),
+				operationName);
+		UtilServer.deployService(service);
+		serviceContext = UtilServer.getConfigurationContext()
+				.createServiceContext(service.getName());
+	}
+
+	protected void tearDown() throws Exception {
+		UtilServer.unDeployService(serviceName);
+		UtilServer.stop();
+	}
+
+	private OMElement createEnvelope() throws Exception {
+
+		DataHandler expectedDH;
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+		OMElement rpcWrapEle = fac.createOMElement("echoOMElement", omNs);
+		OMElement data = fac.createOMElement("data", omNs);
+		Image expectedImage;
+		expectedImage = new JDK13IO()
+				.loadImage(getResourceAsStream("org/apache/axis2/mtom/test.jpg"));
+
+		ImageDataSource dataSource = new ImageDataSource("test.jpg",
+				expectedImage);
+		expectedDH = new DataHandler(dataSource);
+		OMTextImpl textData = new OMTextImpl(expectedDH, true);
+		data.addChild(textData);
+		//OMTextImpl textData1 = new OMTextImpl(expectedDH, true);
+		//data.addChild(textData1);
+		rpcWrapEle.addChild(data);
+		return rpcWrapEle;
+
+	}
+
+	public void testEchoXMLSync() throws Exception {
+		SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+
+		OMElement payload = createEnvelope();
+
+		org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call();
+		call.setTo(targetEPR);
+		call.set(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+		call.setTransportInfo(Constants.TRANSPORT_HTTP,
+				Constants.TRANSPORT_HTTP, false);
+
+		OMElement result = (OMElement) call.invokeBlocking(operationName
+				.getLocalPart(), payload);
+		// result.serializeWithCache(new
+		// OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out)));
+		OMElement ele = (OMElement) result.getFirstChild();
+		OMText binaryNode = (OMText) ele.getFirstChild();
+		DataHandler actualDH;
+		actualDH = binaryNode.getDataHandler();
+		Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
+				.getInputStream());
+		FileOutputStream imageOutStream = new FileOutputStream("testout.jpg");
+		new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
+
+	}
+
+	private InputStream getResourceAsStream(String path) {
+		ClassLoader cl = Thread.currentThread().getContextClassLoader();
+		return cl.getResourceAsStream(path);
+	}
+}
\ No newline at end of file

Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java?rev=208899&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java (added)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java Sun Jul  3 02:05:15 2005
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2004,2005 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.mtom;
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.attachments.ByteArrayDataSource;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMOutput;
+import org.apache.axis2.om.impl.llom.OMTextImpl;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class EchoRawMTOMToBase64Test extends TestCase {
+    private EndpointReference targetEPR =
+            new EndpointReference(AddressingConstants.WSA_TO,
+                    "http://127.0.0.1:"
+            + (UtilServer.TESTING_PORT)
+            + "/axis/services/EchoXMLService/echoMTOMtoBase64");
+    private Log log = LogFactory.getLog(getClass());
+    private QName serviceName = new QName("EchoXMLService");
+    private QName operationName = new QName("echoMTOMtoBase64");
+    private QName transportName = new QName("http://localhost/my", "NullTransport");
+
+    private AxisConfiguration engineRegistry;
+    private MessageContext mc;
+    //private Thread thisThread;
+   // private SimpleHTTPServer sas;
+    private ServiceContext serviceContext;
+    private ServiceDescription service;
+
+    private boolean finish = false;
+
+    public EchoRawMTOMToBase64Test() {
+        super(EchoRawMTOMToBase64Test.class.getName());
+    }
+
+    public EchoRawMTOMToBase64Test(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+        UtilServer.start();
+        service =
+                Utils.createSimpleService(serviceName,
+        Echo.class.getName(),
+                        operationName);
+        UtilServer.deployService(service);
+        serviceContext =
+                UtilServer.getConfigurationContext().createServiceContext(service.getName());
+    }
+
+    protected void tearDown() throws Exception {
+        UtilServer.unDeployService(serviceName);
+        UtilServer.stop();
+    }
+
+    private OMElement createEnvelope() {
+    	
+    	 OMFactory fac = OMAbstractFactory.getOMFactory();
+    	 OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+    	 OMElement rpcWrapEle = fac.createOMElement("echoMTOMtoBase64",omNs);
+		 OMElement data = fac.createOMElement("data", omNs);
+		 byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1,
+				98 };
+		 DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
+		 OMTextImpl textData = new OMTextImpl(dataHandler, true);
+		 data.addChild(textData); 
+         rpcWrapEle.addChild(data);
+		 return rpcWrapEle;
+    }
+
+
+    public void testEchoXMLSync() throws Exception {
+    	for(int i=0; i<10;i++)
+    	{
+    	SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+
+        OMElement payload = createEnvelope();
+
+        org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call();
+
+        call.setTo(targetEPR);
+        call.set(Constants.Configuration.ENABLE_MTOM,Constants.VALUE_TRUE);
+        call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
+
+        OMElement result =
+                (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload);
+        result.serializeWithCache(new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out)));
+        call.close();
+        System.out.println(i);
+    	}
+    }
+
+}

Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/test.jpg
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/test.jpg?rev=208899&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/test.jpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream