KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > rest > HttpGetRESTBasedTest


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.rest;
18
19 //todo
20

21 import junit.framework.TestCase;
22 import org.apache.axis2.description.ServiceDescription;
23 import org.apache.axis2.engine.Echo;
24 import org.apache.axis2.integration.UtilServer;
25 import org.apache.axis2.util.Utils;
26
27 import javax.xml.namespace.QName JavaDoc;
28 import java.io.BufferedReader JavaDoc;
29 import java.io.InputStreamReader JavaDoc;
30 import java.net.HttpURLConnection JavaDoc;
31 import java.net.URL JavaDoc;
32
33 public class HttpGetRESTBasedTest extends TestCase {
34     private QName JavaDoc serviceName = new QName JavaDoc("EchoXMLService");
35     private QName JavaDoc operationName = new QName JavaDoc("echoOMElement");
36
37
38     public HttpGetRESTBasedTest() {
39         super(HttpGetRESTBasedTest.class.getName());
40     }
41
42     public HttpGetRESTBasedTest(String JavaDoc testName) {
43         super(testName);
44     }
45
46     protected void setUp() throws Exception JavaDoc {
47        UtilServer.start();
48        
49        ServiceDescription service =
50                        Utils.createSimpleService(serviceName,Echo.class.getName(),operationName);
51                UtilServer.deployService(service);
52
53     }
54
55     protected void tearDown() throws Exception JavaDoc {
56         UtilServer.unDeployService(serviceName);
57        UtilServer.stop();
58     }
59
60     public void testEchoXMLSync() throws Exception JavaDoc {
61         //TODO support the GET with the Simple Axis Server and enable this test case
62
URL JavaDoc wsdlrequestUrl =
63             new URL JavaDoc("http://127.0.0.1:5555/axis2/services/EchoXMLService/echoOMElement?value1=value1,value2=value2");
64
65         HttpURLConnection JavaDoc connection = (HttpURLConnection JavaDoc) wsdlrequestUrl.openConnection();
66         BufferedReader JavaDoc reader =
67             new BufferedReader JavaDoc(new InputStreamReader JavaDoc(connection.getInputStream()));
68         connection.getResponseCode();
69         String JavaDoc line = reader.readLine();
70         while (line != null) {
71             System.out.println(line);
72             line = reader.readLine();
73         }
74     }
75
76 }
77
Popular Tags