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/03/09 22:16:55 UTC
tomee git commit: TOMEE-1729 ensure CXF rs can set the context of the
app even if previous http layer misset it to root
Repository: tomee
Updated Branches:
refs/heads/master 93b8c6dbc -> 05a8ed134
TOMEE-1729 ensure CXF rs can set the context of the app even if previous http layer misset it to root
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/05a8ed13
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/05a8ed13
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/05a8ed13
Branch: refs/heads/master
Commit: 05a8ed1342ec682ce3ec015f67616f0153b3dea1
Parents: 93b8c6d
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Wed Mar 9 22:16:08 2016 +0100
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Wed Mar 9 22:16:08 2016 +0100
----------------------------------------------------------------------
.../openejb/server/httpd/HttpRequestImpl.java | 7 +++----
.../openejb/server/httpd/HttpRequestImplTest.java | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/05a8ed13/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
index 28a9f47..a8be406 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
@@ -1173,16 +1173,15 @@ public class HttpRequestImpl implements HttpRequest {
}
public void initPathFromContext(final String context) {
- if (!"/".equals(path)) { // already done
+ if (!"/".equals(path) && !"".equals(contextPath)) { // already done
return;
}
final String rawPath = requestRawPath();
if (context != null) {
if (context.endsWith("/")) {
- final int endIndex = context.length() - 1;
- path = rawPath.substring(endIndex, rawPath.length());
- contextPath = context.substring(0, endIndex);
+ path = rawPath.substring(0, rawPath.length());
+ contextPath = "";
} else {
path = rawPath.substring(context.length(), rawPath.length());
contextPath = context;
http://git-wip-us.apache.org/repos/asf/tomee/blob/05a8ed13/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java
index 54b7373..aa7a086 100644
--- a/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java
+++ b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
import java.net.URI;
import java.net.URISyntaxException;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -47,4 +48,19 @@ public class HttpRequestImplTest {
session.invalidate();
assertNull(req.getSession(false));
}
+
+ @Test
+ public void initContext() throws URISyntaxException {
+ final HttpRequestImpl req = new HttpRequestImpl(new URI("http://localhost:1234/api/foo/bar"));
+ req.setUri(req.getSocketURI());
+
+ req.initPathFromContext("/");
+ assertEquals("/api/foo/bar", req.getServletPath());
+
+ req.initPathFromContext("/api"); // reinit, happens with cxf + embedded http
+ assertEquals("/foo/bar", req.getServletPath());
+
+ req.initPathFromContext("/api/bar"); // that's too late we tolerate a wrong context only if its value is "/"
+ assertEquals("/foo/bar", req.getServletPath());
+ }
}