summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2012-06-20 00:31:38 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2012-06-20 00:31:38 +0000
commitd10dbf4a6cb9a549ba8edca1805592b09e5585b8 (patch)
treef67a5c8eeac2e378e18ce226ea338070f1fb7803 /sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache
parent0841514e8aca337df394fcd5acae78a730812233 (diff)
TUSCANY-4065 - Properly retrieving binding context within the response handlers
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1351908 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java45
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java8
2 files changed, 53 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java
new file mode 100644
index 0000000000..0c9d070a4b
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/ThreadBindingContext.java
@@ -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();
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
index 35c46ac56b..17756a7f23 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
@@ -94,6 +94,7 @@ public class TuscanyRESTServlet extends RestServlet {
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 RestServlet {
} finally {
//remove
ThreadHTTPContext.removeHTTPContext();
+ ThreadBindingContext.removeBindingContext();
}
}
@@ -209,6 +211,10 @@ public class TuscanyRESTServlet extends RestServlet {
/**
* 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 RestServlet {
return;
}
+ RESTBinding binding = ThreadBindingContext.getBindingContext();
+
//process declarative headers
for(HTTPHeader header : binding.getHttpHeaders()) {
//treat special headers that need to be calculated