tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r1351908 - in /tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src: main/java/org/apache/tuscany/sca/binding/rest/provider/ test/resources/
Date Wed, 20 Jun 2012 00:31:38 GMT
Author: lresende
Date: Wed Jun 20 00:31:38 2012
New Revision: 1351908

URL: http://svn.apache.org/viewvc?rev=1351908&view=rev
Log:
TUSCANY-4065 - Properly retrieving binding context within the response handlers

Added:
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java
  (with props)
Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite

Added: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java?rev=1351908&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java
(added)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java
Wed Jun 20 00:31:38 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.tuscany.sca.binding.rest.provider;
+
+import org.apache.tuscany.sca.binding.rest.RESTBinding;
+
+public class ThreadBindingContext {
+
+    private static final ThreadLocal<RESTBinding> CONTEXT = new ThreadLocal<RESTBinding>();
+
+    private ThreadBindingContext() {
+    }
+
+    public static RESTBinding setBindingContext(RESTBinding binding) {
+        RESTBinding old = CONTEXT.get();
+        CONTEXT.set(binding);
+        return old;
+    }
+
+    public static RESTBinding getBindingContext() {
+        return CONTEXT.get();
+    }
+
+    public static void removeBindingContext() {
+        CONTEXT.remove();
+    }
+
+}

Propchange: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java?rev=1351908&r1=1351907&r2=1351908&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
Wed Jun 20 00:31:38 2012
@@ -94,6 +94,7 @@ public class TuscanyRESTServlet extends 
         try {
             //store in thread local
             ThreadHTTPContext.setHTTPContext(bindingContext);
+            ThreadBindingContext.setBindingContext(binding);
             
             // handle special ?wadl request
             String query = request.getQueryString();
@@ -105,6 +106,7 @@ public class TuscanyRESTServlet extends 
         } finally {
             //remove
             ThreadHTTPContext.removeHTTPContext();
+            ThreadBindingContext.removeBindingContext();
         }
     }
 
@@ -209,6 +211,10 @@ public class TuscanyRESTServlet extends 
 
     /**
      * TuscanyResponseHandler
+     * 
+     * The response handler is shared, that's why we need to get the 
+     * binding from the thread context otherwise different components
+     * might get wrong binding configuration (e.g. headers)
      *
      * Required to support declarative HTTP Headers
      */
@@ -222,6 +228,8 @@ public class TuscanyRESTServlet extends 
                 return;
             }
 
+            RESTBinding binding = ThreadBindingContext.getBindingContext(); 
+                
             //process declarative headers
             for(HTTPHeader header : binding.getHttpHeaders()) {
                 //treat special headers that need to be calculated

Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite?rev=1351908&r1=1351907&r2=1351908&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite
Wed Jun 20 00:31:38 2012
@@ -22,7 +22,24 @@
 		targetNamespace="http://customer"
 		name="customer">
 		
-	<component name="CustomerService">
+	<component name="DummyComponent">
+		<implementation.java class="services.customer.CustomerServiceImpl"/> 
+		<service name="CustomerService">
+			<tuscany:binding.rest uri="http://localhost:8085/Dummy">
+    		    <tuscany:wireFormat.xml />
+			    <tuscany:operationSelector.jaxrs />
+			    <tuscany:http-headers>
+			       <tuscany:header name="Cache-Control" value="no-cache"/>
+			       <tuscany:header name="Expires" value="-1"/>
+			       <tuscany:header name="X-Tuscany" value="dummy"/>
+			       <tuscany:header name="X-TuscanyComponent" value="DummyComponent"/> 
+			    </tuscany:http-headers>
+    		</tuscany:binding.rest>
+   		</service>
+	</component>
+		
+		
+	<component name="CustomerComponent">
 		<implementation.java class="services.customer.CustomerServiceImpl"/> 
 		<service name="CustomerService">
 			<tuscany:binding.rest uri="http://localhost:8085/Customer">
@@ -32,6 +49,7 @@
 			       <tuscany:header name="Cache-Control" value="no-cache"/>
 			       <tuscany:header name="Expires" value="-1"/>
 			       <tuscany:header name="X-Tuscany" value="tuscany"/> 
+			       <tuscany:header name="X-TuscanyComponent" value="CustomerComponent"/>
 			    </tuscany:http-headers>
     		</tuscany:binding.rest>
    		</service>



Mime
View raw message