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 2015/04/01 19:54:56 UTC
[1/2] tomee git commit: trying to not trigger anymore parameter
parsing cause of cdi during a http request
Repository: tomee
Updated Branches:
refs/heads/master 065171fcb -> a6e42f4f5
trying to not trigger anymore parameter parsing cause of cdi during a http request
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/28b3215d
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/28b3215d
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/28b3215d
Branch: refs/heads/master
Commit: 28b3215d2021d48e7470ccd892a317518473ef9f
Parents: 065171f
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Wed Apr 1 19:54:37 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Wed Apr 1 19:54:37 2015 +0200
----------------------------------------------------------------------
.../openejb/cdi/CdiAppContextsService.java | 36 +++++++++++++++-----
1 file changed, 27 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/28b3215d/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
index 7008ec2..bda7af3 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
@@ -68,6 +68,8 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"), CdiAppContextsService.class);
+ private static final String CID = "cid";
+
private final ThreadLocal<ServletRequestContext> requestContext = new ThreadLocal<>();
private final ThreadLocal<SessionContext> sessionContext = new ThreadLocal<>();
@@ -364,7 +366,7 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
//Re-initialize thread local for session
final HttpSession session = request.getSession(false);
- final String cid = conversationService != null ? request.getParameter("cid") : null;
+ final String cid = conversationService != null ? getCid(request) : null;
if (session != null) {
initSessionContext(session);
if (autoConversationCheck && conversationService != null && !isConversationSkipped(request)) {
@@ -391,6 +393,26 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
}
}
+ public static String getCid(final HttpServletRequest req) {
+ return getFromQuery(CID, req.getQueryString());
+ }
+
+ public static String getFromQuery(final String name, final String q) {
+ final int cid = q == null ? -1 : q.indexOf(name + "=");
+ if (cid < 0) {
+ return null;
+ }
+ int end = q.indexOf("&", cid);
+ final int end2 = q.indexOf("#", cid);
+ if (end2 > 0 && end2 < end) {
+ end = end2;
+ }
+ if (end < 0) {
+ end = q.length();
+ }
+ return q.substring(cid + name.length() + 1, end);
+ }
+
public boolean isAutoConversationCheck() {
return autoConversationCheck;
}
@@ -400,7 +422,7 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
if (rc != null && rc.getServletRequest() != null && conversationService != null) {
final HttpSession session = rc.getServletRequest().getSession(false);
if (session != null) {
- final String cid = rc.getServletRequest().getParameter("cid");
+ final String cid = getFromQuery(CID, rc.getServletRequest().getQueryString());
if (cid != null) {
final ConversationManager conversationManager = webBeansContext.getConversationManager();
final ConversationImpl c = conversationManager.getPropogatedConversation(cid, session.getId());
@@ -585,11 +607,6 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
singletonContext.destroy();
}
- /**
- * Initialize conversation context.
- *
- * @param context context
- */
private ConversationContext initConversationContext(final Object request) {
if (conversationService == null) {
return null;
@@ -697,7 +714,8 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
}
private boolean isConversationSkipped(final HttpServletRequest servletRequest) {
- return "none".equals(servletRequest.getParameter("conversationPropagation")) || "true".equals(servletRequest.getParameter("nocid"));
+ final String queryString = servletRequest.getQueryString();
+ return "none".equals(getFromQuery("conversationPropagation", queryString)) || "true".equals(getFromQuery("nocid", queryString));
}
private boolean isTimeout() {
@@ -775,7 +793,7 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
public String getHttpParameter(final String name) {
final ServletRequestContext req = getRequestContext(false);
if (req != null && req.getServletRequest() != null) {
- return req.getServletRequest().getParameter(name);
+ return getFromQuery(name, req.getServletRequest().getQueryString());
}
return null;
}
[2/2] tomee git commit: small test for query string parsing
Posted by rm...@apache.org.
small test for query string parsing
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a6e42f4f
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a6e42f4f
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a6e42f4f
Branch: refs/heads/master
Commit: a6e42f4f59043e93dd4e93106ae1d3e450aa7ad7
Parents: 28b3215
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Wed Apr 1 19:54:51 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Wed Apr 1 19:54:51 2015 +0200
----------------------------------------------------------------------
.../openejb/cdi/CdiAppContextsServiceTest.java | 36 ++++++++++++++++++++
1 file changed, 36 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/a6e42f4f/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiAppContextsServiceTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiAppContextsServiceTest.java b/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiAppContextsServiceTest.java
new file mode 100644
index 0000000..e56cc7b
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiAppContextsServiceTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.cdi;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class CdiAppContextsServiceTest {
+ @Test
+ public void cid() {
+ assertNull(CdiAppContextsService.getFromQuery(null));
+ assertNull(CdiAppContextsService.getFromQuery(""));
+ assertNull(CdiAppContextsService.getFromQuery("superparam=cejdzl&cfdlcjlzdbc=czlbcjb&cdlzcs&cdlcjkd"));
+ assertEquals("1", CdiAppContextsService.getFromQuery("cid=1"));
+ assertEquals("10", CdiAppContextsService.getFromQuery("cid=10"));
+ assertEquals("10", CdiAppContextsService.getFromQuery("cecfzd=cefczerf&cfdzcd=&é&cdzc&cid=10"));
+ assertEquals("10", CdiAppContextsService.getFromQuery("cecfzd=cefczerf&cfdzcd=&é&cdzc&cid=10&cdsjlcbdjc=djlbcsjlb=ldjbs=cdsln"));
+ assertEquals("10", CdiAppContextsService.getFromQuery("cid=10&cdsjlcbdjc=djlbcsjlb=ldjbs=cdsln"));
+ }
+}