1 16 17 package org.apache.axis2.engine; 18 19 21 import junit.framework.TestCase; 22 import org.apache.axis2.context.MessageContext; 23 import org.apache.axis2.description.ModuleDescription; 24 import org.apache.axis2.description.OperationDescription; 25 import org.apache.axis2.description.ServiceDescription; 26 import org.apache.axis2.integration.UtilServer; 27 import org.apache.axis2.transport.http.SimpleHTTPServer; 28 import org.apache.axis2.util.Utils; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 import javax.xml.namespace.QName ; 33 import java.io.InputStream ; 34 import java.io.InputStreamReader ; 35 import java.io.OutputStream ; 36 import java.io.Reader ; 37 import java.net.Socket ; 38 39 public class MessageWithServerTest extends TestCase { 40 private Log log = LogFactory.getLog(getClass()); 41 private QName serviceName = new QName ("", "EchoService"); 42 private QName operationName = 43 new QName ("http://ws.apache.org/axis2", "echoVoid"); 44 private QName transportName = new QName ("", "NullTransport"); 45 46 private AxisConfiguration engineRegistry; 47 private MessageContext mc; 48 private Thread thisThread; 49 private SimpleHTTPServer sas; 50 private ClassLoader cl; 51 52 public MessageWithServerTest(String testName) { 53 super(testName); 54 cl = Thread.currentThread().getContextClassLoader(); 55 } 56 57 protected void setUp() throws Exception { 58 UtilServer.start(); 59 ServiceDescription service = Utils.createSimpleService(serviceName,Echo.class.getName(),operationName); 60 61 62 service.setInFlow(new MockFlow("service inflow", 4)); 63 service.setOutFlow(new MockFlow("service outflow", 5)); 64 66 ModuleDescription m1 = new ModuleDescription(new QName ("", "A Mdoule 1")); 67 m1.setInFlow(new MockFlow("service module inflow", 4)); 68 service.engageModule(m1); 70 71 OperationDescription operation = new OperationDescription(operationName); 72 service.addOperation(operation); 73 74 UtilServer.deployService(service); 75 UtilServer.start(); 76 } 77 78 protected void tearDown() throws Exception { 79 UtilServer.unDeployService(serviceName); 80 UtilServer.stop(); 81 } 82 83 public void testEchoStringServer() throws Exception { 84 InputStream in = cl.getResourceAsStream("soap/soapmessage.txt"); 85 86 Socket socket = new Socket ("127.0.0.1", UtilServer.TESTING_PORT); 87 OutputStream out = socket.getOutputStream(); 88 byte[] buf = new byte[1024]; 89 int index = -1; 90 while ((index = in.read(buf)) > 0) { 91 out.write(buf, 0, index); 92 } 93 94 InputStream respose = socket.getInputStream(); 95 Reader rReader = new InputStreamReader (respose); 96 char[] charBuf = new char[1024]; 97 while ((index = rReader.read(charBuf)) > 0) { 98 log.info(new String (charBuf)); 99 } 100 101 in.close(); 102 out.close(); 103 104 rReader.close(); 105 socket.close(); 106 } 107 } 108 | Popular Tags |