01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
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: */package org.apache.openejb.client;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.io.OutputStream;
22: import java.net.HttpURLConnection;
23: import java.net.URI;
24: import java.net.URL;
25: import java.util.Properties;
26:
27: /**
28: * @version $Revision: 489459 $ $Date: 2006-12-21 13:02:29 -0800 $
29: */
30: public class HttpConnectionFactory implements ConnectionFactory {
31:
32: public void init(Properties props) {
33: }
34:
35: public Connection getConnection(URI uri) throws IOException {
36: return new HttpConnection(uri);
37: }
38:
39: public static class HttpConnection implements Connection {
40:
41: private HttpURLConnection httpURLConnection;
42:
43: public HttpConnection(URI uri) throws IOException {
44: String host = "localhost";
45: // String host = server.getLocation().getHost();
46: // TODO: Use the URI for making the URL
47: URL url = uri.toURL();
48: httpURLConnection = (HttpURLConnection) url
49: .openConnection();
50: httpURLConnection.setDoOutput(true);
51: httpURLConnection.connect();
52: }
53:
54: public void close() throws IOException {
55: httpURLConnection.disconnect();
56: }
57:
58: public InputStream getInputStream() throws IOException {
59: return httpURLConnection.getInputStream();
60: }
61:
62: public OutputStream getOuputStream() throws IOException {
63: return httpURLConnection.getOutputStream();
64: }
65: }
66: }
|