aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Archer2011-10-19 17:23:10 (EDT)
committerThomas Watson2011-10-19 17:23:10 (EDT)
commit45b02f809c784e7389a7f8b901067926d3d8b620 (patch)
tree28c9314b43ce6b8eb151b5e8c220e1ceb6c6c4b4
parentbcb49f062fc476128f34aed1f6f04808a35147d7 (diff)
downloadrt.equinox.bundles-45b02f809c784e7389a7f8b901067926d3d8b620.zip
rt.equinox.bundles-45b02f809c784e7389a7f8b901067926d3d8b620.tar.gz
rt.equinox.bundles-45b02f809c784e7389a7f8b901067926d3d8b620.tar.bz2
Bug 341643 - Applied polish.
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java14
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java67
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextProxyFactory.java23
3 files changed, 56 insertions, 48 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java
index 79cfaea..49b4816 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java
@@ -170,8 +170,8 @@ public class ProxyServlet extends HttpServlet {
throw new ServletException("This servlet has already been registered."); //$NON-NLS-1$
ServletRegistration registration = new ServletRegistration(servlet, httpContext);
- ServletContext servletContextProxy = createServletContextProxy(httpContext);
- ServletConfig servletConfig = new ServletConfigImpl(servlet, initparams, servletContextProxy);
+ ServletContext servletContext = createServletContext(httpContext);
+ ServletConfig servletConfig = new ServletConfigImpl(servlet, initparams, servletContext);
boolean initialized = false;
proxyContext.createContextAttributes(httpContext);
@@ -235,8 +235,8 @@ public class ProxyServlet extends HttpServlet {
int filterPriority = findFilterPriority(initparams);
FilterRegistration registration = new FilterRegistration(filter, httpContext, alias, filterPriority);
- ServletContext servletContextProxy = createServletContextProxy(httpContext);
- FilterConfig filterConfig = new FilterConfigImpl(filter, initparams, servletContextProxy);
+ ServletContext servletContext = createServletContext(httpContext);
+ FilterConfig filterConfig = new FilterConfigImpl(filter, initparams, servletContext);
boolean initialized = false;
proxyContext.createContextAttributes(httpContext);
@@ -250,9 +250,9 @@ public class ProxyServlet extends HttpServlet {
filterRegistrations.put(filter, registration);
}
- private ServletContext createServletContextProxy(HttpContext httpContext) {
- ServletContextAdaptor handler = new ServletContextAdaptor(proxyContext, getServletContext(), httpContext, AccessController.getContext());
- return ServletContextProxyFactory.create(handler);
+ private ServletContext createServletContext(HttpContext httpContext) {
+ ServletContextAdaptor adaptor = new ServletContextAdaptor(proxyContext, getServletContext(), httpContext, AccessController.getContext());
+ return adaptor.createServletContext();
}
private int findFilterPriority(Dictionary initparams) {
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java
index 7923fde..e396885 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java
@@ -1,9 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2011 Cognos Incorporated, IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cognos Incorporated - initial API and implementation
+ * IBM Corporation - bug fixes and enhancements
+ *******************************************************************************/
package org.eclipse.equinox.http.servlet.internal;
import java.io.IOException;
import java.io.InputStream;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
+import java.lang.reflect.*;
import java.net.URL;
import java.security.*;
import java.util.*;
@@ -11,24 +21,29 @@ import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import org.osgi.service.http.HttpContext;
-public class ServletContextAdaptor implements InvocationHandler {
-
+public class ServletContextAdaptor {
private final static Map contextToHandlerMethods;
static {
+ contextToHandlerMethods = createContextToHandlerMethods();
+ }
+
+ private static Map createContextToHandlerMethods() {
Map methods = new HashMap();
- Class servletContextClazz = ServletContext.class;
- Class handlerClazz = ServletContextAdaptor.class;
- Method[] handlerMethods = handlerClazz.getDeclaredMethods();
+ Method[] handlerMethods = ServletContextAdaptor.class.getDeclaredMethods();
for (int i = 0; i < handlerMethods.length; i++) {
+ Method handlerMethod = handlerMethods[i];
+ String name = handlerMethod.getName();
+ Class[] parameterTypes = handlerMethod.getParameterTypes();
try {
- Method m = servletContextClazz.getMethod(handlerMethods[i].getName(), handlerMethods[i].getParameterTypes());
- methods.put(m, handlerMethods[i]);
+ Method method = ServletContext.class.getMethod(name, parameterTypes);
+ methods.put(method, handlerMethod);
} catch (NoSuchMethodException e) {
// do nothing
}
}
- contextToHandlerMethods = methods;
+ return methods;
}
+
final private ServletContext servletContext;
final HttpContext httpContext;
final private AccessControlContext acc;
@@ -41,6 +56,30 @@ public class ServletContextAdaptor implements InvocationHandler {
this.proxyContext = proxyContext;
}
+ public ServletContext createServletContext() {
+ Class clazz = getClass();
+ ClassLoader classLoader = clazz.getClassLoader();
+ Class[] interfaces = new Class[] {ServletContext.class};
+ InvocationHandler invocationHandler = createInvocationHandler();
+ return (ServletContext) Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
+ }
+
+ private InvocationHandler createInvocationHandler() {
+ return new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return ServletContextAdaptor.this.invoke(proxy, method, args);
+ }
+ };
+ }
+
+ private Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ Method m = (Method) contextToHandlerMethods.get(method);
+ if (m != null) {
+ return m.invoke(this, args);
+ }
+ return method.invoke(servletContext, args);
+ }
+
/**
* @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
*
@@ -120,12 +159,4 @@ public class ServletContextAdaptor implements InvocationHandler {
public RequestDispatcher getRequestDispatcher(String arg0) {
return new RequestDispatcherAdaptor(servletContext.getRequestDispatcher(proxyContext.getServletPath() + arg0));
}
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- Method m = (Method) contextToHandlerMethods.get(method);
- if (m != null) {
- return m.invoke(this, args);
- }
- return method.invoke(servletContext, args);
- }
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextProxyFactory.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextProxyFactory.java
deleted file mode 100644
index 7893c6e..0000000
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextProxyFactory.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
-
-import java.lang.reflect.Proxy;
-import javax.servlet.ServletContext;
-
-class ServletContextProxyFactory extends Object {
- private static ClassLoader cl = ServletContextProxyFactory.class.getClassLoader();
-
- static ServletContext create(ServletContextAdaptor handler) {
- if (handler == null)
- throw new IllegalArgumentException("adapter must not be null"); //$NON-NLS-1$
- Class[] interfaces = new Class[] {ServletContext.class};
- return (ServletContext) Proxy.newProxyInstance(cl, interfaces, handler);
- }
-
-}