Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--VERSION.txt2
-rw-r--r--example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java10
-rw-r--r--jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java61
-rw-r--r--jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java5
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java26
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/AbstractHandlerMBean.java85
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/ContextHandlerMBean.java19
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/session/jmx/AbstractSessionManagerMBean.java56
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/jmx/FilterMappingMBean.java42
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/jmx/ServletMappingMBean.java42
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java37
-rw-r--r--jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java4
-rw-r--r--jetty-webapp/src/main/java/org/eclipse/jetty/webapp/jmx/WebAppContextMBean.java43
13 files changed, 349 insertions, 83 deletions
diff --git a/VERSION.txt b/VERSION.txt
index 6e454f9fac..718c904090 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -1,6 +1,6 @@
jetty-7.4.1-SNAPSHOT
+ 288563 remove unsupported and deprecated --secure option
- + 332907 (work in progress) Added AbstractHandlerContainer.findContainerOf
+ + 332907 Add context property to ObjectName of JMX MBeans
+ 336056 Ability to override the computation of the ContextHandler to deploy the DefaultServlet on the HttpService
+ 340040 Support for a total timeout
+ 343083 Set nested dispatch type and connection
diff --git a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java
index abb0a0109a..a893c21a34 100644
--- a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java
+++ b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java
@@ -15,11 +15,15 @@ package org.eclipse.jetty.embedded;
+import java.lang.management.ManagementFactory;
+
+import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.util.log.Log;
public class ManyServletContexts
{
@@ -27,6 +31,12 @@ public class ManyServletContexts
{
Server server = new Server(8080);
+ // Setup JMX
+ MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
+ server.getContainer().addEventListener(mbContainer);
+ server.addBean(mbContainer);
+ mbContainer.addBean(Log.getLog());
+
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java
index 672f2192e5..419d7b9acf 100644
--- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java
+++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java
@@ -232,29 +232,32 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste
if (dot >= 0)
type = type.substring(dot + 1);
- String name = null;
+ String context = null;
if (mbean instanceof ObjectMBean)
{
- name = ((ObjectMBean)mbean).getObjectNameBasis();
- if (name != null)
- {
- name = name.replace('\\', '/');
- if (name.endsWith("/"))
- name = name.substring(0, name.length() - 1);
-
- int slash = name.lastIndexOf('/', name.length() - 1);
- if (slash > 0)
- name = name.substring(slash + 1);
- dot = name.lastIndexOf('.');
- if (dot > 0)
- name = name.substring(0, dot);
-
- name = name.replace(':', '_').replace('*', '_').replace('?', '_').replace('=', '_').replace(',', '_').replace(' ', '_');
- }
+ context = makeName(((ObjectMBean)mbean).getObjectContextBasis());
}
- String basis = (name != null && name.length() > 1) ? ("type=" + type + ",name=" + name) : ("type=" + type);
+ String name = null;
+ if (mbean instanceof ObjectMBean)
+ {
+ name = makeName(((ObjectMBean)mbean).getObjectNameBasis());
+ }
+ StringBuffer buf = new StringBuffer();
+ buf.append("type=").append(type);
+ if (context != null && context.length()>1)
+ {
+ buf.append(buf.length()>0 ? ",":"");
+ buf.append("context=").append(context);
+ }
+ if (name != null && name.length()>1)
+ {
+ buf.append(buf.length()>0 ? ",":"");
+ buf.append("name=").append(name);
+ }
+
+ String basis = buf.toString();
Integer count = _unique.get(basis);
count = count == null ? 0 : 1 + count;
_unique.put(basis, count);
@@ -278,6 +281,28 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste
}
}
+ public String makeName(String basis)
+ {
+ String name = basis;
+ if (name != null)
+ {
+ name = name.replace('\\', '/');
+ if (name.endsWith("/"))
+ name = name.substring(0, name.length() - 1);
+
+ int slash = name.lastIndexOf('/', name.length() - 1);
+ if (slash > 0)
+ name = name.substring(slash + 1);
+ int dot = name.lastIndexOf('.');
+ if (dot > 0)
+ name = name.substring(0, dot);
+
+ name = name.replace(':', '_').replace('*', '_').replace('?', '_').replace('=', '_').replace(',', '_').replace(' ', '_');
+ }
+
+ return name;
+ }
+
/**
* Perform actions needed to start lifecycle
*
diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java
index dd3efe5343..31a8986c86 100644
--- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java
+++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java
@@ -182,6 +182,11 @@ public class ObjectMBean implements DynamicMBean
return null;
}
+ public String getObjectContextBasis()
+ {
+ return null;
+ }
+
public String getObjectNameBasis()
{
return null;
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
index 7fa375521b..1ff9ef338e 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
@@ -1440,8 +1440,28 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
return Collections.emptySet();
}
-
-
+ /* ------------------------------------------------------------ */
+ public String getName()
+ {
+ if (_displayName != null)
+ return _displayName;
+
+ if (_baseResource != null && _baseResource.getName().length() > 1)
+ return _baseResource.getName();
+
+ if (_contextPath != null && _contextPath.length() > 0)
+ {
+ int idx = _contextPath.lastIndexOf(File.separator);
+ String basis = idx < 0 ? _contextPath : _contextPath.substring(++idx);
+ if (basis.isEmpty())
+ return "[root]";
+ else
+ return basis;
+ }
+
+ return null;
+ }
+
/* ------------------------------------------------------------ */
private String normalizeHostname( String host )
{
@@ -1453,7 +1473,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
return host;
}
-
+
/* ------------------------------------------------------------ */
/** Context.
* <p>
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/AbstractHandlerMBean.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/AbstractHandlerMBean.java
new file mode 100644
index 0000000000..ea9d5958d9
--- /dev/null
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/AbstractHandlerMBean.java
@@ -0,0 +1,85 @@
+//========================================================================
+//Copyright (c) Webtide LLC
+//------------------------------------------------------------------------
+//All rights reserved. This program and the accompanying materials
+//are made available under the terms of the Eclipse Public License v1.0
+//and Apache License v2.0 which accompanies this distribution.
+//
+//The Eclipse Public License is available at
+//http://www.eclipse.org/legal/epl-v10.html
+//
+//The Apache License v2.0 is available at
+//http://www.apache.org/licenses/LICENSE-2.0.txt
+//
+//You may elect to redistribute this code under either of these licenses.
+//========================================================================
+
+package org.eclipse.jetty.server.handler.jmx;
+
+import java.io.File;
+
+import org.eclipse.jetty.jmx.ObjectMBean;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.util.resource.Resource;
+
+public class AbstractHandlerMBean extends ObjectMBean
+{
+ public AbstractHandlerMBean(Object managedObject)
+ {
+ super(managedObject);
+ }
+
+ /* ------------------------------------------------------------ */
+ @Override
+ public String getObjectContextBasis()
+ {
+ if (_managed != null )
+ {
+ String basis = null;
+ if (_managed instanceof ContextHandler)
+ {
+ return null;
+ }
+ else if (_managed instanceof AbstractHandler)
+ {
+ AbstractHandler handler = (AbstractHandler)_managed;
+ Server server = handler.getServer();
+ if (server != null)
+ {
+ ContextHandler context =
+ AbstractHandlerContainer.findContainerOf(server,
+ ContextHandler.class, handler);
+
+ if (context != null)
+ basis = context.getName();
+ }
+ }
+ if (basis != null)
+ return basis;
+ }
+ return super.getObjectContextBasis();
+ }
+
+ /* ------------------------------------------------------------ */
+ @Override
+ public String getObjectNameBasis()
+ {
+ if (_managed != null )
+ {
+ String name = null;
+ if (_managed instanceof ContextHandler)
+ {
+ ContextHandler context = (ContextHandler)_managed;
+ name = context.getName();
+ }
+
+ if (name != null)
+ return name;
+ }
+
+ return super.getObjectNameBasis();
+ }
+}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/ContextHandlerMBean.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/ContextHandlerMBean.java
index 76dbe9baee..fd06c1b71d 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/ContextHandlerMBean.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/jmx/ContextHandlerMBean.java
@@ -17,33 +17,16 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.jetty.jmx.ObjectMBean;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.Attributes;
-public class ContextHandlerMBean extends ObjectMBean
+public class ContextHandlerMBean extends AbstractHandlerMBean
{
public ContextHandlerMBean(Object managedObject)
{
super(managedObject);
}
- /* ------------------------------------------------------------ */
- public String getObjectNameBasis()
- {
- if (_managed!=null && _managed instanceof ContextHandler)
- {
- ContextHandler context = (ContextHandler)_managed;
- String name = context.getDisplayName();
- if (name!=null)
- return name;
-
- if (context.getBaseResource()!=null && context.getBaseResource().getName().length()>1)
- return context.getBaseResource().getName();
- }
- return super.getObjectNameBasis();
- }
-
public Map getContextAttributes()
{
Map map = new HashMap();
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/jmx/AbstractSessionManagerMBean.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/jmx/AbstractSessionManagerMBean.java
new file mode 100644
index 0000000000..c302ead8e8
--- /dev/null
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/jmx/AbstractSessionManagerMBean.java
@@ -0,0 +1,56 @@
+//========================================================================
+//Copyright (c) Webtide LLC
+//------------------------------------------------------------------------
+//All rights reserved. This program and the accompanying materials
+//are made available under the terms of the Eclipse Public License v1.0
+//and Apache License v2.0 which accompanies this distribution.
+//
+//The Eclipse Public License is available at
+//http://www.eclipse.org/legal/epl-v10.html
+//
+//The Apache License v2.0 is available at
+//http://www.apache.org/licenses/LICENSE-2.0.txt
+//
+//You may elect to redistribute this code under either of these licenses.
+//========================================================================
+
+package org.eclipse.jetty.server.session.jmx;
+
+import org.eclipse.jetty.jmx.ObjectMBean;
+import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.session.AbstractSessionManager;
+import org.eclipse.jetty.server.session.SessionHandler;
+
+public class AbstractSessionManagerMBean extends ObjectMBean
+{
+ public AbstractSessionManagerMBean(Object managedObject)
+ {
+ super(managedObject);
+ }
+
+ /* ------------------------------------------------------------ */
+ public String getObjectContextBasis()
+ {
+ if (_managed != null && _managed instanceof AbstractSessionManager)
+ {
+ AbstractSessionManager manager = (AbstractSessionManager)_managed;
+
+ String basis = null;
+ SessionHandler handler = manager.getSessionHandler();
+ if (handler != null)
+ {
+ ContextHandler context =
+ AbstractHandlerContainer.findContainerOf(handler.getServer(),
+ ContextHandler.class,
+ handler);
+ if (context != null)
+ basis = context.getName();
+ }
+
+ if (basis != null)
+ return basis;
+ }
+ return super.getObjectContextBasis();
+ }
+}
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/jmx/FilterMappingMBean.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/jmx/FilterMappingMBean.java
new file mode 100644
index 0000000000..1c37300ba2
--- /dev/null
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/jmx/FilterMappingMBean.java
@@ -0,0 +1,42 @@
+//========================================================================
+//Copyright (c) Webtide LLC
+//------------------------------------------------------------------------
+//All rights reserved. This program and the accompanying materials
+//are made available under the terms of the Eclipse Public License v1.0
+//and Apache License v2.0 which accompanies this distribution.
+//
+//The Eclipse Public License is available at
+//http://www.eclipse.org/legal/epl-v10.html
+//
+//The Apache License v2.0 is available at
+//http://www.apache.org/licenses/LICENSE-2.0.txt
+//
+//You may elect to redistribute this code under either of these licenses.
+//========================================================================
+
+package org.eclipse.jetty.servlet.jmx;
+
+import org.eclipse.jetty.jmx.ObjectMBean;
+import org.eclipse.jetty.servlet.FilterMapping;
+
+public class FilterMappingMBean extends ObjectMBean
+{
+
+ public FilterMappingMBean(Object managedObject)
+ {
+ super(managedObject);
+ }
+
+ public String getObjectNameBasis()
+ {
+ if (_managed != null && _managed instanceof FilterMapping)
+ {
+ FilterMapping mapping = (FilterMapping)_managed;
+ String name = mapping.getFilterName();
+ if (name != null)
+ return name;
+ }
+
+ return super.getObjectNameBasis();
+ }
+}
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/jmx/ServletMappingMBean.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/jmx/ServletMappingMBean.java
new file mode 100644
index 0000000000..76e4594eb1
--- /dev/null
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/jmx/ServletMappingMBean.java
@@ -0,0 +1,42 @@
+//========================================================================
+//Copyright (c) Webtide LLC
+//------------------------------------------------------------------------
+//All rights reserved. This program and the accompanying materials
+//are made available under the terms of the Eclipse Public License v1.0
+//and Apache License v2.0 which accompanies this distribution.
+//
+//The Eclipse Public License is available at
+//http://www.eclipse.org/legal/epl-v10.html
+//
+//The Apache License v2.0 is available at
+//http://www.apache.org/licenses/LICENSE-2.0.txt
+//
+//You may elect to redistribute this code under either of these licenses.
+//========================================================================
+
+package org.eclipse.jetty.servlet.jmx;
+
+import org.eclipse.jetty.jmx.ObjectMBean;
+import org.eclipse.jetty.servlet.ServletMapping;
+
+public class ServletMappingMBean extends ObjectMBean
+{
+
+ public ServletMappingMBean(Object managedObject)
+ {
+ super(managedObject);
+ }
+
+ public String getObjectNameBasis()
+ {
+ if (_managed != null && _managed instanceof ServletMapping)
+ {
+ ServletMapping mapping = (ServletMapping)_managed;
+ String name = mapping.getServletName();
+ if (name != null)
+ return name;
+ }
+
+ return super.getObjectNameBasis();
+ }
+}
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java
new file mode 100644
index 0000000000..9d9e4a3dfb
--- /dev/null
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java
@@ -0,0 +1,37 @@
+package org.eclipse.jetty.servlet;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.security.SecurityHandler;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
+import org.eclipse.jetty.server.session.SessionHandler;
+import org.junit.Test;
+
+public class ServletContextHandlerTest
+{
+
+ @Test
+ public void testFindContainer() throws Exception
+ {
+ Server server = new Server();
+
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ server.setHandler(contexts);
+
+ ServletContextHandler root = new ServletContextHandler(contexts,"/",ServletContextHandler.SESSIONS);
+
+ SessionHandler session = root.getSessionHandler();
+ ServletHandler servlet = root.getServletHandler();
+ SecurityHandler security = new ConstraintSecurityHandler();
+ root.setSecurityHandler(security);
+ server.start();
+
+ assertEquals(root, AbstractHandlerContainer.findContainerOf(server, ContextHandler.class, session));
+ assertEquals(root, AbstractHandlerContainer.findContainerOf(server, ContextHandler.class, security));
+ assertEquals(root, AbstractHandlerContainer.findContainerOf(server, ContextHandler.class, servlet));
+ }
+}
diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java
index c215e6f152..deb2992431 100644
--- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java
+++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java
@@ -1184,6 +1184,10 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
return _throwUnavailableOnStartupException;
}
+ public String getName()
+ {
+ return getWar();
+ }
/* ------------------------------------------------------------ */
@Override
diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/jmx/WebAppContextMBean.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/jmx/WebAppContextMBean.java
deleted file mode 100644
index 7af1a05ce1..0000000000
--- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/jmx/WebAppContextMBean.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// ========================================================================
-// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.webapp.jmx;
-
-import org.eclipse.jetty.server.handler.jmx.ContextHandlerMBean;
-import org.eclipse.jetty.webapp.WebAppContext;
-
-public class WebAppContextMBean extends ContextHandlerMBean
-{
-
- public WebAppContextMBean(Object managedObject)
- {
- super(managedObject);
- }
-
- /* ------------------------------------------------------------ */
- public String getObjectNameBasis()
- {
- String basis = super.getObjectNameBasis();
- if (basis!=null)
- return basis;
-
- if (_managed!=null && _managed instanceof WebAppContext)
- {
- WebAppContext context = (WebAppContext)_managed;
- String name = context.getWar();
- if (name!=null)
- return name;
- }
- return null;
- }
-}

Back to the top