KickJava   Java API By Example, From Geeks To Geeks.

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


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 CommonsHTTPEchoRawXMLTest 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
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 CommonsHTTPEchoRawXMLTest() {
62         super(CommonsHTTPEchoRawXMLTest.class.getName());
63     }
64
65     public CommonsHTTPEchoRawXMLTest(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     public void testEchoXMLASync() throws Exception JavaDoc {
87         OMElement payload = TestingUtils.createDummyOMElement();
88
89         org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(Constants.TESTING_PATH+"commons-http-enabledRepository");
90
91         call.setTo(targetEPR);
92         call.setTransportInfo(Constants.TRANSPORT_COMMONS_HTTP, Constants.TRANSPORT_HTTP, false);
93
94         Callback callback = new Callback() {
95             public void onComplete(AsyncResult result) {
96                 TestingUtils.campareWithCreatedOMElement(result.getResponseEnvelope().getBody().getFirstElement());
97                  finish = true;
98             }
99
100             public void reportError(Exception JavaDoc e) {
101                 e.printStackTrace();
102                 finish = true;
103             }
104         };
105
106         call.invokeNonBlocking(operationName.getLocalPart(), payload, callback);
107         int index = 0;
108         while (!finish) {
109             Thread.sleep(1000);
110             index++;
111             if(index > 10 ){
112                 throw new AxisFault("Server is shutdown as the Async response take too longs time");
113             }
114         }
115         call.close();
116
117
118         log.info("send the reqest");
119     }
120
121     public void testEchoXMLSync() throws Exception JavaDoc {
122         SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
123
124         OMElement payload = TestingUtils.createDummyOMElement();
125
126         org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(Constants.TESTING_PATH+"commons-http-enabledRepository");
127
128         call.setTo(targetEPR);
129         call.setTransportInfo(Constants.TRANSPORT_COMMONS_HTTP, Constants.TRANSPORT_HTTP, false);
130
131         OMElement result =
132                 (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload);
133         TestingUtils.campareWithCreatedOMElement(result);
134         call.close();
135     }
136
137 }
138
Popular Tags