KickJava   Java API By Example, From Geeks To Geeks.

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


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 import junit.framework.TestCase;
20 import org.apache.axis2.Constants;
21 import org.apache.axis2.addressing.AddressingConstants;
22 import org.apache.axis2.addressing.EndpointReference;
23 import org.apache.axis2.clientapi.AsyncResult;
24 import org.apache.axis2.clientapi.Callback;
25 import org.apache.axis2.context.MessageContext;
26 import org.apache.axis2.context.ServiceContext;
27 import org.apache.axis2.description.ServiceDescription;
28 import org.apache.axis2.integration.TestingUtils;
29 import org.apache.axis2.integration.UtilServer;
30 import org.apache.axis2.om.OMAbstractFactory;
31 import org.apache.axis2.om.OMElement;
32 import org.apache.axis2.om.OMFactory;
33 import org.apache.axis2.om.OMNamespace;
34 import org.apache.axis2.transport.http.SimpleHTTPServer;
35 import org.apache.axis2.util.Utils;
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39 import javax.xml.namespace.QName JavaDoc;
40
41 public class EchoRawXMLOnTwoChannelsTest extends TestCase {
42     private EndpointReference targetEPR =
43         new EndpointReference(
44             AddressingConstants.WSA_TO,
45             "http://127.0.0.1:"
46                 + (UtilServer.TESTING_PORT)
47                 + "/axis/services/EchoXMLService/echoOMElement");
48     private Log log = LogFactory.getLog(getClass());
49     private QName JavaDoc serviceName = new QName JavaDoc("EchoXMLService");
50     private QName JavaDoc operationName = new QName JavaDoc("echoOMElement");
51     private QName JavaDoc transportName = new QName JavaDoc("http://localhost/my", "NullTransport");
52
53     private AxisConfiguration engineRegistry;
54     private MessageContext mc;
55     private Thread JavaDoc thisThread;
56     private SimpleHTTPServer sas;
57     private ServiceContext serviceContext;
58
59     private boolean finish = false;
60
61     public EchoRawXMLOnTwoChannelsTest() {
62         super(EchoRawXMLOnTwoChannelsTest.class.getName());
63     }
64
65     public EchoRawXMLOnTwoChannelsTest(String JavaDoc testName) {
66         super(testName);
67     }
68
69     protected void setUp() throws Exception JavaDoc {
70         UtilServer.start();
71         UtilServer.getConfigurationContext().getAxisConfiguration().engageModule(
72             new QName JavaDoc("addressing"));
73
74         ServiceDescription service =
75             Utils.createSimpleService(
76                 serviceName,
77         Echo.class.getName(),
78                 operationName);
79         UtilServer.deployService(service);
80         serviceContext =
81             UtilServer.getConfigurationContext().createServiceContext(service.getName());
82
83     }
84
85     protected void tearDown() throws Exception JavaDoc {
86         UtilServer.unDeployService(serviceName);
87         UtilServer.stop();
88     }
89
90  
91
92     public void testEchoXMLCompleteASync() throws Exception JavaDoc {
93         ServiceDescription service =
94             Utils.createSimpleService(
95                 serviceName,
96         Echo.class.getName(),
97                 operationName);
98
99         ServiceContext serviceContext = UtilServer.createAdressedEnabledClientSide(service);
100
101         OMFactory fac = OMAbstractFactory.getOMFactory();
102
103         OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
104         OMElement method = fac.createOMElement("echoOMElement", omNs);
105         OMElement value = fac.createOMElement("myValue", omNs);
106         value.setText("Isaac Assimov, the foundation Sega");
107         method.addChild(value);
108
109         org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(serviceContext);
110         call.engageModule(new QName JavaDoc(Constants.MODULE_ADDRESSING));
111
112         try {
113             call.setTo(targetEPR);
114             call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);
115             Callback callback = new Callback() {
116                 public void onComplete(AsyncResult result) {
117                     TestingUtils.campareWithCreatedOMElement(result.getResponseEnvelope().getBody().getFirstElement());
118                     finish = true;
119                 }
120
121                 public void reportError(Exception JavaDoc e) {
122                     e.printStackTrace();
123                     finish = true;
124                 }
125             };
126
127             call.invokeNonBlocking(operationName.getLocalPart(), method, callback);
128             int index = 0;
129             while (!finish) {
130                 Thread.sleep(1000);
131                 index++;
132                 if (index > 10) {
133                     throw new AxisFault("Server is shutdown as the Async response take too longs time");
134                 }
135             }
136             log.info("send the reqest");
137             call.close();
138         } finally {
139             call.close();
140         }
141
142     }
143  }
144
Popular Tags