cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject cayenne git commit: CAY-2090 Untangle HttpRemoteService from ServiceContext thread local setup
Date Wed, 08 Jun 2016 14:59:43 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master f5ae597e9 -> 85852f92e


CAY-2090 Untangle HttpRemoteService from ServiceContext thread local setup


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/85852f92
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/85852f92
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/85852f92

Branch: refs/heads/master
Commit: 85852f92ee05f5e1ae70dae7315beda32f2b4077
Parents: f5ae597
Author: Savva Kolbachev <s.kolbachev@gmail.com>
Authored: Wed Jun 8 17:58:42 2016 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Wed Jun 8 17:58:42 2016 +0300

----------------------------------------------------------------------
 .../apache/cayenne/rop/ROPRequestContext.java   | 107 +++++++++++++++++++
 .../java/org/apache/cayenne/rop/ROPServlet.java |   6 +-
 .../cayenne/rop/ServerHttpRemoteService.java    |   3 +-
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |   1 +
 4 files changed, 112 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/85852f92/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPRequestContext.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPRequestContext.java b/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPRequestContext.java
new file mode 100644
index 0000000..126b5d2
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPRequestContext.java
@@ -0,0 +1,107 @@
+/*****************************************************************
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.cayenne.rop;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class ROPRequestContext {
+
+    private static final ThreadLocal<ROPRequestContext> localContext = new ThreadLocal<>();
+
+    private String serviceId;
+    private String objectId;
+    private ServletRequest request;
+    private ServletResponse response;
+    private int count;
+
+    private ROPRequestContext() {
+    }
+
+    public static void start(String serviceId, String objectId, ServletRequest request, ServletResponse
response) {
+        ROPRequestContext context = localContext.get();
+
+        if (context == null) {
+            context = new ROPRequestContext();
+            localContext.set(context);
+        }
+
+        context.serviceId = serviceId;
+        context.objectId = objectId;
+        context.request = request;
+        context.response = response;
+        context.count++;
+    }
+
+    public static ROPRequestContext getROPRequestContext() {
+        return localContext.get();
+    }
+
+    public static String getContextServiceId() {
+        ROPRequestContext context = localContext.get();
+
+        if (context != null) {
+            return context.serviceId;
+        } else {
+            return null;
+        }
+    }
+
+    public static String getContextObjectId() {
+        ROPRequestContext context = localContext.get();
+
+        if (context != null) {
+            return context.objectId;
+        } else {
+            return null;
+        }
+    }
+
+    public static ServletRequest getContextRequest() {
+        ROPRequestContext context = localContext.get();
+
+        if (context != null) {
+            return context.request;
+        } else {
+            return null;
+        }
+    }
+
+    public static ServletResponse getContextResponse() {
+        ROPRequestContext context = localContext.get();
+
+        if (context != null) {
+            return context.response;
+        } else {
+            return null;
+        }
+    }
+
+    public static void end() {
+        ROPRequestContext context = localContext.get();
+
+        if (context != null && --context.count == 0) {
+            context.request = null;
+            context.response = null;
+
+            localContext.set(null);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/85852f92/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java b/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java
index 8c12baf..db1bb0a 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.rop;
 
-import com.caucho.services.server.ServiceContext;
 import org.apache.cayenne.configuration.CayenneRuntime;
 import org.apache.cayenne.configuration.rop.server.ROPServerModule;
 import org.apache.cayenne.configuration.server.ServerRuntime;
@@ -98,8 +97,7 @@ public class ROPServlet extends HttpServlet {
                 objectId = req.getParameter("ejbid");
             }
 
-            // TODO: need to untangle HttpRemoteService from dependence on Hessian's ServiceContext
thread local setup
-            ServiceContext.begin(req, resp, serviceId, objectId);
+            ROPRequestContext.start(serviceId, objectId, req, resp);
 
             String operation = req.getParameter(ROPConstants.OPERATION_PARAMETER);
 
@@ -128,6 +126,8 @@ public class ROPServlet extends HttpServlet {
             throw e;
         } catch (Throwable e) {
             throw new ServletException(e);
+        } finally {
+            ROPRequestContext.end();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/85852f92/cayenne-server/src/main/java/org/apache/cayenne/rop/ServerHttpRemoteService.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/rop/ServerHttpRemoteService.java
b/cayenne-server/src/main/java/org/apache/cayenne/rop/ServerHttpRemoteService.java
index 22aba9f..9099b04 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/rop/ServerHttpRemoteService.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/rop/ServerHttpRemoteService.java
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.rop;
 
-import com.caucho.services.server.ServiceContext;
 import org.apache.cayenne.configuration.Constants;
 import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.di.Inject;
@@ -37,7 +36,7 @@ public class ServerHttpRemoteService extends HttpRemoteService {
 
 	@Override
 	protected HttpSession getSession(boolean create) {
-		HttpServletRequest request = (HttpServletRequest) ServiceContext.getContextRequest();
+		HttpServletRequest request = (HttpServletRequest) ROPRequestContext.getContextRequest();
 		if (request == null) {
 			throw new IllegalStateException(
 					"Attempt to access HttpSession outside the request scope.");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/85852f92/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 0c9ae04..6cf687e 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -22,6 +22,7 @@ CAY-2065 Pluggable serialization and connectivity layers for ROP
 CAY-2073 Ordering.orderedList methods
 CAY-2074 Support for catalogs in stored procedures
 CAY-2083 Implement Protostuff as serialization service for Cayenne ROP
+CAY-2090 Untangle HttpRemoteService from ServiceContext thread local setup
 
 Bug Fixes:
 


Mime
View raw message