KickJava   Java API By Example, From Geeks To Geeks.

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


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.context.MessageContext;
24 import org.apache.axis2.context.ServiceContext;
25 import org.apache.axis2.description.ServiceDescription;
26 import org.apache.axis2.integration.TestingUtils;
27 import org.apache.axis2.integration.UtilServer;
28 import org.apache.axis2.om.OMAbstractFactory;
29 import org.apache.axis2.om.OMElement;
30 import org.apache.axis2.om.OMFactory;
31 import org.apache.axis2.om.OMNamespace;
32 import org.apache.axis2.transport.http.SimpleHTTPServer;
33 import org.apache.axis2.util.Utils;
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36
37 import javax.xml.namespace.QName JavaDoc;
38
39 public class EchoRawXMLOnTwoChannelsSyncTest extends TestCase {
40     private EndpointReference targetEPR =
41         new EndpointReference(
42             AddressingConstants.WSA_TO,
43             "http://127.0.0.1:"
44                 + (UtilServer.TESTING_PORT)
45                 + "/axis/services/EchoXMLService/echoOMElement");
46     private Log log = LogFactory.getLog(getClass());
47     private QName JavaDoc serviceName = new QName JavaDoc("EchoXMLService");
48     private QName JavaDoc operationName = new QName JavaDoc("echoOMElement");
49     private QName JavaDoc transportName = new QName JavaDoc("http://localhost/my", "NullTransport");
50
51     private AxisConfiguration engineRegistry;
52     private MessageContext mc;
53     private Thread JavaDoc thisThread;
54     private SimpleHTTPServer sas;
55     private ServiceContext serviceContext;
56
57     private boolean finish = false;
58
59     public EchoRawXMLOnTwoChannelsSyncTest() {
60         super(EchoRawXMLOnTwoChannelsSyncTest.class.getName());
61     }
62
63     public EchoRawXMLOnTwoChannelsSyncTest(String JavaDoc testName) {
64         super(testName);
65     }
66
67     protected void setUp() throws Exception JavaDoc {
68         UtilServer.start();
69         UtilServer.getConfigurationContext().getAxisConfiguration().engageModule(
70             new QName JavaDoc("addressing"));
71
72         ServiceDescription service =
73             Utils.createSimpleService(serviceName, Echo.class.getName(), operationName);
74         UtilServer.deployService(service);
75         serviceContext =
76             UtilServer.getConfigurationContext().createServiceContext(service.getName());
77
78     }
79
80     protected void tearDown() throws Exception JavaDoc {
81         UtilServer.unDeployService(serviceName);
82         UtilServer.stop();
83     }
84
85  
86
87     public void testEchoXMLCompleteSync() throws Exception JavaDoc {
88         ServiceDescription service =
89             Utils.createSimpleService(
90                 serviceName,
91         Echo.class.getName(),
92                 operationName);
93
94         ServiceContext serviceContext = UtilServer.createAdressedEnabledClientSide(service);
95
96         OMFactory fac = OMAbstractFactory.getOMFactory();
97
98         OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
99         OMElement method = fac.createOMElement("echoOMElement", omNs);
100         OMElement value = fac.createOMElement("myValue", omNs);
101         value.setText("Isaac Assimov, the foundation Sega");
102         method.addChild(value);
103
104         org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(serviceContext);
105         call.setTo(targetEPR);
106         call.engageModule(new QName JavaDoc(Constants.MODULE_ADDRESSING));
107         call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);
108
109         OMElement result = (OMElement) call.invokeBlocking(operationName.getLocalPart(), method);
110         TestingUtils.campareWithCreatedOMElement(result);
111         call.close();
112
113     }
114
115 }
116
Popular Tags