KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > framework > internal > orchestrator > OrchestratorClient


1 /*
2  * ========================================================================
3  *
4  * Copyright 2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.framework.internal.orchestrator;
21
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.net.HttpURLConnection JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import java.net.URL JavaDoc;
27
28 import org.apache.cactus.framework.internal.orchestrator.handlers.GetTestHandler;
29 import org.apache.cactus.framework.internal.orchestrator.handlers.SetTestHandler;
30
31 public class OrchestratorClient
32 {
33     public void setTest(String JavaDoc name)
34         throws MalformedURLException JavaDoc, IOException JavaDoc
35     {
36         // TODO: get port from configuration
37
URL JavaDoc url = new URL JavaDoc(
38             "http://localhost:7777" + SetTestHandler.PATH_IN_CONTEXT
39             + "?name=" + name);
40      
41         // TODO: use proper logging system
42
System.err.println("URL = [" + url + "]");
43         HttpURLConnection JavaDoc connection =
44             (HttpURLConnection JavaDoc) url.openConnection();
45         connection.setRequestMethod("GET");
46         connection.getInputStream();
47     }
48
49     public String JavaDoc getTest()
50         throws MalformedURLException JavaDoc, IOException JavaDoc
51     {
52         // TODO: get port from configuration
53
URL JavaDoc url = new URL JavaDoc(
54             "http://localhost:7777" + GetTestHandler.PATH_IN_CONTEXT);
55      
56         // TODO: use proper logging system
57
System.err.println("URL = [" + url + "]");
58         HttpURLConnection JavaDoc connection =
59             (HttpURLConnection JavaDoc) url.openConnection();
60         connection.setRequestMethod("GET");
61
62         InputStream JavaDoc in = connection.getInputStream();
63         byte[] b = new byte[in.available()];
64         in.read(b);
65         
66         return new String JavaDoc(b);
67     }
68
69 }
70
Popular Tags