cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1494608 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/ja...
Date Wed, 19 Jun 2013 13:22:59 GMT
Author: sergeyb
Date: Wed Jun 19 13:22:59 2013
New Revision: 1494608

URL: http://svn.apache.org/r1494608
Log:
Merged revisions 1479604,1479874 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1479604 | sergeyb | 2013-05-06 16:25:01 +0100 (Mon, 06 May 2013) | 1 line
  
  [CXF-4988] The exceptions thrown from readers should be mapped too
........
  r1479874 | sergeyb | 2013-05-07 13:12:26 +0100 (Tue, 07 May 2013) | 1 line
  
  [CXF-4988] Minor update to the way readers/writers manage tcontent types
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1479604,1479874

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-blocked' - no diff available.

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java?rev=1494608&r1=1494607&r2=1494608&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
Wed Jun 19 13:22:59 2013
@@ -21,8 +21,6 @@ package org.apache.cxf.jaxrs.impl;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 
-import javax.ws.rs.core.MediaType;
-
 import org.apache.cxf.message.Message;
 
 public class AbstractInterceptorContextImpl extends AbstractPropertiesImpl {
@@ -30,16 +28,13 @@ public class AbstractInterceptorContextI
     private Class<?> cls;
     private Type type;
     private Annotation[] anns;
-    private MediaType mt;
     public AbstractInterceptorContextImpl(Class<?> cls,
                                         Type type,
                                         Annotation[] anns,
-                                        MediaType mt,
                                         Message message) {
         super(message);
         this.cls = cls;
         this.type = type;
-        this.mt = mt;
         this.anns = anns;
     }
     
@@ -55,10 +50,6 @@ public class AbstractInterceptorContextI
         return type;
     }
 
-    public MediaType getMediaType() {
-        return mt;
-    }
-
     public void setAnnotations(Annotation[] annotations) {
         anns = annotations;
 
@@ -68,10 +59,6 @@ public class AbstractInterceptorContextI
         type = genType;
     }
 
-    public void setMediaType(MediaType mtype) {
-        mt = mtype;
-    }
-
     public void setType(Class<?> ctype) {
         cls = ctype;
     }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java?rev=1494608&r1=1494607&r2=1494608&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
Wed Jun 19 13:22:59 2013
@@ -25,11 +25,13 @@ import java.lang.reflect.Type;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.ReaderInterceptor;
 import javax.ws.rs.ext.ReaderInterceptorContext;
 
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
 public class ReaderInterceptorContextImpl extends AbstractInterceptorContextImpl 
@@ -40,11 +42,10 @@ public class ReaderInterceptorContextImp
     public ReaderInterceptorContextImpl(Class<?> cls,
                                         Type type,
                                         Annotation[] anns,
-                                        MediaType mt,
                                         InputStream is,
                                         Message message,
                                         List<ReaderInterceptor> readers) {
-        super(cls, type, anns, mt, message);
+        super(cls, type, anns, message);
         this.is = is;
         this.readers = readers;
     }
@@ -77,4 +78,15 @@ public class ReaderInterceptorContextImp
 
     }
 
+    @Override
+    public MediaType getMediaType() {
+        return JAXRSUtils.toMediaType(getHeaders().getFirst(HttpHeaders.CONTENT_TYPE));
+    }
+
+    @Override
+    public void setMediaType(MediaType mt) {
+        getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, JAXRSUtils.mediaTypeToString(mt));
+        
+    }
+
 }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java?rev=1494608&r1=1494607&r2=1494608&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
Wed Jun 19 13:22:59 2013
@@ -25,11 +25,13 @@ import java.lang.reflect.Type;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.WriterInterceptor;
 import javax.ws.rs.ext.WriterInterceptorContext;
 
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
 public class WriterInterceptorContextImpl extends AbstractInterceptorContextImpl 
@@ -43,12 +45,11 @@ public class WriterInterceptorContextImp
                                         Class<?> cls,
                                         Type type,
                                         Annotation[] anns,
-                                        MediaType mt,
                                         OutputStream os,
                                         Message message,
                                         List<WriterInterceptor> writers) {
     //CHECKSTYLE:ON    
-        super(cls, type, anns, mt, message);
+        super(cls, type, anns, message);
         this.entity = entity;
         this.os = os;
         this.writers = writers;
@@ -94,4 +95,17 @@ public class WriterInterceptorContextImp
 
     }
 
