cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1201788 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/or...
Date Mon, 14 Nov 2011 17:03:46 GMT
Author: sergeyb
Date: Mon Nov 14 17:03:46 2011
New Revision: 1201788

URL: http://svn.apache.org/viewvc?rev=1201788&view=rev
Log:
[CXF-3908] Checking for exception mappers before wrapping IOExceptions

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1201788&r1=1201787&r2=1201788&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Mon Nov
14 17:03:46 2011
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs;
 
 
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -236,12 +237,17 @@ public class JAXRSInvoker extends Abstra
                 msg.put(URITemplate.TEMPLATE_PARAMETERS, values);
                 // work out request parameters for the sub-resource class. Here we
                 // presume InputStream has not been consumed yet by the root resource class.
-                //I.e., only one place either in the root resource or sub-resource class
can
-                //have a parameter that read from entity body.
                 List<Object> newParams = JAXRSUtils.processParameters(subOri, values,
msg);
                 msg.setContent(List.class, newParams);
 
                 return this.invoke(exchange, newParams, result);
+            } catch (IOException ex) {
+                Response resp = JAXRSUtils.convertFaultToResponse(ex, exchange.getInMessage());
+                if (resp == null) {
+                    resp = JAXRSUtils.convertFaultToResponse(new WebApplicationException(ex),

+                                                             exchange.getInMessage());
+                }
+                return new MessageContentsList(resp);
             } catch (WebApplicationException ex) {
                 Response excResponse;
                 if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(), 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1201788&r1=1201787&r2=1201788&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Mon Nov 14 17:03:46 2011
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs.interceptor;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.ResourceBundle;
 import java.util.logging.Level;
@@ -233,8 +234,18 @@ public class JAXRSInInterceptor extends 
         setExchangeProperties(message, ori, values, resources.size());  
       
         //Process parameters
-        List<Object> params = JAXRSUtils.processParameters(ori, values, message);
-        message.setContent(List.class, params);
+        try {
+            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 WebApplicationException(ex);
+            } else {
+                message.getExchange().put(Response.class, excResponse);
+            }
+        }
+        
     }
     
     private void setExchangeProperties(Message message, OperationResourceInfo ori, 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1201788&r1=1201787&r2=1201788&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Mon
Nov 14 17:03:46 2011
@@ -550,7 +550,8 @@ public final class JAXRSUtils {
     //Message contains following information: PATH, HTTP_REQUEST_METHOD, CONTENT_TYPE, InputStream.
     public static List<Object> processParameters(OperationResourceInfo ori, 
                                                  MultivaluedMap<String, String> values,

-                                                 Message message) {
+                                                 Message message)
+        throws IOException, WebApplicationException {
         
         
         Method method = ori.getMethodToInvoke();
@@ -595,7 +596,8 @@ public final class JAXRSUtils {
                                            Parameter parameter, 
                                            MultivaluedMap<String, String> values,
                                            Message message,
-                                           OperationResourceInfo ori) {
+                                           OperationResourceInfo ori) 
+        throws IOException, WebApplicationException {
         InputStream is = message.getContent(InputStream.class);
 
         if (parameter.getType() == ParameterType.REQUEST_BODY) {
@@ -1016,7 +1018,7 @@ public final class JAXRSUtils {
                                                   InputStream is, 
                                                   MediaType contentType, 
                                                   List<MediaType> consumeTypes,
-                                                  Message m) {
+                                                  Message m) throws IOException, WebApplicationException
{
         
         List<MediaType> types = JAXRSUtils.intersectMimeTypes(consumeTypes, contentType);
         
@@ -1035,11 +1037,7 @@ public final class JAXRSUtils {
                               targetTypeClass, parameterType, parameterAnnotations, contentType,
                               headers.getRequestHeaders(), is);
                 } catch (IOException e) {
-                    String errorMessage = "Error deserializing input stream into target class
"
-                                          + targetTypeClass.getSimpleName() 
-                                           + ", content type : " + contentType;
-                    LOG.severe(errorMessage);
-                    throw new WebApplicationException(e);
+                    throw e;
                 } catch (WebApplicationException ex) {
                     throw ex;
                 } catch (Exception ex) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=1201788&r1=1201787&r2=1201788&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
Mon Nov 14 17:03:46 2011
@@ -166,7 +166,7 @@ public class SelectMethodCandidatesTest 
         assertEquals("The Book", c.getTitle());
     }
     
-    private void doTestGenericSuperType(Class<?> serviceClass, String methodName) {
+    private void doTestGenericSuperType(Class<?> serviceClass, String methodName) throws
Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
         sf.setResourceClasses(serviceClass);
         sf.create();

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java?rev=1201788&r1=1201787&r2=1201788&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
Mon Nov 14 17:03:46 2011
@@ -19,11 +19,7 @@
 
 package org.apache.cxf.systest.jaxrs;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Collection;
@@ -74,49 +70,7 @@ public class JAXRSClientServerResourceJa
         Book book = collection.iterator().next();
         assertEquals(123L, book.getId());
     }
-    
-    @Test
-    public void testPostPetStatus() throws Exception {
         
-        String endpointAddress =
-            "http://localhost:" + PORT + "/webapp/petstore/pets";
-
-        URL url = new URL(endpointAddress);   
-        HttpURLConnection httpUrlConnection = (HttpURLConnection)url.openConnection();  
-             
-        httpUrlConnection.setUseCaches(false);   
-        httpUrlConnection.setDefaultUseCaches(false);   
-        httpUrlConnection.setDoOutput(true);   
-        httpUrlConnection.setDoInput(true);   
-        httpUrlConnection.setRequestMethod("POST");   
-        httpUrlConnection.setRequestProperty("Accept",   "text/xml");   
-        httpUrlConnection.setRequestProperty("Content-type",   "application/x-www-form-urlencoded");
  
-        httpUrlConnection.setRequestProperty("Connection",   "close");   
-
-        OutputStream outputstream = httpUrlConnection.getOutputStream();
-        File inputFile = new File(getClass().getResource("resources/singleValPostBody.txt").toURI());
        
-         
-        byte[] tmp = new byte[4096];
-        int i = 0;
-        InputStream is = new FileInputStream(inputFile);
-        try {
-            while ((i = is.read(tmp)) >= 0) {
-                outputstream.write(tmp, 0, i);
-            }
-        } finally {
-            is.close();
-        }
-
-        outputstream.flush();
-
-        int responseCode = httpUrlConnection.getResponseCode();   
-        assertEquals(200, responseCode); 
-        assertEquals("Wrong status returned", "open", getStringFromInputStream(httpUrlConnection
-            .getInputStream()));  
-        httpUrlConnection.disconnect();
-    }
-    
-    
     
     private String getStringFromInputStream(InputStream in) throws Exception {
         return IOUtils.toString(in);



Mime
View raw message