tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r608621 - in /openejb/trunk/openejb3/server/openejb-http/src: main/java/org/apache/openejb/server/httpd/ test/java/org/apache/openejb/server/httpd/
Date Thu, 03 Jan 2008 20:27:02 GMT
Author: dain
Date: Thu Jan  3 12:27:02 2008
New Revision: 608621

URL: http://svn.apache.org/viewvc?rev=608621&view=rev
Log:
When jetty classes are present use it instead of the OpenEJBHttpSever

Added:
    openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java
    openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
  (contents, props changed)
      - copied, changed from r608268, openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java
    openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/JettyTest.java
Modified:
    openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpEjbServer.java
    openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/JettyHttpServer.java
    openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java

Modified: openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpEjbServer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpEjbServer.java?rev=608621&r1=608620&r2=608621&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpEjbServer.java
(original)
+++ openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpEjbServer.java
Thu Jan  3 12:27:02 2008
@@ -49,7 +49,28 @@
 
         registry.addHttpListener(adapter, "/ejb/?.*");
 
-        httpServer = new HttpServer(registry);
+        // props can name an implementation
+        // if implementation is not named, use jetty if jetty classes are present; otherwise
use openejb
+        String impl = props.getProperty("impl");
+        if ("Jetty".equalsIgnoreCase(impl)) {
+            httpServer = (HttpServer) getClass().getClassLoader().loadClass("org.apache.openejb.server.httpd.JettyHttpServer").newInstance();
+        } else if ("OpenEJB".equalsIgnoreCase(impl)) {
+            httpServer = new OpenEJBHttpServer(registry);
+        } else if (impl == null) {
+            try {
+                getClass().getClassLoader().loadClass("org.mortbay.jetty.Server");
+                httpServer = (HttpServer) getClass().getClassLoader().loadClass("org.apache.openejb.server.httpd.JettyHttpServer").newInstance();
+            } catch (Exception ignored) {
+                // Jetty classes not available
+                httpServer = new OpenEJBHttpServer(registry);
+            }
+        } else {
+            throw new IllegalArgumentException("Unknown HTTP server impl '" + impl + "'.
Valid implementation are OpenEJB and Jetty.");
+        }
+
+        // register the http server
+        systemInstance.setComponent(HttpServer.class, httpServer);
+
         httpServer.init(props);
         ejbServer.init(props);
     }

Added: openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java?rev=608621&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java
(added)
+++ openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java
Thu Jan  3 12:27:02 2008
@@ -0,0 +1,24 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.server.httpd;
+
+import org.apache.openejb.server.ServerService;
+
+public interface HttpServer extends ServerService {
+    HttpListener getListener();
+}

Modified: openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/JettyHttpServer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/JettyHttpServer.java?rev=608621&r1=608620&r2=608621&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/JettyHttpServer.java
(original)
+++ openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/JettyHttpServer.java
Thu Jan  3 12:27:02 2008
@@ -17,7 +17,6 @@
 package org.apache.openejb.server.httpd;
 
 import org.apache.openejb.server.SelfManaging;
-import org.apache.openejb.server.ServerService;
 import org.apache.openejb.server.ServiceException;
 import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Handler;
@@ -40,7 +39,7 @@
 /**
  * Jetty based http server implementation
  */
