Author: reto
Date: Sun Mar 14 20:09:07 2010
New Revision: 922939

URL: http://svn.apache.org/viewvc?rev=922939&view=rev
Log:
CLEREZZA-161: invoking body.writeTo of result of exception handling as 
priviledged.

Modified:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java

Modified: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java?rev=922939&r1=922938&r2=922939&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java
 Sun Mar 14 20:09:07 2010
@@ -40,6 +40,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.logging.Level;
 
 import javax.activation.UnsupportedDataTypeException;
 import javax.security.auth.Subject;
@@ -306,7 +307,7 @@ class ResponseProcessor {
                                }
                        }
 
-                       private void writeTo(OutputStream firstByteActionOut, 
WritableByteChannel out)
+                       private void writeTo(OutputStream firstByteActionOut, 
final WritableByteChannel out)
                                        throws IOException{
                                try {
                                        finalWriter.writeTo(finalEntity, 
finalEntity.getClass(), entityType,
@@ -316,9 +317,33 @@ class ResponseProcessor {
                                        try {
                                                BodyStoringResponse 
responseFake = new BodyStoringResponse(response);
                                                
JaxRsHandler.handleException(ex, request, responseFake);
-                                               MessageBody body = 
responseFake.getBody();
+                                               final MessageBody body = 
responseFake.getBody();
                                                if (body != null) {
-                                                       body.writeTo(out);
+                                                       try {
+                                                               //doing 
priviledged as this might invoke doAs to
+                                                               //write the 
body as subject
+                                                               
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+
+                                                                       
@Override
+                                                                       public 
Subject run() throws IOException {
+                                                                               
body.writeTo(out);
+                                                                               
return null;
+                                                                       }
+                                                               });
+                                                       } catch 
(PrivilegedActionException privEx) {
+                                                               Throwable cause 
= privEx.getCause();
+                                                               if (cause 
instanceof IOException) {
+                                                                       throw 
(IOException)cause;
+                                                               }
+                                                               if (cause 
instanceof RuntimeException) {
+                                                                       throw 
(RuntimeException)cause;
+                                                               }
+                                                               if (cause 
instanceof Error) {
+                                                                       throw 
(Error)cause;
+                                                               }
+                                                               throw new 
RuntimeException(cause);
+                                                       }
+                                                       
                                                }
                                        } catch (HandlerException e) {
                                                throw new RuntimeException(e);


Reply via email to