+
+    @Override
+    public MediaType getMediaType() {
+        Object value = getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
+        return value instanceof MediaType ? (MediaType)value : JAXRSUtils.toMediaType((String)value);
+    }
+
+
+    @Override
+    public void setMediaType(MediaType mt) {
+        getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, mt);
+    }
+
 }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1494608&r1=1494607&r2=1494608&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Wed Jun 19 13:22:59 2013
@@ -36,6 +36,7 @@ import javax.ws.rs.core.Response;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -98,15 +99,10 @@ public class JAXRSInInterceptor extends 
         
         try {
             processRequest(message);
+        } catch (Fault ex) {
+            convertExceptionToResponseIfPossible(ex.getCause(), message);
         } catch (RuntimeException ex) {
-            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
-            if (excResponse == null) {
-                ProviderFactory.getInstance(message).clearThreadLocalProxies();
-                message.getExchange().put(Message.PROPOGATE_EXCEPTION, 
-                                          JAXRSUtils.propogateException(message));
-                throw ex;
-            }
-            message.getExchange().put(Response.class, excResponse);
+            convertExceptionToResponseIfPossible(ex, message);
         }
         
         
@@ -240,16 +236,22 @@ public class JAXRSInInterceptor extends 
             List<Object> params = JAXRSUtils.processParameters(ori, values, message);
             message.setContent(List.class, params);
         } catch (IOException ex) {
-            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
-            if (excResponse == null) {
-                throw new InternalServerErrorException(ex);
-            } else {
-                message.getExchange().put(Response.class, excResponse);
-            }
+            convertExceptionToResponseIfPossible(ex, message);
         }
         
     }
     
+    private void convertExceptionToResponseIfPossible(Throwable ex, Message message) {
+        Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
+        if (excResponse == null) {
+            ProviderFactory.getInstance(message).clearThreadLocalProxies();
+            message.getExchange().put(Message.PROPOGATE_EXCEPTION, 
+                                      JAXRSUtils.propogateException(message));
+            throw ex instanceof RuntimeException ? (RuntimeException)ex : new InternalServerErrorException(ex);
+        }
+        message.getExchange().put(Response.class, excResponse);
+    }
+    
     private void setExchangeProperties(Message message, OperationResourceInfo ori, 
                                       MultivaluedMap<String, String> values,
                                       int numberOfResources) {

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1494608&r1=1494607&r2=1494608&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Wed Jun 19 13:22:59 2013
@@ -100,6 +100,7 @@ import org.apache.cxf.common.util.Packag
 import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.ext.ContextProvider;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.MessageContextImpl;
@@ -1245,7 +1246,7 @@ public final class JAXRSUtils {
                 } catch (WebApplicationException ex) {
                     throw ex;
                 } catch (Exception ex) {
-                    throw new WebApplicationException(ex);
+                    throw new Fault(ex);
                 }
             } else {
                 String errorMessage = new org.apache.cxf.common.i18n.Message("NO_MSG_READER",
@@ -1275,7 +1276,6 @@ public final class JAXRSUtils {
             ReaderInterceptorContext context = new ReaderInterceptorContextImpl(targetTypeClass,

                                                                             parameterType,

                                                                             parameterAnnotations,

-                                                                            mediaType,
                                                                             is,
                                                                             m,
                                                                             readers);
@@ -1308,8 +1308,7 @@ public final class JAXRSUtils {
             WriterInterceptorContext context = new WriterInterceptorContextImpl(entity,
                                                                                 type, 
                                                                             genericType,

-                                                                            annotations,

-                                                                            mediaType,
+                                                                            annotations,
                                                                             entityStream,
                                                                             message,
                                                                             writers);

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java?rev=1494608&r1=1494607&r2=1494608&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
Wed Jun 19 13:22:59 2013
@@ -46,6 +46,7 @@ import javax.ws.rs.container.PreMatching
 import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Configurable;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ReaderInterceptor;
@@ -360,7 +361,7 @@ public class BookServer20 extends Abstra
             if (!ct.endsWith("ISO-8859-1")) {
                 ct += "us-ascii";
             }
-            context.getHeaders().putSingle("Content-Type", ct);
+            context.setMediaType(MediaType.valueOf(ct));
             context.proceed();
         }
         



Mime
View raw message