-public class JettyHttpServer implements ServerService, SelfManaging {
+public class JettyHttpServer implements HttpServer, SelfManaging {
     private final HttpListener listener;
     private Server server;
     private int port;
@@ -53,6 +52,10 @@
         this.listener = listener;
     }
 
+    public HttpListener getListener() {
+        return listener;
+    }
+
     public void service(Socket socket) throws ServiceException, IOException {
         throw new UnsupportedOperationException();
     }
@@ -74,7 +77,7 @@
     }
 
     public void init(Properties props) throws Exception {
-        port = Integer.parseInt(props.getProperty("port"));
+        port = Integer.parseInt(props.getProperty("port", "8080"));
 
         // Create all the Jetty objects but dont' start them
         server = new Server();

Copied: openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
(from r608268, openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java?p2=openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java&p1=openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java&r1=608268&r2=608621&rev=608621&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpServer.java
(original)
+++ openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
Thu Jan  3 12:27:02 2008
@@ -17,7 +17,6 @@
 package org.apache.openejb.server.httpd;
 
 import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.server.ServerService;
 import org.apache.openejb.server.ServiceException;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
@@ -35,16 +34,20 @@
  *
  * @since 11/25/2001
  */
-public class HttpServer implements ServerService {
+public class OpenEJBHttpServer implements HttpServer {
     private static final Logger log = Logger.getInstance(LogCategory.HTTPSERVER, "org.apache.openejb.util.resources");
 
     private HttpListener listener;
 
-    public HttpServer() {
+    public OpenEJBHttpServer() {
     }
 
-    public HttpServer(HttpListener listener) {
+    public OpenEJBHttpServer(HttpListener listener) {
         this.listener = listener;
+    }
+
+    public HttpListener getListener() {
+        return listener;
     }
 
     public void service(Socket socket) throws ServiceException, IOException {

Propchange: openejb/trunk/openejb3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author Id Revision HeadURL

Modified: openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java?rev=608621&r1=608620&r2=608621&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java
(original)
+++ openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java
Thu Jan  3 12:27:02 2008
@@ -77,7 +77,7 @@
             try {
                 EjbServer ejbServer = new EjbServer();
                 ServerServiceAdapter adapter = new ServerServiceAdapter(ejbServer);
-                HttpServer httpServer = new HttpServer(adapter);
+                HttpServer httpServer = new OpenEJBHttpServer(adapter);
 
                 props.put("openejb.deployments.classpath", "true");
                 OpenEJB.init(props, new ServerFederation());

Added: openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/JettyTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/JettyTest.java?rev=608621&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/JettyTest.java
(added)
+++ openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/JettyTest.java
Thu Jan  3 12:27:02 2008
@@ -0,0 +1,79 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.server.httpd;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+import org.apache.openejb.core.CoreContainerSystem;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+
+public class JettyTest extends TestCase {
+    public void testJettyImpl() throws Exception {
+        SystemInstance.get().setComponent(ContainerSystem.class, new CoreContainerSystem());
+
+        Properties props = new Properties();
+        props.setProperty("impl", "Jetty");
+
+        HttpEjbServer server = new HttpEjbServer();
+        server.init(props);
+
+        assertTrue("SystemInstance.get().getComponent(HttpServer.class) should be an instance
of JettyHttpServer",
+                SystemInstance.get().getComponent(HttpServer.class) instanceof JettyHttpServer);
+    }
+
+    public void testOpenEJBImpl() throws Exception {
+        SystemInstance.get().setComponent(ContainerSystem.class, new CoreContainerSystem());
+
+        Properties props = new Properties();
+        props.setProperty("impl", "openejb");
+
+        HttpEjbServer server = new HttpEjbServer();
+        server.init(props);
+
+        assertTrue("SystemInstance.get().getComponent(HttpServer.class) should be an instance
of OpenEJBHttpServer",
+                SystemInstance.get().getComponent(HttpServer.class) instanceof OpenEJBHttpServer);
+    }
+
+    public void testJettyClassCheck() throws Exception {
+        SystemInstance.get().setComponent(ContainerSystem.class, new CoreContainerSystem());
+
+        Properties props = new Properties();
+
+        HttpEjbServer server = new HttpEjbServer();
+        server.init(props);
+
+        assertTrue("SystemInstance.get().getComponent(HttpServer.class) should be an instance
of JettyHttpServer",
+                SystemInstance.get().getComponent(HttpServer.class) instanceof JettyHttpServer);
+    }
+
+    public void testUnknownImpl() throws Exception {
+        SystemInstance.get().setComponent(ContainerSystem.class, new CoreContainerSystem());
+
+        Properties props = new Properties();
+        props.setProperty("impl", "fake");
+
+        try {
+            HttpEjbServer server = new HttpEjbServer();
+            server.init(props);
+            fail("expected IllegalArgumentException");
+        } catch (IllegalArgumentException expected) {
+        }
+    }
+}



Mime
View raw message