cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r734965 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Date Fri, 16 Jan 2009 10:43:27 GMT
Author: sergeyb
Date: Fri Jan 16 02:43:25 2009
New Revision: 734965

URL: http://svn.apache.org/viewvc?rev=734965&view=rev
Log:
If WebApplicationException is thrown by custom parameter class then rethrow it

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=734965&r1=734964&r2=734965&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Fri
Jan 16 02:43:25 2009
@@ -27,6 +27,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
 import org.apache.cxf.message.Message;
@@ -122,4 +123,12 @@
         return sb.toString();
     }
     
+    public static Response.Status getParameterFailureStatus(ParameterType pType) {
+        if (pType == ParameterType.MATRIX || pType == ParameterType.PATH
+            || pType == ParameterType.QUERY) {
+            return Response.Status.NOT_FOUND;
+        }
+        return Response.Status.BAD_REQUEST;
+    }
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=734965&r1=734964&r2=734965&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Fri Jan 16 02:43:25 2009
@@ -172,11 +172,13 @@
             return c.newInstance(new Object[]{value});
         } catch (NoSuchMethodException ex) {
             // try valueOf
-        } catch (Exception ex) {
+        } catch (WebApplicationException ex) {
+            throw ex;
+        } catch (Exception ex) { 
             LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_CONSTRUCTOR_FAILURE",

                                                                BUNDLE, 
                                                                pClass.getName()).toString());
-            throw new WebApplicationException(ex, getFailureStatus(pType));
+            throw new WebApplicationException(ex, HttpUtils.getParameterFailureStatus(pType));
         }
         
         // check for valueOf(String) static methods
@@ -233,7 +235,7 @@
             LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_VALUE_OF_FAILURE", 
                                                                BUNDLE, 
                                                                pClass.getName()).toString());
-            throw new WebApplicationException(t, getFailureStatus(pType));
+            throw new WebApplicationException(t, HttpUtils.getParameterFailureStatus(pType));
         }
         return null;
     }
@@ -500,12 +502,4 @@
             InjectionUtils.injectContextField(cri, f, o, value, true);
         }
     }
-    
-    public static Response.Status getFailureStatus(ParameterType pType) {
-        if (pType == ParameterType.MATRIX || pType == ParameterType.PATH
-            || pType == ParameterType.QUERY) {
-            return Response.Status.NOT_FOUND;
-        }
-        return Response.Status.BAD_REQUEST;
-    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java?rev=734965&r1=734964&r2=734965&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Fri Jan 16 02:43:25 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.jaxrs.utils;
 
+import javax.ws.rs.core.Response;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -36,4 +38,20 @@
         
     }
     
+    @Test
+    public void testParameterErrorStatus() {
+        assertEquals(Response.Status.NOT_FOUND,
+                     HttpUtils.getParameterFailureStatus(ParameterType.PATH));
+        assertEquals(Response.Status.NOT_FOUND,
+                     HttpUtils.getParameterFailureStatus(ParameterType.QUERY));
+        assertEquals(Response.Status.NOT_FOUND,
+                     HttpUtils.getParameterFailureStatus(ParameterType.MATRIX));
+        assertEquals(Response.Status.BAD_REQUEST,
+                     HttpUtils.getParameterFailureStatus(ParameterType.HEADER));
+        assertEquals(Response.Status.BAD_REQUEST,
+                     HttpUtils.getParameterFailureStatus(ParameterType.FORM));
+        assertEquals(Response.Status.BAD_REQUEST,
+                     HttpUtils.getParameterFailureStatus(ParameterType.COOKIE));
+    }
+    
 }



Mime
View raw message