cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1154870 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: JAXRSInvoker.java impl/WebApplicationExceptionMapper.java interceptor/JAXRSInInterceptor.java utils/JAXRSUtils.java
Date Mon, 08 Aug 2011 08:41:38 GMT
Author: sergeyb
Date: Mon Aug  8 08:41:38 2011
New Revision: 1154870

URL: http://svn.apache.org/viewvc?rev=1154870&view=rev
Log:
[CXF-3654] Optional reporting of uri mismatch related error messages

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/impl/WebApplicationExceptionMapper.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

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=1154870&r1=1154869&r2=1154870&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 Aug
 8 08:41:38 2011
@@ -244,7 +244,7 @@ public class JAXRSInvoker extends Abstra
                 Response excResponse;
                 if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(), 
                         (String)exchange.getInMessage().get(Message.HTTP_REQUEST_METHOD)))
{
-                    excResponse = JAXRSUtils.createResponse(subCri, 200, true);
+                    excResponse = JAXRSUtils.createResponse(subCri, null, null, 200, true);
                 } else {
                     excResponse = JAXRSUtils.convertFaultToResponse(ex, exchange.getInMessage());
                 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java?rev=1154870&r1=1154869&r2=1154870&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
Mon Aug  8 08:41:38 2011
@@ -40,32 +40,23 @@ public class WebApplicationExceptionMapp
     private boolean printStackTrace;
     
     public Response toResponse(WebApplicationException ex) {
-        if (LOG.isLoggable(Level.WARNING)) {
-            String message = ex.getCause() == null ? ex.getMessage() : ex.getCause().getMessage();
-            if (message == null) {
-                if (ex.getCause() != null) {
-                    message = "cause is " + ex.getCause().getClass().getName();
-                } else {
-                    message = "no cause is available";
-                }
+        
+        String message = ex.getCause() == null ? ex.getMessage() : ex.getCause().getMessage();
+        if (message == null) {
+            if (ex.getCause() != null) {
+                message = "cause is " + ex.getCause().getClass().getName();
+            } else {
+                message = "no cause is available";
             }
-            org.apache.cxf.common.i18n.Message errorMsg = 
-                new org.apache.cxf.common.i18n.Message("WEB_APP_EXCEPTION", BUNDLE, message);
+        }
+        org.apache.cxf.common.i18n.Message errorMsg = 
+            new org.apache.cxf.common.i18n.Message("WEB_APP_EXCEPTION", BUNDLE, message);
+        if (LOG.isLoggable(Level.WARNING)) {
             LOG.warning(errorMsg.toString());
         }
         Response r = ex.getResponse(); 
         if (r == null) {
-            String message = null;
-            if (ex.getCause() == null) {
-                message = new org.apache.cxf.common.i18n.Message("DEFAULT_EXCEPTION_MESSAGE",

-                                                                 BUNDLE).toString();
-            } else {
-                message = ex.getCause().getMessage();
-                if (message == null) {
-                    message = ex.getCause().getClass().getName();
-                }
-            }
-            r = Response.status(500).type(MediaType.TEXT_PLAIN).entity(message).build();
+            r = Response.status(500).type(MediaType.TEXT_PLAIN).entity(errorMsg.toString()).build();
         }
         
         if (printStackTrace) {

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=1154870&r1=1154869&r2=1154870&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 Aug  8 08:41:38 2011
@@ -146,8 +146,9 @@ public class JAXRSInInterceptor extends 
                                                    message.get(Message.REQUEST_URI),
                                                    rawPath);
             LOG.warning(errorMsg.toString());
-
-            throw new WebApplicationException(Response.Status.NOT_FOUND);
+            Response resp = JAXRSUtils.createResponse(resource, message, errorMsg.toString(),

+                    Response.Status.NOT_FOUND.getStatusCode(), false);
+            throw new WebApplicationException(resp);
         }
 
         message.getExchange().put(JAXRSUtils.ROOT_RESOURCE_CLASS, resource);
@@ -207,7 +208,7 @@ public class JAXRSInInterceptor extends 
                 setExchangeProperties(message, ori, values, resources.size());
             } catch (WebApplicationException ex) {
                 if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(), httpMethod))
{
-                    Response response = JAXRSUtils.createResponse(resource, 200, true);
+                    Response response = JAXRSUtils.createResponse(resource, null, null, 200,
true);
                     message.getExchange().put(Response.class, response);
                     return;
                 } else {

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=1154870&r1=1154869&r2=1154870&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
Aug  8 08:41:38 2011
@@ -114,6 +114,7 @@ public final class JAXRSUtils {
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSUtils.class);
     private static final String PROPAGATE_EXCEPTION = "org.apache.cxf.propagate.exception";
+    private static final String REPORT_FAULT_MESSAGE_PROPERTY = "org.apache.cxf.jaxrs.report-fault-message";
     
     private JAXRSUtils() {        
     }
@@ -407,7 +408,8 @@ public final class JAXRSUtils {
         if (!"OPTIONS".equalsIgnoreCase(httpMethod) && logNow) {
             LOG.warning(errorMsg.toString());
         }
-        Response response = createResponse(resource, status, methodMatched == 0);
+        Response response = 
+            createResponse(resource, message, errorMsg.toString(), status, methodMatched
== 0);
         throw new WebApplicationException(response);
         
     }    
@@ -437,7 +439,8 @@ public final class JAXRSUtils {
         LOG.fine(errorMsg.toString());
     }
 
-    public static Response createResponse(ClassResourceInfo cri, int status, boolean addAllow)
{
+    public static Response createResponse(ClassResourceInfo cri, Message msg,
+                                          String responseMessage, int status, boolean addAllow)
{
         ResponseBuilder rb = Response.status(status);
         if (addAllow) {
             Set<String> allowedMethods = cri.getAllowedMethods();
@@ -452,6 +455,9 @@ public final class JAXRSUtils {
                 rb.header("Allow", "HEAD");
             }
         }
+        if (msg != null && MessageUtils.isTrue(msg.getContextualProperty(REPORT_FAULT_MESSAGE_PROPERTY)))
{
+            rb.type(MediaType.TEXT_PLAIN_TYPE).entity(responseMessage);
+        }
         return rb.build();
     }
     



Mime
View raw message