You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by wo...@apache.org on 2010/09/09 18:56:18 UTC
svn commit: r995492 - in
/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src:
main/java/org/apache/jetspeed/container/invoker/
test/java/org/apache/jetspeed/container/invoker/
Author: woonsan
Date: Thu Sep 9 16:56:18 2010
New Revision: 995492
URL: http://svn.apache.org/viewvc?rev=995492&view=rev
Log:
Simplifying properties of concurrent container request/response unwrapper component.
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/invoker/ConcurrentContainerRequestResponseUnwrapper.java
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/invoker/TestConcurrentContainerRequestResponseUnwrapper.java
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/invoker/ConcurrentContainerRequestResponseUnwrapper.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/invoker/ConcurrentContainerRequestResponseUnwrapper.java?rev=995492&r1=995491&r2=995492&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/invoker/ConcurrentContainerRequestResponseUnwrapper.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/invoker/ConcurrentContainerRequestResponseUnwrapper.java Thu Sep 9 16:56:18 2010
@@ -16,6 +16,9 @@
*/
package org.apache.jetspeed.container.invoker;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
@@ -91,6 +94,27 @@ public class ConcurrentContainerRequestR
request = ((HttpServletRequestWrapper) request).getRequest();
}
+ if (proxySuperClass == null)
+ {
+ proxySuperClass = request.getClass();
+ }
+
+ if (proxyConstructorArgTypes == null)
+ {
+ Constructor<?> constructor = findAccessibleConstructor(proxySuperClass);
+ proxyConstructorArgTypes = constructor.getParameterTypes();
+
+ if (proxyConstructorArgTypes == null)
+ {
+ proxyConstructorArgTypes = new Class<?>[0];
+ }
+ }
+
+ if (proxyConstructorArgs == null)
+ {
+ proxyConstructorArgs = new Object[proxyConstructorArgTypes.length];
+ }
+
if (enhancer == null)
{
ConcurrentRequestMethodInterceptor interceptor = new ConcurrentRequestMethodInterceptor(request);
@@ -101,7 +125,7 @@ public class ConcurrentContainerRequestR
}
enhancer = new Enhancer();
- enhancer.setSuperclass(proxySuperClass != null ? proxySuperClass : request.getClass());
+ enhancer.setSuperclass(proxySuperClass);
enhancer.setStrategy(new UndeclaredThrowableStrategy(UndeclaredThrowableException.class));
enhancer.setInterceptDuringConstruction(false);
enhancer.setCallback(interceptor);
@@ -128,4 +152,44 @@ public class ConcurrentContainerRequestR
return containerResponse;
}
+
+ private Constructor<?> findAccessibleConstructor(Class<?> clazz)
+ {
+ Constructor<?> constructor = null;
+
+ try
+ {
+ Constructor<?> defaultConstructor = clazz.getDeclaredConstructor(new Class<?>[0]);
+
+ if (Modifier.PUBLIC == (Modifier.PUBLIC & defaultConstructor.getModifiers()))
+ {
+ constructor = defaultConstructor;
+ }
+ }
+ catch (Throwable ignore)
+ {
+ }
+
+ if (constructor == null)
+ {
+ try
+ {
+ Constructor<?>[] constructors = clazz.getDeclaredConstructors();
+
+ for (Constructor<?> c : constructors)
+ {
+ if (Modifier.PUBLIC == (Modifier.PUBLIC & c.getModifiers()))
+ {
+ constructor = c;
+ break;
+ }
+ }
+ }
+ catch (Throwable ignore)
+ {
+ }
+ }
+
+ return constructor;
+ }
}
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/invoker/TestConcurrentContainerRequestResponseUnwrapper.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/invoker/TestConcurrentContainerRequestResponseUnwrapper.java?rev=995492&r1=995491&r2=995492&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/invoker/TestConcurrentContainerRequestResponseUnwrapper.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/container/invoker/TestConcurrentContainerRequestResponseUnwrapper.java Thu Sep 9 16:56:18 2010
@@ -16,14 +16,9 @@
*/
package org.apache.jetspeed.container.invoker;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
import junit.framework.TestCase;
-import net.sf.cglib.proxy.Enhancer;
-import net.sf.cglib.proxy.UndeclaredThrowableException;
-import net.sf.cglib.transform.impl.UndeclaredThrowableStrategy;
+
+import com.mockrunner.mock.web.MockHttpServletRequest;
/**
* TestConcurrentContainerRequestResponseUnwrapper
@@ -31,35 +26,29 @@ import net.sf.cglib.transform.impl.Undec
*/
public class TestConcurrentContainerRequestResponseUnwrapper extends TestCase
{
- private Enhancer enhancer;
- private ConcurrentRequest concurrentRequest;
+ private ContainerRequestResponseUnwrapper unwrapper;
public void setUp() throws Exception
{
super.setUp();
- concurrentRequest = new ConcurrentRequest(null);
-
- ConcurrentRequestMethodInterceptor interceptor = new ConcurrentRequestMethodInterceptor(concurrentRequest);
- interceptor.setAttributableProperties(new String [] { "dispatcherContext" });
+ ConcurrentContainerRequestResponseUnwrapper unwrapperImpl = new ConcurrentContainerRequestResponseUnwrapper();
+ unwrapperImpl.setAttributableProperties(new String [] { "dispatcherContext" });
- enhancer = new Enhancer();
- enhancer.setSuperclass(ConcurrentRequest.class);
- enhancer.setStrategy(new UndeclaredThrowableStrategy(UndeclaredThrowableException.class));
- enhancer.setInterceptDuringConstruction(false);
- enhancer.setCallback(interceptor);
-
- concurrentRequest = (ConcurrentRequest) enhancer.create(new Class[] { ConcurrentRequest.class }, new Object[] { null });
+ unwrapper = unwrapperImpl;
}
public void testThreadSafety() throws Exception
{
+ MockConcurrentRequest containerConcurrentRequest = new MockConcurrentRequest(null);
+ MockConcurrentRequest adjustedConcurrentRequest = (MockConcurrentRequest) unwrapper.unwrapContainerRequest(containerConcurrentRequest);
+
int workerCount = 40;
Worker[] workers = new Worker[workerCount];
for (int i = 0; i < workerCount; i++)
{
- workers[i] = new Worker("Worker-" + i, concurrentRequest, "Portlet-" + i, new Object());
+ workers[i] = new Worker("Worker-" + i, adjustedConcurrentRequest, "Portlet-" + i, new Object());
}
for (int i = 0; i < workerCount; i++)
@@ -85,13 +74,13 @@ public class TestConcurrentContainerRequ
private static class Worker extends Thread
{
- private final ConcurrentRequest concurrentRequest;
+ private final MockConcurrentRequest concurrentRequest;
private final String orginalPortletName;
private String currentPortletName;
private final Object originalWebAppDispatcherContext;
private Object currentWebAppDispatcherContext;
- private Worker(String name, final ConcurrentRequest concurrentRequest, final String orginalPortletName, final Object originalWebAppDispatcherContext)
+ private Worker(String name, final MockConcurrentRequest concurrentRequest, final String orginalPortletName, final Object originalWebAppDispatcherContext)
{
super(name);
this.concurrentRequest = concurrentRequest;
@@ -137,24 +126,13 @@ public class TestConcurrentContainerRequ
}
}
- public static class ConcurrentRequest
+ public static class MockConcurrentRequest extends MockHttpServletRequest
{
- private Map<String, Object> attributes;
private Object dispatcherContext;
- public ConcurrentRequest(ConcurrentRequest parent)
- {
- this.attributes = Collections.synchronizedMap(new HashMap<String, Object>());
- }
-
- public void setAttribute(String s, Object obj)
- {
- attributes.put(s, obj);
- }
-
- public Object getAttribute(String s)
+ public MockConcurrentRequest(MockConcurrentRequest parent)
{
- return attributes.get(s);
+ super();
}
public void setDispatcherContext(Object dispatcherContext)
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org