cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: Updating JAXRsInInterceptor to check if Response has alrready been set and also removing a duplicate call
Date Fri, 16 May 2014 10:30:33 GMT
Repository: cxf
Updated Branches:
  refs/heads/master a91805329 -> 190f6e24d


Updating JAXRsInInterceptor to check if Response has alrready been set and also removing a
duplicate call


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/190f6e24
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/190f6e24
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/190f6e24

Branch: refs/heads/master
Commit: 190f6e24de6404ae937a02a4530e17fea8434f42
Parents: a918053
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri May 16 11:30:13 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri May 16 11:30:13 2014 +0100

----------------------------------------------------------------------
 .../jaxrs/interceptor/JAXRSInInterceptor.java   | 38 ++++++++++----------
 1 file changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/190f6e24/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
index 9c140fa..8f5f9dd 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
@@ -71,16 +71,17 @@ public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message>
{
         final Exchange exchange = message.getExchange(); 
         
         exchange.put(Message.REST_MESSAGE, Boolean.TRUE);
-        
-        try {
-            processRequest(message);
-            if (exchange.isOneWay()) {
-                ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
+        if (exchange.get(Response.class) == null) {
+            try {
+                processRequest(message, exchange);
+                if (exchange.isOneWay()) {
+                    ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
+                }
+            } catch (Fault ex) {
+                convertExceptionToResponseIfPossible(ex.getCause(), message);
+            } catch (RuntimeException ex) {
+                convertExceptionToResponseIfPossible(ex, message);
             }
-        } catch (Fault ex) {
-            convertExceptionToResponseIfPossible(ex.getCause(), message);
-        } catch (RuntimeException ex) {
-            convertExceptionToResponseIfPossible(ex, message);
         }
         
         Response r = exchange.get(Response.class);
@@ -91,7 +92,7 @@ public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message>
{
         }
     }
     
-    private void processRequest(Message message) {
+    private void processRequest(Message message, Exchange exchange) {
         
         ServerProviderFactory providerFactory = ServerProviderFactory.getInstance(message);
         
@@ -149,7 +150,7 @@ public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message>
{
         } catch (IllegalArgumentException ex) {
             throw ExceptionUtils.toNotAcceptableException(null, null);
         }
-        message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
+        exchange.put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
 
         //1. Matching target resource class
         List<ClassResourceInfo> resources = JAXRSUtils.getRootResources(message);
@@ -174,11 +175,11 @@ public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message>
{
         try {                
             ori = JAXRSUtils.findTargetMethod(matchedResources, message, 
                       httpMethod, matchedValues, requestContentType, acceptContentTypes,
true);
-            setExchangeProperties(message, ori, matchedValues, resources.size());
+            setExchangeProperties(message, exchange, ori, matchedValues, resources.size());
         } catch (WebApplicationException ex) {
             if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(), httpMethod)) {
                 Response response = JAXRSUtils.createResponse(resources, null, null, 200,
true);
-                message.getExchange().put(Response.class, response);
+                exchange.put(Response.class, response);
                 return;
             } else {
                 throw ex;
@@ -195,8 +196,6 @@ public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message>
{
             LOG.fine("Found operation: " + ori.getMethodToInvoke().getName());
         }
         
-        setExchangeProperties(message, ori, matchedValues, resources.size());
-        
         // Global and name-bound post-match request filters
         if (JAXRSUtils.runContainerRequestFilters(providerFactory,
                                                   message,
@@ -230,10 +229,11 @@ public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message>
{
         message.getExchange().put(Throwable.class, ex);
     }
     
-    private void setExchangeProperties(Message message, OperationResourceInfo ori, 
-                                      MultivaluedMap<String, String> values,
-                                      int numberOfResources) {
-        final Exchange exchange = message.getExchange();
+    private void setExchangeProperties(Message message,
+                                       Exchange exchange,
+                                       OperationResourceInfo ori, 
+                                       MultivaluedMap<String, String> values,
+                                       int numberOfResources) {
         final ClassResourceInfo cri = ori.getClassResourceInfo();
         exchange.put(OperationResourceInfo.class, ori);
         exchange.put(JAXRSUtils.ROOT_RESOURCE_CLASS, cri);


Mime
View raw message