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.server.httpd;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.io.OutputStream;
22: import java.net.Socket;
23: import java.util.Properties;
24:
25: import org.apache.openejb.loader.SystemInstance;
26: import org.apache.openejb.server.ServerService;
27: import org.apache.openejb.server.ServiceException;
28: import org.apache.openejb.server.ejbd.EjbServer;
29:
30: /**
31: * @version $Revision: 628862 $ $Date: 2008-02-18 12:37:07 -0800 $
32: */
33: public abstract class HttpEjbServer implements ServerService {
34: protected HttpServer httpServer;
35: private String name;
36:
37: public void init(Properties props) throws Exception {
38: name = props.getProperty("name");
39: EjbServer ejbServer = new EjbServer();
40: ServerServiceAdapter adapter = new ServerServiceAdapter(
41: ejbServer);
42:
43: SystemInstance systemInstance = SystemInstance.get();
44: HttpListenerRegistry registry = systemInstance
45: .getComponent(HttpListenerRegistry.class);
46: if (registry == null) {
47: registry = new HttpListenerRegistry();
48: systemInstance.setComponent(HttpListenerRegistry.class,
49: registry);
50: }
51:
52: registry.addHttpListener(adapter, "/ejb/?.*");
53:
54: // register the http server
55: systemInstance.setComponent(HttpServer.class, httpServer);
56:
57: httpServer.init(props);
58: ejbServer.init(props);
59: }
60:
61: public void service(Socket socket) throws ServiceException,
62: IOException {
63: httpServer.service(socket);
64: }
65:
66: public void service(InputStream in, OutputStream out)
67: throws ServiceException, IOException {
68: httpServer.service(in, out);
69: }
70:
71: public void start() throws ServiceException {
72: httpServer.start();
73: }
74:
75: public void stop() throws ServiceException {
76: httpServer.stop();
77: }
78:
79: public String getName() {
80: return name;
81: }
82:
83: public int getPort() {
84: return httpServer.getPort();
85: }
86:
87: public String getIP() {
88: return httpServer.getIP();
89: }
90: }
|