KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > engine > MessageWithServerTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis2.engine;
18
19 //todo
20

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 JavaDoc;
33 import java.io.InputStream JavaDoc;
34 import java.io.InputStreamReader JavaDoc;
35 import java.io.OutputStream JavaDoc;
36 import java.io.Reader JavaDoc;
37 import java.net.Socket JavaDoc;
38
39 public class MessageWithServerTest extends TestCase {
40     private Log log = LogFactory.getLog(getClass());
41     private QName JavaDoc serviceName = new QName JavaDoc("", "EchoService");
42     private QName JavaDoc operationName =
43         new QName JavaDoc("http://ws.apache.org/axis2", "echoVoid");
44     private QName JavaDoc transportName = new QName JavaDoc("", "NullTransport");
45
46     private AxisConfiguration engineRegistry;
47     private MessageContext mc;
48     private Thread JavaDoc thisThread;
49     private SimpleHTTPServer sas;
50     private ClassLoader JavaDoc cl;
51
52     public MessageWithServerTest(String JavaDoc testName) {
53         super(testName);
54         cl = Thread.currentThread().getContextClassLoader();
55     }
56
57     protected void setUp() throws Exception JavaDoc {
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         //service.setFaultInFlow(new MockFlow("service faultflow", 1));
65

66         ModuleDescription m1 = new ModuleDescription(new QName JavaDoc("", "A Mdoule 1"));
67         m1.setInFlow(new MockFlow("service module inflow", 4));
68         //m1.setFaultInFlow(new MockFlow("service module faultflow", 1));
69
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 JavaDoc {
79         UtilServer.unDeployService(serviceName);
80         UtilServer.stop();
81     }
82
83     public void testEchoStringServer() throws Exception JavaDoc {
84         InputStream JavaDoc in = cl.getResourceAsStream("soap/soapmessage.txt");
85
86         Socket JavaDoc socket = new Socket JavaDoc("127.0.0.1", UtilServer.TESTING_PORT);
87         OutputStream JavaDoc 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 JavaDoc respose = socket.getInputStream();
95         Reader JavaDoc rReader = new InputStreamReader JavaDoc(respose);
96         char[] charBuf = new char[1024];
97         while ((index = rReader.read(charBuf)) > 0) {
98             log.info(new String JavaDoc(charBuf));
99         }
100
101         in.close();
102         out.close();
103
104         rReader.close();
105         socket.close();
106     }
107 }
108
Popular Tags