You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/02/12 18:48:21 UTC
[1/2] tomee git commit: TOMEE-1711 unwrap http request before
initializing the HttpRequest servlet for cxf-rs
Repository: tomee
Updated Branches:
refs/heads/master fcf9c7d37 -> 4655c053b
TOMEE-1711 unwrap http request before initializing the HttpRequest servlet for cxf-rs
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/bf1b5d0d
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/bf1b5d0d
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/bf1b5d0d
Branch: refs/heads/master
Commit: bf1b5d0d95ff712035b2883bd17f442d0e7764ae
Parents: fcf9c7d
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Fri Feb 12 15:32:40 2016 +0100
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Fri Feb 12 15:32:40 2016 +0100
----------------------------------------------------------------------
.../openejb/server/cxf/rs/CxfRsHttpListener.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/bf1b5d0d/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
index f279f09..2dfd582 100644
--- a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
+++ b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
@@ -114,7 +114,9 @@ import javax.management.openmbean.TabularData;
import javax.naming.Context;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.ConstrainedTo;
import javax.ws.rs.RuntimeType;
@@ -187,10 +189,19 @@ public class CxfRsHttpListener implements RsHttpListener {
@Override
public void onMessage(final HttpRequest httpRequest, final HttpResponse httpResponse) throws Exception {
// fix the address (to manage multiple connectors)
- if (HttpRequestImpl.class.isInstance(httpRequest)) {
- final HttpRequestImpl requestImpl = HttpRequestImpl.class.cast(httpRequest);
- requestImpl.initPathFromContext((!context.startsWith("/") ? "/" : "") + context);
- requestImpl.initServletPath(servlet);
+ {
+ ServletRequest unwrapped = httpRequest;
+ while (ServletRequestAdapter.class.isInstance(unwrapped)) {
+ unwrapped = ServletRequestAdapter.class.cast(unwrapped).getRequest();
+ }
+ while (HttpServletRequestWrapper.class.isInstance(unwrapped)) {
+ unwrapped = HttpServletRequestWrapper.class.cast(unwrapped).getRequest();
+ }
+ if (HttpRequestImpl.class.isInstance(unwrapped)) {
+ final HttpRequestImpl requestImpl = HttpRequestImpl.class.cast(unwrapped);
+ requestImpl.initPathFromContext((!context.startsWith("/") ? "/" : "") + context);
+ requestImpl.initServletPath(servlet);
+ }
}
boolean matchedStatic = false;
[2/2] tomee git commit: SingleApplicationComposer rule
Posted by rm...@apache.org.
SingleApplicationComposer rule
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/4655c053
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/4655c053
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/4655c053
Branch: refs/heads/master
Commit: 4655c053b4d91046131b47c2f8c3087517e1d2a3
Parents: bf1b5d0
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Fri Feb 12 18:48:00 2016 +0100
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Fri Feb 12 18:48:00 2016 +0100
----------------------------------------------------------------------
.../SingleApplicationComposerRunner.java | 133 ++++++++++++-------
1 file changed, 83 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/4655c053/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java b/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
index 1758ec6..dcbfe9a 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
@@ -22,6 +22,9 @@ import org.apache.webbeans.inject.OWBInjector;
import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.archive.FileArchive;
import org.junit.rules.MethodRule;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runner.notification.RunListener;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
@@ -41,6 +44,34 @@ public class SingleApplicationComposerRunner extends BlockJUnit4ClassRunner {
private static final AtomicReference<Object> APP = new AtomicReference<>();
private static final AtomicReference<Thread> HOOK = new AtomicReference<>();
+ // use when you use another runner like Parameterized of JUnit
+ public static class Rule implements TestRule {
+ private final Object test;
+
+ public Rule(final Object test) {
+ this.test = test;
+ }
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ start(test.getClass());
+ composerInject(test);
+ base.evaluate();
+ }
+ };
+ }
+ }
+
+ public static class Start extends RunListener {
+ @Override
+ public void testStarted(final Description description) throws Exception {
+ start(null);
+ }
+ }
+
public static void setApp(final Object o) {
APP.set(o);
}
@@ -57,7 +88,28 @@ public class SingleApplicationComposerRunner extends BlockJUnit4ClassRunner {
public SingleApplicationComposerRunner(final Class<?> klass) throws InitializationError {
super(klass);
+ }
+
+ @Override
+ protected List<MethodRule> rules(final Object test) {
+ final List<MethodRule> rules = super.rules(test);
+ rules.add(new MethodRule() {
+ @Override
+ public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ start(getTestClass().getJavaClass());
+ composerInject(target);
+ base.evaluate();
+ }
+ };
+ }
+ });
+ return rules;
+ }
+ private static void start(final Class<?> marker) throws Exception {
if (APP.get() == null) {
final Class<?> type;
final String typeStr = System.getProperty("tomee.application-composer.application");
@@ -67,9 +119,11 @@ public class SingleApplicationComposerRunner extends BlockJUnit4ClassRunner {
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
+ } else if (marker == null) {
+ throw new IllegalArgumentException("set tomee.application-composer.application system property or add a marker to the rule or runner");
} else {
final Iterator<Class<?>> descriptors =
- new AnnotationFinder(new FileArchive(Thread.currentThread().getContextClassLoader(), jarLocation(klass)), false)
+ new AnnotationFinder(new FileArchive(Thread.currentThread().getContextClassLoader(), jarLocation(marker)), false)
.findAnnotatedClasses(Application.class).iterator();
if (!descriptors.hasNext()) {
throw new IllegalArgumentException("No descriptor class using @Application");
@@ -85,59 +139,38 @@ public class SingleApplicationComposerRunner extends BlockJUnit4ClassRunner {
throw new IllegalStateException(e);
}
}
- }
-
- @Override
- protected List<MethodRule> rules(final Object test) {
- final List<MethodRule> rules = super.rules(test);
- rules.add(new MethodRule() {
- @Override
- public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- start();
- OWBInjector.inject(WebBeansContext.currentInstance().getBeanManagerImpl(), target, null);
- composerInject(target);
- base.evaluate();
- }
-
- private void start() throws Exception {
- if (!started) {
- final Object app = APP.get();
- new ApplicationComposers(app.getClass()) {
- @Override
- public void deployApp(final Object inputTestInstance) throws Exception {
- super.deployApp(inputTestInstance);
- if (!started) {
- final ThreadContext previous = ThreadContext.getThreadContext(); // done here for logging
- final ApplicationComposers comp = this;
- final Thread hook = new Thread() {
- @Override
- public void run() {
- try {
- comp.after();
- } catch (final Exception e) {
- ThreadContext.exit(previous);
- throw new IllegalStateException(e);
- }
- }
- };
- HOOK.set(hook);
- Runtime.getRuntime().addShutdownHook(hook);
- started = true;
- }
+ if (!started) {
+ final Object app = APP.get();
+ new ApplicationComposers(app.getClass()) {
+ @Override
+ public void deployApp(final Object inputTestInstance) throws Exception {
+ super.deployApp(inputTestInstance);
+ if (!started) {
+ final ThreadContext previous = ThreadContext.getThreadContext(); // done here for logging
+ final ApplicationComposers comp = this;
+ final Thread hook = new Thread() {
+ @Override
+ public void run() {
+ try {
+ comp.after();
+ } catch (final Exception e) {
+ ThreadContext.exit(previous);
+ throw new IllegalStateException(e);
}
- }.before(app);
- }
+ }
+ };
+ HOOK.set(hook);
+ Runtime.getRuntime().addShutdownHook(hook);
+ started = true;
}
- };
- }
- });
- return rules;
+ }
+ }.before(app);
+ }
}
- private void composerInject(final Object target) throws IllegalAccessException {
+ private static void composerInject(final Object target) throws IllegalAccessException {
+ OWBInjector.inject(WebBeansContext.currentInstance().getBeanManagerImpl(), target, null);
+
final Object app = APP.get();
final Class<?> aClass = target.getClass();
for (final Field f : aClass.getDeclaredFields()) {