KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > client > HttpConnectionFactory


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

17 package org.openejb.client;
18
19 import java.util.Properties JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.net.HttpURLConnection JavaDoc;
24 import java.net.URL JavaDoc;
25
26 /**
27  * @version $Revision$ $Date$
28  */

29 public class HttpConnectionFactory implements ConnectionFactory {
30
31     public void init(Properties JavaDoc props) {
32     }
33
34     public Connection getConnection(ServerMetaData server) throws IOException JavaDoc {
35         return new HttpConnection(server);
36     }
37
38     public static class HttpConnection implements Connection {
39
40         private final ServerMetaData server;
41         private HttpURLConnection JavaDoc httpURLConnection;
42
43         public HttpConnection(ServerMetaData server) throws IOException JavaDoc {
44             this.server = server;
45             String JavaDoc host = "localhost";
46 // String host = server.getLocation().getHost();
47
// TODO: Use the URI for making the URL
48
URL JavaDoc url = server.getLocation().toURL();
49             httpURLConnection = (HttpURLConnection JavaDoc)url.openConnection();
50             httpURLConnection.setRequestProperty("Content-Type","application/ejb");
51             httpURLConnection.setDoOutput(true);
52             httpURLConnection.setRequestProperty("Content-Type","application/ejb");
53             httpURLConnection.connect();
54         }
55
56         public void close() throws IOException JavaDoc {
57             httpURLConnection.disconnect();
58         }
59
60         public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
61             return httpURLConnection.getInputStream();
62         }
63
64         public OutputStream JavaDoc getOuputStream() throws IOException JavaDoc {
65             return httpURLConnection.getOutputStream();
66         }
67     }
68 }
69
Popular Tags