You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2006/09/22 10:27:24 UTC
svn commit: r448862 - in
/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6:
./ handler/
Author: djencks
Date: Fri Sep 22 01:27:23 2006
New Revision: 448862
URL: http://svn.apache.org/viewvc?view=rev&rev=448862
Log:
jump through some extremely convoluted hoops to outwit jetty's mixing of lifecycle and containment management methods. jndi almost works
Added:
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java (with props)
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/LifecycleCommand.java (with props)
Modified:
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/AbstractImmutableHandler.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ComponentContextHandler.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/InstanceContextHandler.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ThreadClassloaderHandler.java
Added: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java?view=auto&rev=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java (added)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java Fri Sep 22 01:27:23 2006
@@ -0,0 +1,74 @@
+/*
+ * 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.geronimo.jetty6;
+
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.apache.geronimo.jetty6.handler.AbstractImmutableHandler;
+import org.apache.geronimo.jetty6.handler.LifecycleCommand;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class InternalJettyServletHolder extends ServletHolder {
+
+ private final AbstractImmutableHandler lifecycleChain;
+
+ public InternalJettyServletHolder(AbstractImmutableHandler lifecycleChain) {
+ this.lifecycleChain = lifecycleChain;
+ }
+
+ public void doStart() throws Exception {
+ LifecycleCommand lifecycleCommand = new StartCommand();
+ lifecycleChain.lifecycleCommand(lifecycleCommand);
+ }
+
+ public void doStop() {
+ LifecycleCommand lifecycleCommand = new StopCommand();
+ try {
+ lifecycleChain.lifecycleCommand(lifecycleCommand);
+ } catch (Exception e) {
+ //ignore????
+ }
+ }
+
+ private void internalDoStart() throws Exception {
+ super.doStart();
+ }
+
+ private void internalDoStop() {
+ super.doStop();
+ }
+
+ public class StartCommand implements LifecycleCommand {
+
+ public void lifecycleMethod() throws Exception {
+ internalDoStart();
+ }
+ }
+
+ public class StopCommand implements LifecycleCommand {
+
+ public void lifecycleMethod() throws Exception {
+ internalDoStop();
+ }
+ }
+
+}
Propchange: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java?view=diff&rev=448862&r1=448861&r2=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java (original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java Fri Sep 22 01:27:23 2006
@@ -50,15 +50,17 @@
private static final ThreadLocal currentServletName = new ThreadLocal();
+ private final JettyServletRegistration servletRegistration;
private final ServletHolder servletHolder;
private final Subject runAsSubject;
private final String objectName;
//todo consider interface instead of this constructor for endpoint use.
public JettyServletHolder() {
- this.servletHolder = null;
- this.objectName = null;
- this.runAsSubject = null;
+ servletRegistration = null;
+ servletHolder = null;
+ objectName = null;
+ runAsSubject = null;
}
public JettyServletHolder(String objectName,
@@ -70,7 +72,8 @@
Set servletMappings,
Subject runAsSubject,
JettyServletRegistration context) throws Exception {
- servletHolder = new ServletHolder();
+ servletRegistration = context;
+ servletHolder = new InternalJettyServletHolder(context == null? null: context.getLifecycleChain());
servletHolder.setName(servletName);
servletHolder.setClassName(servletClassName);
//context will be null only for use as "default servlet info holder" in deployer.
@@ -146,11 +149,12 @@
}
public void doStart() throws Exception {
- servletHolder.start();
+ //start actually handled in constructor
+// servletHolder.start();
}
public void doStop() throws Exception {
- servletHolder.stop();
+ servletRegistration.unregisterServletHolder(servletHolder, servletHolder.getName(), null, objectName);
}
public void doFail() {
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java?view=diff&rev=448862&r1=448861&r2=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java (original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java Fri Sep 22 01:27:23 2006
@@ -20,6 +20,7 @@
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder;
+import org.apache.geronimo.jetty6.handler.AbstractImmutableHandler;
/**
* @version $Rev$ $Date$
@@ -27,9 +28,12 @@
public interface JettyServletRegistration {
void registerServletHolder(ServletHolder servletHolder, String servletName, Set servletMappings, String objectName) throws Exception;
+ void unregisterServletHolder(ServletHolder servletHolder, String servletName, Set servletMappings, String objectName) throws Exception;
ServletHandler getServletHandler();
ClassLoader getWebClassLoader();
+
+ AbstractImmutableHandler getLifecycleChain();
}
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java?view=diff&rev=448862&r1=448861&r2=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java (original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java Fri Sep 22 01:27:23 2006
@@ -46,6 +46,8 @@
import org.apache.geronimo.jetty6.handler.InstanceContextHandler;
import org.apache.geronimo.jetty6.handler.JettySecurityHandler;
import org.apache.geronimo.jetty6.handler.ThreadClassloaderHandler;
+import org.apache.geronimo.jetty6.handler.LifecycleCommand;
+import org.apache.geronimo.jetty6.handler.AbstractImmutableHandler;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.ObjectNameUtil;
import org.apache.geronimo.management.J2EEApplication;
@@ -88,6 +90,7 @@
private final String objectName;
private final WebAppContext webAppContext;//delegate
+ private final AbstractImmutableHandler lifecycleChain;
private final Set servletNames = new HashSet();
@@ -106,6 +109,7 @@
objectName = null;
configurationBaseURL = null;
webAppContext = null;
+ lifecycleChain = null;
}
public JettyWebAppContext(String objectName,
@@ -169,6 +173,7 @@
Context enc = EnterpriseNamingContext.createEnterpriseNamingContext(componentContext, userTransaction, kernel, classLoader);
next = new ComponentContextHandler(next, enc);
next = new InstanceContextHandler(next, unshareableResources, applicationManagedSecurityResources, trackedConnectionAssociator);
+ lifecycleChain = (AbstractImmutableHandler) next;
webAppContext.setHandler(next);
this.server = server;
@@ -283,6 +288,10 @@
return webClassLoader;
}
+ public AbstractImmutableHandler getLifecycleChain() {
+ return lifecycleChain;
+ }
+
public void doStart() throws Exception {
// reset the classsloader... jetty likes to set it to null when stopping
this.webAppContext.setClassLoader(webClassLoader);
@@ -421,7 +430,7 @@
public void registerServletHolder(ServletHolder servletHolder, String servletName, Set servletMappings, String objectName) throws Exception {
//TODO filters
- this.webAppContext.getServletHandler().addServlet(servletHolder);
+ webAppContext.getServletHandler().addServlet(servletHolder);
if (servletMappings != null) {
for (Iterator iterator = servletMappings.iterator(); iterator.hasNext();) {
String urlPattern = (String) iterator.next();
@@ -431,11 +440,32 @@
this.webAppContext.getServletHandler().addServletMapping(servletMapping);
}
}
- //most likely this is not done with correct jndi, classloader, or connection tracking
- servletHolder.start();
+// LifecycleCommand lifecycleCommand = new LifecycleCommand.StartCommand(servletHolder);
+// lifecycleChain.lifecycleCommand(lifecycleCommand);
if (objectName != null) {
synchronized (servletNames) {
servletNames.add(objectName);
+ }
+ }
+ }
+
+ public void unregisterServletHolder(ServletHolder servletHolder, String servletName, Set servletMappings, String objectName) throws Exception {
+ //no way to remove servlets
+// webAppContext.getServletHandler().removeServlet(servletHolder);
+// if (servletMappings != null) {
+// for (Iterator iterator = servletMappings.iterator(); iterator.hasNext();) {
+// String urlPattern = (String) iterator.next();
+// ServletMapping servletMapping = new ServletMapping();
+// servletMapping.setPathSpec(urlPattern);
+// servletMapping.setServletName(servletName);
+// webAppContext.getServletHandler().removeServletMapping(servletMapping);
+// }
+// }
+// LifecycleCommand lifecycleCommand = new LifecycleCommand.StopCommand(servletHolder);
+// lifecycleChain.lifecycleCommand(lifecycleCommand);
+ if (objectName != null) {
+ synchronized (servletNames) {
+ servletNames.remove(objectName);
}
}
}
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/AbstractImmutableHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/AbstractImmutableHandler.java?view=diff&rev=448862&r1=448861&r2=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/AbstractImmutableHandler.java (original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/AbstractImmutableHandler.java Fri Sep 22 01:27:23 2006
@@ -25,7 +25,7 @@
import org.mortbay.jetty.Server;
/**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
*/
public abstract class AbstractImmutableHandler extends AbstractHandler {
protected final AbstractHandler next;
@@ -45,6 +45,14 @@
public void setServer(Server server) {
super.setServer(server);
next.setServer(server);
+ }
+
+ public void lifecycleCommand(LifecycleCommand lifecycleCommand) throws Exception {
+ if (next instanceof AbstractImmutableHandler) {
+ ((AbstractImmutableHandler)next).lifecycleCommand(lifecycleCommand);
+ } else {
+ lifecycleCommand.lifecycleMethod();
+ }
}
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ComponentContextHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ComponentContextHandler.java?view=diff&rev=448862&r1=448861&r2=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ComponentContextHandler.java (original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ComponentContextHandler.java Fri Sep 22 01:27:23 2006
@@ -51,4 +51,14 @@
RootContext.setComponentContext(oldContext);
}
}
+
+ public void lifecycleCommand(LifecycleCommand lifecycleCommand) throws Exception {
+ Context oldContext = RootContext.getComponentContext();
+ try {
+ RootContext.setComponentContext(componentContext);
+ super.lifecycleCommand(lifecycleCommand);
+ } finally {
+ RootContext.setComponentContext(oldContext);
+ }
+ }
}
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/InstanceContextHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/InstanceContextHandler.java?view=diff&rev=448862&r1=448861&r2=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/InstanceContextHandler.java (original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/InstanceContextHandler.java Fri Sep 22 01:27:23 2006
@@ -63,4 +63,12 @@
}
}
+ public void lifecycleCommand(LifecycleCommand lifecycleCommand) throws Exception {
+ ConnectorInstanceContext oldContext = trackedConnectionAssociator.enter(new ConnectorInstanceContextImpl(unshareableResources, applicationManagedSecurityResources));
+ try {
+ super.lifecycleCommand(lifecycleCommand);
+ } finally {
+ trackedConnectionAssociator.exit(oldContext);
+ }
+ }
}
Added: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/LifecycleCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/LifecycleCommand.java?view=auto&rev=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/LifecycleCommand.java (added)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/LifecycleCommand.java Fri Sep 22 01:27:23 2006
@@ -0,0 +1,32 @@
+/*
+ * 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.geronimo.jetty6.handler;
+
+import org.mortbay.jetty.servlet.ServletHolder;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface LifecycleCommand {
+
+ void lifecycleMethod() throws Exception;
+
+}
Propchange: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/LifecycleCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/LifecycleCommand.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/LifecycleCommand.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ThreadClassloaderHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ThreadClassloaderHandler.java?view=diff&rev=448862&r1=448861&r2=448862
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ThreadClassloaderHandler.java (original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/ThreadClassloaderHandler.java Fri Sep 22 01:27:23 2006
@@ -51,4 +51,14 @@
}
}
+ public void lifecycleCommand(LifecycleCommand lifecycleCommand) throws Exception {
+ Thread thread = Thread.currentThread();
+ ClassLoader oldClassLoader = thread.getContextClassLoader();
+ thread.setContextClassLoader(classLoader);
+ try {
+ super.lifecycleCommand(lifecycleCommand);
+ } finally {
+ thread.setContextClassLoader(oldClassLoader);
+ }
+ }
}