KickJava   Java API By Example, From Geeks To Geeks.

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


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