cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1506633 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Date Wed, 24 Jul 2013 17:23:45 GMT
Author: sergeyb
Date: Wed Jul 24 17:23:45 2013
New Revision: 1506633

URL: http://svn.apache.org/r1506633
Log:
Merged revisions 1506578 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1506578 | sergeyb | 2013-07-24 15:35:11 +0100 (Wed, 24 Jul 2013) | 1 line
  
  Some ResponseImpl clean up
........

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/ResponseImpl.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1506578

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/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1506633&r1=1506632&r2=1506633&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Wed Jul 24 17:23:45 2013
@@ -297,16 +297,19 @@ public final class ResponseImpl extends 
         checkEntityIsClosed();
         
         if (!hasEntity()) {
-            return null;
+            throw new MessageProcessingException("Null entity");
         }
         
         if (cls.isAssignableFrom(entity.getClass())) {
-            T response = cls.cast(entity);
-            closeIfNotBufferred(cls);
-            return response;
+            return cls.cast(entity);
         }
-        
-        if (responseMessage != null && entity instanceof InputStream) {
+        if (entity instanceof InputStream) {
+            
+            if (responseMessage == null) {
+                // won't happen, just in case
+                throw new RuntimeException();    
+            }
+            
             MediaType mediaType = getMediaType();
             if (mediaType == null) {
                 mediaType = MediaType.WILDCARD_TYPE;
@@ -318,36 +321,33 @@ public final class ResponseImpl extends 
             if (readers != null) {
                 try {
                     responseMessage.put(Message.PROTOCOL_HEADERS, this.getMetadata());
-                    return cls.cast(JAXRSUtils.readFromMessageBodyReader(readers, cls, t,

-                                                                anns, 
-                                                                InputStream.class.cast(entity),

-                                                                mediaType, 
-                                                                responseMessage));
+                    Object newEntity = JAXRSUtils.readFromMessageBodyReader(readers, cls,
t, 
+                                                                           anns, 
+                                                                           InputStream.class.cast(entity),

+                                                                           mediaType, 
+                                                                           responseMessage);
+                    InputStream.class.cast(entity).close();
+                    entity = newEntity;
+                    entityBufferred = true;
+                    
+                    return cls.cast(entity);
                 } catch (Exception ex) {
                     throw new MessageProcessingException(ex);
-                } finally {
-                    closeIfNotBufferred(cls);
                 }
             }
         }
+        throw new IllegalStateException("The entity is not backed by an input stream");
         
-        throw new MessageProcessingException("No Message Body reader is available");
     }
     
-    private void closeIfNotBufferred(Class<?> responseCls) {
-        if (!entityBufferred && !InputStream.class.isAssignableFrom(responseCls))
{
-            close();
-        }
-    }
     
     public boolean bufferEntity() throws MessageProcessingException {
-        if (entityClosed) {
-            throw new IllegalStateException();
-        }
+        checkEntityIsClosed();
         if (!entityBufferred && entity instanceof InputStream) {
             try {
                 InputStream oldEntity = (InputStream)entity;
                 entity = IOUtils.loadIntoBAIS(oldEntity);
+                oldEntity.close();
                 entityBufferred = true;
             } catch (IOException ex) {
                 throw new MessageProcessingException(ex);
@@ -358,16 +358,15 @@ public final class ResponseImpl extends 
 
     public void close() throws MessageProcessingException {
         if (!entityClosed) {
-            if (entity instanceof InputStream) {
+            if (!entityBufferred && entity instanceof InputStream) {
                 try {
                     ((InputStream)entity).close();
-                    entity = null;
                 } catch (IOException ex) {
                     throw new MessageProcessingException(ex);
                 }
             }
+            entity = null;
             entityClosed = true;
-            
         }
         
     }



Mime
View raw message