You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/02/10 23:43:46 UTC

svn commit: r1566780 [1/2] - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ frontend/jaxrs/src/main/ja...

Author: sergeyb
Date: Mon Feb 10 22:43:44 2014
New Revision: 1566780

URL: http://svn.apache.org/r1566780
Log:
[CXF-5556] Initial updates to get 2.0 exception API not interfering with 1.1 API

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/SpecExceptions.java   (with props)
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/ext/multipart/Attachment.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/lifecycle/PerRequestResourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XPathProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/security/KerberosAuthenticationFilter.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/xmlbeans/XMLBeansElementProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/xmlbeans/XMLBeansJSONProvider.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/services/AuthorizationRequestHandler.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2-saml/src/main/java/org/apache/cxf/rs/security/oauth2/auth/saml/Saml2BearerAuthHandler.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2-saml/src/main/java/org/apache/cxf/rs/security/oauth2/saml/SamlOAuthValidator.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AbstractAccessTokenValidator.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AbstractOAuthService.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AbstractTokenService.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/RedirectionBasedGrantService.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/AuthorizationUtils.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/OAuthContextUtils.java
    cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractServiceProviderFilter.java
    cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/RequestAssertionConsumerService.java
    cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SamlPostBindingFilter.java
    cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SamlRedirectBindingFilter.java
    cxf/trunk/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/AbstractSamlInHandler.java
    cxf/trunk/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlSecInHandler.java
    cxf/trunk/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
    cxf/trunk/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecOutInterceptor.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=1566780&r1=1566779&r2=1566780&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 Feb 10 22:43:44 2014
@@ -28,7 +28,6 @@ import java.util.List;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
-import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.container.AsyncResponse;
 import javax.ws.rs.core.Application;
@@ -52,6 +51,7 @@ import org.apache.cxf.jaxrs.model.Operat
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
@@ -253,7 +253,7 @@ public class JAXRSInvoker extends Abstra
                                                                BUNDLE,
                                                                subResourcePath);
                     LOG.severe(errorM.toString());
-                    throw new NotFoundException();
+                    throw ExceptionUtils.toNotFoundException(null, null);
                 }
 
                 OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(
@@ -335,7 +335,7 @@ public class JAXRSInvoker extends Abstra
         Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(), inMessage);
         if (excResponse == null) {
             inMessage.getExchange().put(Message.PROPOGATE_EXCEPTION, 
-                                        JAXRSUtils.propogateException(inMessage));
+                                        ExceptionUtils.propogateException(inMessage));
             throw ex;
         }
         return new MessageContentsList(excResponse);
@@ -413,7 +413,7 @@ public class JAXRSInvoker extends Abstra
                                                        BUNDLE,
                                                        subResourcePath);
             LOG.info(errorM.toString());
-            throw new NotFoundException();
+            throw ExceptionUtils.toNotFoundException(null, null);
         }
 
         return result;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java Mon Feb 10 22:43:44 2014
@@ -27,7 +27,6 @@ import java.util.List;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -36,6 +35,7 @@ import javax.ws.rs.ext.Providers;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.Transferable;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 /**
@@ -137,7 +137,7 @@ public class Attachment implements Trans
                     return mbr.readFrom(cls, cls, new Annotation[]{}, getContentType(), 
                                         headers, getDataHandler().getInputStream());
                 } catch (Exception ex) {
-                    throw new InternalServerErrorException(ex);
+                    ExceptionUtils.toInternalServerErrorException(ex, null);
                 }
             }
         }

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=1566780&r1=1566779&r2=1566780&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 Feb 10 22:43:44 2014
@@ -27,9 +27,6 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.ws.rs.HttpMethod;
-import javax.ws.rs.InternalServerErrorException;
-import javax.ws.rs.NotAcceptableException;
-import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -50,6 +47,7 @@ import org.apache.cxf.jaxrs.model.ClassR
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
@@ -149,7 +147,7 @@ public class JAXRSInInterceptor extends 
         try {
             acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes, JAXRSUtils.MEDIA_TYPE_Q_PARAM);
         } catch (IllegalArgumentException ex) {
-            throw new NotAcceptableException();
+            throw ExceptionUtils.toNotAcceptableException(null, null);
         }
         message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
 
@@ -166,7 +164,7 @@ public class JAXRSInInterceptor extends 
             LOG.warning(errorMsg.toString());
             Response resp = JAXRSUtils.createResponse(resources, message, errorMsg.toString(), 
                     Response.Status.NOT_FOUND.getStatusCode(), false);
-            throw new NotFoundException(resp);
+            throw ExceptionUtils.toNotFoundException(null, resp);
         }
 
         MultivaluedMap<String, String> matchedValues = new MetadataMap<String, String>();
@@ -224,8 +222,9 @@ public class JAXRSInInterceptor extends 
         if (excResponse == null) {
             ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
             message.getExchange().put(Message.PROPOGATE_EXCEPTION, 
-                                      JAXRSUtils.propogateException(message));
-            throw ex instanceof RuntimeException ? (RuntimeException)ex : new InternalServerErrorException(ex);
+                                      ExceptionUtils.propogateException(message));
+            throw ex instanceof RuntimeException ? (RuntimeException)ex 
+                : ExceptionUtils.toInternalServerErrorException(ex, null);
         }
         message.getExchange().put(Response.class, excResponse);
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java Mon Feb 10 22:43:44 2014
@@ -25,12 +25,13 @@ import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.Map;
 
-import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -81,25 +82,29 @@ public class PerRequestResourceProvider 
             return instance;
         } catch (InstantiationException ex) {
             String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated";
-            throw new InternalServerErrorException(Response.serverError().entity(msg).build());
+            throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg));
         } catch (IllegalAccessException ex) {
             String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated"
                 + " due to IllegalAccessException";
-            throw new InternalServerErrorException(Response.serverError().entity(msg).build());
+            throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg));
         } catch (InvocationTargetException ex) {
             Response r = JAXRSUtils.convertFaultToResponse(ex.getCause(), m);
             if (r != null) {
                 m.getExchange().put(Response.class, r);
-                throw new InternalServerErrorException();
+                throw new WebApplicationException();
             }
             String msg = "Resource class "
                 + c.getDeclaringClass().getName() + " can not be instantiated"
                 + " due to InvocationTargetException";
-            throw new InternalServerErrorException(Response.serverError().entity(msg).build());
+            throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg));
         }
         
     }
 
+    private Response serverError(String msg) {
+        return Response.serverError().entity(msg).build();
+    }
+    
     /**
      * {@inheritDoc}
      */

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java Mon Feb 10 22:43:44 2014
@@ -38,8 +38,6 @@ import java.util.ResourceBundle;
 import java.util.Set;
 import java.util.logging.Logger;
 
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -75,6 +73,7 @@ import org.apache.cxf.common.logging.Log
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -694,7 +693,9 @@ public abstract class AbstractJAXBProvid
             ? Response.Status.BAD_REQUEST : Response.Status.INTERNAL_SERVER_ERROR; 
         Response r = Response.status(status)
             .type(MediaType.TEXT_PLAIN).entity(message).build();
-        throw read ? new BadRequestException(r, t) : new InternalServerErrorException(r, t);
+        WebApplicationException ex = read ? ExceptionUtils.toBadRequestException(t, r) 
+            : ExceptionUtils.toInternalServerErrorException(t, r);
+        throw ex;
     }
     
     protected void handleJAXBException(JAXBException e, boolean read) {
@@ -798,7 +799,7 @@ public abstract class AbstractJAXBProvid
                         ? Integer.valueOf(innerElementCountStr) : -1;
                     return new DocumentDepthProperties(totalElementCount, elementLevel, innerElementCount);
                 } catch (Exception ex) {
-                    throw new InternalServerErrorException(ex);
+                    throw ExceptionUtils.toInternalServerErrorException(ex, null);
                 }
             }
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java Mon Feb 10 22:43:44 2014
@@ -26,13 +26,14 @@ import java.lang.reflect.Type;
 import java.util.Collections;
 import java.util.List;
 
-import javax.ws.rs.NotAcceptableException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.Provider;
 
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+
 @Provider
 public class CachingMessageBodyReader<T> extends AbstractCachingMessageProvider<T>
     implements MessageBodyReader<T> {
@@ -84,7 +85,7 @@ public class CachingMessageBodyReader<T>
             org.apache.cxf.common.i18n.Message message = 
                 new org.apache.cxf.common.i18n.Message("NO_MSG_READER", BUNDLE, type);
             LOG.severe(message.toString());
-            throw new NotAcceptableException();
+            throw ExceptionUtils.toNotAcceptableException(null, null);
         }
         return r;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java Mon Feb 10 22:43:44 2014
@@ -26,13 +26,14 @@ import java.lang.reflect.Type;
 import java.util.Collections;
 import java.util.List;
 
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+
 @Provider
 public class CachingMessageBodyWriter<T> extends AbstractCachingMessageProvider<T>
     implements MessageBodyWriter<T> {
@@ -87,7 +88,7 @@ public class CachingMessageBodyWriter<T>
             org.apache.cxf.common.i18n.Message message = 
                 new org.apache.cxf.common.i18n.Message("NO_MSG_WRITER", BUNDLE, type);
             LOG.severe(message.toString());
-            throw new InternalServerErrorException();
+            throw ExceptionUtils.toInternalServerErrorException(null, null);
         }
         return w;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java Mon Feb 10 22:43:44 2014
@@ -24,9 +24,7 @@ import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 
-import javax.ws.rs.BadRequestException;
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -40,6 +38,7 @@ import javax.xml.stream.XMLStreamWriter;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 
 @Provider
@@ -74,7 +73,7 @@ public class DataBindingProvider<T> impl
             Object o = dataReader.read(null, reader, clazz);
             return o == null ? null : clazz.cast(o);
         } catch (Exception ex) {
-            throw new BadRequestException(ex);
+            throw ExceptionUtils.toBadRequestException(ex, null);
         } finally {
             try {
                 StaxUtils.close(reader);
@@ -108,7 +107,7 @@ public class DataBindingProvider<T> impl
             writer = createWriter(clazz, genericType, os);
             writeToWriter(writer, o);
         } catch (Exception ex) {
-            throw new InternalServerErrorException(ex);
+            throw ExceptionUtils.toInternalServerErrorException(ex, null);
         } finally {
             StaxUtils.close(writer);
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java Mon Feb 10 22:43:44 2014
@@ -25,7 +25,6 @@ import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 
-import javax.ws.rs.BadRequestException;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.Produces;
@@ -43,6 +42,7 @@ import org.apache.cxf.jaxrs.ext.multipar
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.FormUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
@@ -123,7 +123,7 @@ public class FormEncodingProvider<T> imp
         } catch (WebApplicationException e) {
             throw e;
         } catch (Exception e) {
-            throw new BadRequestException(e);
+            throw ExceptionUtils.toBadRequestException(e, null);
         }
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java Mon Feb 10 22:43:44 2014
@@ -34,9 +34,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import javax.ws.rs.BadRequestException;
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -65,6 +63,7 @@ import org.apache.cxf.jaxrs.ext.xml.XMLI
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.ext.xml.XSISchemaLocation;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXBUtils;
@@ -203,7 +202,7 @@ public class JAXBElementProvider<T> exte
             throw e;
         } catch (Exception e) {
             LOG.warning(getStackTrace(e));
-            throw new BadRequestException(e);        
+            throw ExceptionUtils.toBadRequestException(e, null);        
         } finally {
             try {
                 StaxUtils.close(reader);
@@ -243,8 +242,8 @@ public class JAXBElementProvider<T> exte
                 try {
                     reader = factory.createXMLStreamReader(is);
                 } catch (XMLStreamException e) {
-                    throw new InternalServerErrorException(
-                        new RuntimeException("Can not create XMLStreamReader", e));
+                    throw ExceptionUtils.toInternalServerErrorException(
+                        new RuntimeException("Can not create XMLStreamReader", e), null);
                 }
             }
         }
@@ -272,7 +271,7 @@ public class JAXBElementProvider<T> exte
                 Reader reader = getStreamHandlerFromCurrentMessage(Reader.class);
                 if (reader == null) {
                     LOG.severe("No InputStream, Reader, or XMLStreamReader is available");
-                    throw new InternalServerErrorException();
+                    throw ExceptionUtils.toInternalServerErrorException(null, null);
                 }
                 xmlReader = StaxUtils.createXMLStreamReader(reader);
             } else {
@@ -312,7 +311,7 @@ public class JAXBElementProvider<T> exte
             throw e;
         } catch (Exception e) {
             e.printStackTrace();
-            throw new InternalServerErrorException(e);        
+            throw ExceptionUtils.toInternalServerErrorException(e, null);        
         }
     }
 
@@ -559,8 +558,8 @@ public class JAXBElementProvider<T> exte
                     try {
                         writer = factory.createXMLStreamWriter(os);
                     } catch (XMLStreamException e) {
-                        throw new InternalServerErrorException(
-                            new RuntimeException("Cant' create XMLStreamWriter", e));
+                        throw ExceptionUtils.toInternalServerErrorException(
+                            new RuntimeException("Cant' create XMLStreamWriter", e), null);
                     }
                 }
             }
@@ -581,7 +580,7 @@ public class JAXBElementProvider<T> exte
             Writer writer = getStreamHandlerFromCurrentMessage(Writer.class);
             if (writer == null) {
                 LOG.severe("No OutputStream, Writer, or XMLStreamWriter is available");
-                throw new InternalServerErrorException();
+                throw ExceptionUtils.toInternalServerErrorException(null, null);
             }
             ms.marshal(obj, writer);
             writer.flush();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java Mon Feb 10 22:43:44 2014
@@ -40,9 +40,7 @@ import java.util.logging.Logger;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
-import javax.ws.rs.BadRequestException;
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -66,6 +64,7 @@ import org.apache.cxf.jaxrs.ext.multipar
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
@@ -191,7 +190,7 @@ public class MultipartProvider extends A
             return defaultValue;
         }
         
-        throw new BadRequestException();
+        throw ExceptionUtils.toBadRequestException(null, null);
         
     }
     
@@ -394,7 +393,7 @@ public class MultipartProvider extends A
                                                    BUNDLE,
                                                    cls);
             LOG.severe(message.toString());
-            throw new InternalServerErrorException();
+            throw ExceptionUtils.toInternalServerErrorException(null, null);
         }
         
         return new MessageBodyWriterDataHandler<T>(r, obj, cls, genericType, anns, mt);
@@ -459,7 +458,7 @@ public class MultipartProvider extends A
                 writer.writeTo(obj, cls, genericType, anns, contentType, 
                                new MetadataMap<String, Object>(), os);
             } catch (IOException ex) {
-                throw new InternalServerErrorException(ex);
+                throw ExceptionUtils.toInternalServerErrorException(ex, null); 
             }
         }
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java Mon Feb 10 22:43:44 2014
@@ -34,7 +34,6 @@ import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
@@ -47,6 +46,7 @@ import javax.ws.rs.ext.Provider;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
@@ -194,7 +194,7 @@ public class RequestDispatcherProvider e
         } catch (Throwable ex) {
             mc.put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.FALSE);
             ex.printStackTrace();
-            throw new InternalServerErrorException(ex);
+            throw ExceptionUtils.toInternalServerErrorException(ex, null); 
         }
     }
 
@@ -270,7 +270,7 @@ public class RequestDispatcherProvider e
                     new org.apache.cxf.common.i18n.Message("RESOURCE_DISPATCH_NOT_FOUND", 
                                                            BUNDLE, servletContextPath).toString();
                 LOG.severe(message);
-                throw new InternalServerErrorException();
+                throw ExceptionUtils.toInternalServerErrorException(null, null);
             }
         }
         return sc; 
@@ -285,7 +285,7 @@ public class RequestDispatcherProvider e
                 new org.apache.cxf.common.i18n.Message("RESOURCE_PATH_NOT_FOUND", 
                                                        BUNDLE, path).toString();
             LOG.severe(message);
-            throw new InternalServerErrorException();
+            throw ExceptionUtils.toInternalServerErrorException(null, null);
         }
         return rd;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java Mon Feb 10 22:43:44 2014
@@ -26,7 +26,6 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -48,6 +47,7 @@ import org.w3c.dom.Document;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.staxutils.DepthExceededStaxException;
 import org.apache.cxf.staxutils.StaxSource;
@@ -166,7 +166,7 @@ public class SourceProvider<T> extends A
         try {
             StaxUtils.copy(reader, writer);
         } catch (XMLStreamException e) {
-            throw new InternalServerErrorException(e);
+            throw ExceptionUtils.toInternalServerErrorException(e, null); 
         } finally {
             try {
                 reader.close();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XPathProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XPathProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XPathProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XPathProvider.java Mon Feb 10 22:43:44 2014
@@ -27,7 +27,6 @@ import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -35,6 +34,7 @@ import javax.ws.rs.ext.MessageBodyReader
 import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 
 @Provider
 @Consumes({"text/xml", "application/xml", "application/*+xml" })
@@ -89,7 +89,7 @@ public class XPathProvider<T> implements
             : classExpressions.get(cls.getName());
         if (expression == null) {
             // must not happen if isReadable() returned true
-            throw new InternalServerErrorException();
+            throw ExceptionUtils.toInternalServerErrorException(null, null);
         }
         XMLSource source = new XMLSource(is);
         if (forceDOM) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java Mon Feb 10 22:43:44 2014
@@ -32,9 +32,7 @@ import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.ws.rs.BadRequestException;
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -65,6 +63,7 @@ import org.xml.sax.XMLFilter;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.staxutils.StaxSource;
@@ -186,7 +185,7 @@ public class XSLTJaxbProvider<T> extends
             return unmarshaller.unmarshal(source);
         } catch (TransformerConfigurationException ex) {
             LOG.warning("Transformation exception : " + ex.getMessage());
-            throw new InternalServerErrorException(ex);
+            throw ExceptionUtils.toInternalServerErrorException(ex, null); 
         }
     }
     
@@ -220,7 +219,7 @@ public class XSLTJaxbProvider<T> extends
             writer.close();
             return unmarshalFromInputStream(unmarshaller, out.getInputStream(), mt);
         } catch (Exception ex) {
-            throw new BadRequestException(ex);
+            throw ExceptionUtils.toBadRequestException(ex, null);
         }
     }
     
@@ -343,7 +342,7 @@ public class XSLTJaxbProvider<T> extends
                 return null;
             } else {
                 LOG.severe("No template is available");
-                throw new InternalServerErrorException();
+                throw ExceptionUtils.toInternalServerErrorException(null, null);
             }
         }
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/security/KerberosAuthenticationFilter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/security/KerberosAuthenticationFilter.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/security/KerberosAuthenticationFilter.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/security/KerberosAuthenticationFilter.java Mon Feb 10 22:43:44 2014
@@ -28,7 +28,6 @@ import javax.security.auth.callback.Call
 import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
-import javax.ws.rs.NotAuthorizedException;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.PreMatching;
@@ -43,6 +42,7 @@ import org.apache.cxf.common.util.Base64
 import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
@@ -75,12 +75,12 @@ public class KerberosAuthenticationFilte
             .getRequestHeader(HttpHeaders.AUTHORIZATION);
         if (authHeaders.size() != 1) {
             LOG.fine("No Authorization header is available");
-            throw new NotAuthorizedException(getFaultResponse());
+            throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
         }
         String[] authPair = StringUtils.split(authHeaders.get(0), " ");
         if (authPair.length != 2 || !NEGOTIATE_SCHEME.equalsIgnoreCase(authPair[0])) {
             LOG.fine("Negotiate Authorization scheme is expected");
-            throw new NotAuthorizedException(getFaultResponse());
+            throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
         }
                 
         byte[] serviceTicket = getServiceTicket(authPair[1]);
@@ -94,7 +94,7 @@ public class KerberosAuthenticationFilte
             
             GSSName srcName = gssContext.getSrcName();
             if (srcName == null) {
-                throw new NotAuthorizedException(getFaultResponse());
+                throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
             }
             
             String complexUserName = srcName.toString();
@@ -116,13 +116,13 @@ public class KerberosAuthenticationFilte
             
         } catch (LoginException e) {
             LOG.fine("Unsuccessful JAAS login for the service principal: " + e.getMessage());
-            throw new NotAuthorizedException(getFaultResponse(), e);
+            throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
         } catch (GSSException e) {
             LOG.fine("GSS API exception: " + e.getMessage());
-            throw new NotAuthorizedException(getFaultResponse(), e);
+            throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
         } catch (PrivilegedActionException e) {
             LOG.fine("PrivilegedActionException: " + e.getMessage());
-            throw new NotAuthorizedException(getFaultResponse(), e);
+            throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
         }
     }
 
@@ -163,7 +163,7 @@ public class KerberosAuthenticationFilte
         try {
             return Base64Utility.decode(encodedServiceTicket);
         } catch (Base64Exception ex) {
-            throw new NotAuthorizedException(getFaultResponse());
+            throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
         }
     }
     

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java?rev=1566780&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java Mon Feb 10 22:43:44 2014
@@ -0,0 +1,154 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.utils;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
+
+public final class ExceptionUtils {
+    private static final String PROPAGATE_EXCEPTION = "org.apache.cxf.propagate.exception";
+    private static final String  SUPPORT_WAE_SPEC_OPTIMIZATION = "support.wae.spec.optimization";
+    
+    private ExceptionUtils() {        
+    }
+    
+    public static Class<?> getWebApplicationExceptionClass(Response exResponse,
+                                                           Class<?> defaultExceptionType) {
+        return SpecExceptions.getWebApplicationExceptionClass(exResponse, defaultExceptionType);
+    }
+    
+     
+    public static boolean propogateException(Message m) {
+        
+        Object value = m.getContextualProperty(PROPAGATE_EXCEPTION);
+        
+        if (value == null) {
+            return true;
+        }
+
+        if (Boolean.TRUE.equals(value) || "true".equalsIgnoreCase(value.toString())) {
+            return true;
+        }
+        
+        return false;
+    }
+    
+    
+    public static <T extends Throwable> Response convertFaultToResponse(T ex, Message currentMessage) {
+        if (ex == null || currentMessage == null) {
+            return null;
+        }
+        Message inMessage = currentMessage.getExchange().getInMessage();
+        Response response = null;
+        if (ex.getClass() == WebApplicationException.class) {
+            WebApplicationException webEx = (WebApplicationException)ex;
+            if (webEx.getResponse().hasEntity() 
+                && webEx.getCause() == null) {
+                Object prop = inMessage.getContextualProperty(SUPPORT_WAE_SPEC_OPTIMIZATION);
+                if (prop == null || MessageUtils.isTrue(prop)) {
+                    response = webEx.getResponse();
+                }
+            }
+        }
+        
+        if (response == null) {
+            ExceptionMapper<T>  mapper =
+                ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage);
+            if (mapper != null) {
+                try {
+                    response = mapper.toResponse(ex);
+                } catch (Exception mapperEx) {
+                    inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
+                    mapperEx.printStackTrace();
+                    return Response.serverError().build();
+                }
+            }
+        }
+        JAXRSUtils.setMessageContentType(currentMessage, response);
+        return response;
+    }
+    
+    public static WebApplicationException toWebApplicationException(Throwable cause, Response response) {
+        return new WebApplicationException(cause);
+    }
+    
+    //TODO: we can simply use the reflection, investigate 
+    
+    public static WebApplicationException toInternalServerErrorException(Throwable cause, Response response) {
+        try {
+            return SpecExceptions.toInternalServerErrorException(cause, response);
+        } catch (NoClassDefFoundError ex) { 
+            return toWebApplicationException(ex, response);
+        }
+    }
+    
+    public static WebApplicationException toBadRequestException(Throwable cause, Response response) {
+        try {
+            return SpecExceptions.toBadRequestException(cause, response);
+        } catch (NoClassDefFoundError ex) { 
+            return toWebApplicationException(ex, response);
+        }
+    }
+    
+    public static WebApplicationException toNotFoundException(Throwable cause, Response response) {
+        try {
+            return SpecExceptions.toNotFoundException(cause, response);
+        } catch (NoClassDefFoundError ex) { 
+            return toWebApplicationException(ex, response);
+        }
+    }
+    
+    public static WebApplicationException toNotAuthorizedException(Throwable cause, Response response) {
+        try {
+            return SpecExceptions.toNotAuthorizedException(cause, response);
+        } catch (NoClassDefFoundError ex) { 
+            return toWebApplicationException(ex, response);
+        }
+    }
+    
+    public static WebApplicationException toNotAcceptableException(Throwable cause, Response response) {
+        try {
+            return SpecExceptions.toNotAcceptableException(cause, response);
+        } catch (NoClassDefFoundError ex) { 
+            return toWebApplicationException(ex, response);
+        }
+    }
+    
+    public static WebApplicationException toNotSupportedException(Throwable cause, Response response) {
+        try {
+            return SpecExceptions.toNotSupportedException(cause, response);
+        } catch (NoClassDefFoundError ex) { 
+            return toWebApplicationException(ex, response);
+        }
+    }
+    
+    public static WebApplicationException toHttpException(Throwable cause, Response response) {
+        try {
+            return SpecExceptions.toHttpException(cause, response);
+        } catch (NoClassDefFoundError ex) { 
+            return toWebApplicationException(ex, response);
+        }
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java Mon Feb 10 22:43:44 2014
@@ -31,8 +31,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
 
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Form;
 import javax.ws.rs.core.MediaType;
@@ -117,7 +115,7 @@ public final class FormUtils {
             IOUtils.copy(is, bos, 1024);
             return new String(bos.toByteArray(), encoding);
         } catch (Exception ex) {
-            throw new InternalServerErrorException(ex);
+            throw ExceptionUtils.toInternalServerErrorException(ex, null);
         }
     }
     
@@ -214,7 +212,7 @@ public final class FormUtils {
             String contentId = a.getContentId();
             String name = StringUtils.isEmpty(cdName) ? contentId : cdName.replace("\"", "").replace("'", "");
             if (StringUtils.isEmpty(name)) { 
-                throw new BadRequestException();
+                throw ExceptionUtils.toBadRequestException(null, null);
             }
             if (CONTENT_DISPOSITION_FILES_PARAM.equals(name)) {
                 // this is a reserved name in Content-Disposition for parts containing files
@@ -227,9 +225,9 @@ public final class FormUtils {
             } catch (IllegalArgumentException ex) {
                 LOG.warning("Illegal URL-encoded characters, make sure that no "
                     + "@FormParam and @Multipart annotations are mixed up");
-                throw new InternalServerErrorException();
+                throw ExceptionUtils.toInternalServerErrorException(ex, null);
             } catch (IOException ex) {
-                throw new BadRequestException();
+                throw ExceptionUtils.toBadRequestException(null, null);
             }
         }
     }
@@ -249,7 +247,7 @@ public final class FormUtils {
                 throw new WebApplicationException(413);
             }
         } catch (NumberFormatException ex) {
-            throw new InternalServerErrorException();
+            throw ExceptionUtils.toInternalServerErrorException(ex, null);
         }
     }
 }

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=1566780&r1=1566779&r2=1566780&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 Mon Feb 10 22:43:44 2014
@@ -49,10 +49,6 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.logging.Logger;
 
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.ClientErrorException;
-import javax.ws.rs.InternalServerErrorException;
-import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.GenericEntity;
@@ -308,7 +304,7 @@ public final class InjectionUtils {
             Response r = JAXRSUtils.convertFaultToResponse(ex.getCause(), inMessage);
             if (r != null) {
                 inMessage.getExchange().put(Response.class, r);
-                throw new InternalServerErrorException();
+                throw new WebApplicationException();
             }
             reportServerError("METHOD_ACCESS_FAILURE", method.getName());
         } catch (Exception ex) {
@@ -374,9 +370,9 @@ public final class InjectionUtils {
                 //
                 if (pType == ParameterType.PATH || pType == ParameterType.QUERY
                     || pType == ParameterType.MATRIX) {
-                    throw new NotFoundException(nfe);
+                    throw ExceptionUtils.toNotFoundException(nfe, null);
                 }
-                throw new BadRequestException(nfe);
+                throw ExceptionUtils.toBadRequestException(nfe, null);
             }
         }
         
@@ -403,7 +399,8 @@ public final class InjectionUtils {
             LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_CONSTRUCTOR_FAILURE", 
                                                                BUNDLE, 
                                                                pClass.getName()).toString());
-            throw new ClientErrorException(HttpUtils.getParameterFailureStatus(pType), t);
+            Response r = JAXRSUtils.toResponse(HttpUtils.getParameterFailureStatus(pType));
+            throw ExceptionUtils.toHttpException(t, r);
         }
         if (result == null) {
             // check for valueOf(String) static methods
@@ -465,7 +462,7 @@ public final class InjectionUtils {
         Response r = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                          .type(MediaType.TEXT_PLAIN_TYPE)
                          .entity(errorMessage.toString()).build();
-        throw new InternalServerErrorException(r);
+        throw ExceptionUtils.toInternalServerErrorException(null, r);
     }
     
     private static <T> T evaluateFactoryMethod(String value,
@@ -1248,7 +1245,8 @@ public final class InjectionUtils {
             } catch (IllegalAccessException ex) {
                 String msg = "Method " + method.getName() + " can not be invoked"
                     + " due to IllegalAccessException";
-                throw new InternalServerErrorException(Response.serverError().entity(msg).build());
+                throw ExceptionUtils.toInternalServerErrorException(ex, 
+                                                                    Response.serverError().entity(msg).build());
             } 
         }
     }

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=1566780&r1=1566779&r2=1566780&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 Feb 10 22:43:44 2014
@@ -31,7 +31,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -49,21 +48,9 @@ import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.ClientErrorException;
 import javax.ws.rs.Consumes;
-import javax.ws.rs.ForbiddenException;
 import javax.ws.rs.HttpMethod;
-import javax.ws.rs.InternalServerErrorException;
-import javax.ws.rs.NotAcceptableException;
-import javax.ws.rs.NotAllowedException;
-import javax.ws.rs.NotAuthorizedException;
-import javax.ws.rs.NotFoundException;
-import javax.ws.rs.NotSupportedException;
 import javax.ws.rs.Produces;
-import javax.ws.rs.RedirectionException;
-import javax.ws.rs.ServerErrorException;
-import javax.ws.rs.ServiceUnavailableException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.container.AsyncResponse;
 import javax.ws.rs.container.ContainerRequestContext;
@@ -79,7 +66,6 @@ import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.NoContentException;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
@@ -87,7 +73,6 @@ import javax.ws.rs.core.Response.Respons
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ContextResolver;
-import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Providers;
@@ -174,22 +159,8 @@ 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 PATH_SEGMENT_SEP = "/";
-    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 static final String  SUPPORT_WAE_SPEC_OPTIMIZATION = "support.wae.spec.optimization";
-    private static final Map<Integer, Class<?>> EXCEPTIONS_MAP;
-    static {
-        EXCEPTIONS_MAP = new HashMap<Integer, Class<?>>();
-        EXCEPTIONS_MAP.put(400, BadRequestException.class);
-        EXCEPTIONS_MAP.put(401, NotAuthorizedException.class);
-        EXCEPTIONS_MAP.put(403, ForbiddenException.class);
-        EXCEPTIONS_MAP.put(404, NotFoundException.class);
-        EXCEPTIONS_MAP.put(405, NotAllowedException.class);
-        EXCEPTIONS_MAP.put(406, NotAcceptableException.class);
-        EXCEPTIONS_MAP.put(415, NotSupportedException.class);
-        EXCEPTIONS_MAP.put(500, InternalServerErrorException.class);
-        EXCEPTIONS_MAP.put(503, ServiceUnavailableException.class);
-    }
+    private static final String NO_CONTENT_EXCEPTION = "javax.ws.rs.core.NoContentException";
     
     private JAXRSUtils() {        
     }
@@ -407,7 +378,7 @@ public final class JAXRSUtils {
         try {
             requestType = toMediaType(requestContentType);
         } catch (IllegalArgumentException ex) {
-            throw new NotSupportedException(ex);
+            throw ExceptionUtils.toNotSupportedException(ex, null);
         }
         
         SortedMap<OperationResourceInfo, MultivaluedMap<String, String>> candidateList = 
@@ -538,7 +509,7 @@ public final class JAXRSUtils {
         }
         Response response = 
             createResponse(getRootResources(message), message, errorMsg.toString(), status, methodMatched == 0);
-        throw new ClientErrorException(response);
+        throw ExceptionUtils.toHttpException(null, response);
         
     }    
 
@@ -966,7 +937,7 @@ public final class JAXRSUtils {
                                                                BUNDLE, 
                                                                mt.toString());
                     LOG.warning(errorMsg.toString());
-                    throw new NotSupportedException();
+                    throw ExceptionUtils.toNotSupportedException(null, null);
                 }
             }
         }
@@ -1053,13 +1024,13 @@ public final class JAXRSUtils {
             // is available indicates that the one created at start up has been 
             // lost and hence it is 500
             LOG.warning("Bean parameter info is not available");
-            throw new InternalServerErrorException();
+            throw ExceptionUtils.toInternalServerErrorException(null, null);
         }
         Object instance;
         try {
             instance = ClassLoaderUtils.loadClass(clazz.getName(), JAXRSUtils.class).newInstance();
         } catch (Throwable t) {
-            throw new InternalServerErrorException(t);
+            throw ExceptionUtils.toInternalServerErrorException(t, null); 
         }
         JAXRSUtils.injectParameters(ori, bmi, instance, m);
         
@@ -1295,10 +1266,12 @@ public final class JAXRSUtils {
                                                      is, 
                                                      type,
                                                      m);    
-                } catch (NoContentException e) {
-                    throw new BadRequestException(e);
                 } catch (IOException e) {
-                    throw e;
+                    if (e.getClass().getName().equals(NO_CONTENT_EXCEPTION)) {
+                        throw ExceptionUtils.toBadRequestException(e, null);    
+                    } else {
+                        throw e;
+                    }
                 } catch (WebApplicationException ex) {
                     throw ex;
                 } catch (Exception ex) {
@@ -1593,55 +1566,9 @@ public final class JAXRSUtils {
         return types;
     }
     
-    public static Class<?> getWebApplicationExceptionClass(Response exResponse,
-                                                           Class<?> defaultExceptionType) {
-        int status = exResponse.getStatus();
-        Class<?> cls = EXCEPTIONS_MAP.get(status);
-        if (cls == null) {
-            int family = status / 100;
-            if (family == 3) {
-                cls = RedirectionException.class;
-            } else if (family == 4) {
-                cls = ClientErrorException.class;
-            } else if (family == 5) {
-                cls = ServerErrorException.class;
-            }
-        }
-        return cls == null ? defaultExceptionType : cls;
-    }
-    
+
     public static <T extends Throwable> Response convertFaultToResponse(T ex, Message currentMessage) {
-        if (ex == null || currentMessage == null) {
-            return null;
-        }
-        Message inMessage = currentMessage.getExchange().getInMessage();
-        Response response = null;
-        if (ex.getClass() == WebApplicationException.class) {
-            WebApplicationException webEx = (WebApplicationException)ex;
-            if (webEx.getResponse().hasEntity() 
-                && webEx.getCause() == null) {
-                Object prop = inMessage.getContextualProperty(SUPPORT_WAE_SPEC_OPTIMIZATION);
-                if (prop == null || MessageUtils.isTrue(prop)) {
-                    response = webEx.getResponse();
-                }
-            }
-        }
-        
-        if (response == null) {
-            ExceptionMapper<T>  mapper =
-                ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage);
-            if (mapper != null) {
-                try {
-                    response = mapper.toResponse(ex);
-                } catch (Exception mapperEx) {
-                    inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
-                    mapperEx.printStackTrace();
-                    return Response.serverError().build();
-                }
-            }
-        }
-        setMessageContentType(currentMessage, response);
-        return response;
+        return ExceptionUtils.convertFaultToResponse(ex, currentMessage);
     }
     
     public static void setMessageContentType(Message message, Response response) {
@@ -1659,21 +1586,6 @@ public final class JAXRSUtils {
         
     }
     
-    public static boolean propogateException(Message m) {
-        
-        Object value = m.getContextualProperty(PROPAGATE_EXCEPTION);
-        
-        if (value == null) {
-            return true;
-        }
-
-        if (Boolean.TRUE.equals(value) || "true".equalsIgnoreCase(value.toString())) {
-            return true;
-        }
-        
-        return false;
-    }
-    
     public static QName getClassQName(Class<?> type) {
         String nsURI = PackageUtils.getNamespace(PackageUtils.getPackageName(type));
         if (nsURI.endsWith("/")) {
@@ -1700,7 +1612,7 @@ public final class JAXRSUtils {
                     InjectionUtils.injectContexts(filter.getProvider(), filter, m);
                     filter.getProvider().filter(context);
                 } catch (IOException ex) {
-                    throw new InternalServerErrorException(ex);
+                    throw ExceptionUtils.toInternalServerErrorException(ex, null); 
                 }
                 Response response = m.getExchange().get(Response.class);
                 if (response != null) {

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/SpecExceptions.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/SpecExceptions.java?rev=1566780&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/SpecExceptions.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/SpecExceptions.java Mon Feb 10 22:43:44 2014
@@ -0,0 +1,123 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.ClientErrorException;
+import javax.ws.rs.ForbiddenException;
+import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.NotAcceptableException;
+import javax.ws.rs.NotAllowedException;
+import javax.ws.rs.NotAuthorizedException;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.NotSupportedException;
+import javax.ws.rs.RedirectionException;
+import javax.ws.rs.ServerErrorException;
+import javax.ws.rs.ServiceUnavailableException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+public final class SpecExceptions {
+    
+    private static final Map<Integer, Class<?>> EXCEPTIONS_MAP;
+    
+    static {
+        EXCEPTIONS_MAP = new HashMap<Integer, Class<?>>();
+        EXCEPTIONS_MAP.put(400, BadRequestException.class);
+        EXCEPTIONS_MAP.put(401, NotAuthorizedException.class);
+        EXCEPTIONS_MAP.put(403, ForbiddenException.class);
+        EXCEPTIONS_MAP.put(404, NotFoundException.class);
+        EXCEPTIONS_MAP.put(405, NotAllowedException.class);
+        EXCEPTIONS_MAP.put(406, NotAcceptableException.class);
+        EXCEPTIONS_MAP.put(415, NotSupportedException.class);
+        EXCEPTIONS_MAP.put(500, InternalServerErrorException.class);
+        EXCEPTIONS_MAP.put(503, ServiceUnavailableException.class);
+    }
+    
+    private SpecExceptions() {        
+    }
+    
+    public static Class<?> getWebApplicationExceptionClass(Response exResponse,
+                                                           Class<?> defaultExceptionType) {
+        int status = exResponse.getStatus();
+        Class<?> cls = EXCEPTIONS_MAP.get(status);
+        if (cls == null) {
+            int family = status / 100;
+            if (family == 3) {
+                cls = RedirectionException.class;
+            } else if (family == 4) {
+                cls = ClientErrorException.class;
+            } else if (family == 5) {
+                cls = ServerErrorException.class;
+            }
+        }
+        return cls == null ? defaultExceptionType : cls;
+    }
+    
+    public static InternalServerErrorException toInternalServerErrorException(Throwable cause, Response response) {
+        
+        return new InternalServerErrorException(checkResponse(response, 500), cause);
+    }
+    
+    public static BadRequestException toBadRequestException(Throwable cause, Response response) {
+        
+        return new BadRequestException(checkResponse(response, 400), cause);
+    }
+    
+    public static NotFoundException toNotFoundException(Throwable cause, Response response) {
+        
+        return new NotFoundException(checkResponse(response, 404), cause);
+    }
+    
+    public static NotAuthorizedException toNotAuthorizedException(Throwable cause, Response response) {
+        
+        return new NotAuthorizedException(checkResponse(response, 401), cause);
+    }
+    
+    public static NotAcceptableException toNotAcceptableException(Throwable cause, Response response) {
+        
+        return new NotAcceptableException(checkResponse(response, 406), cause);
+    }
+    
+    public static NotSupportedException toNotSupportedException(Throwable cause, Response response) {
+        
+        return new NotSupportedException(checkResponse(response, 415), cause);
+    }
+    
+    public static WebApplicationException toHttpException(Throwable cause, Response response) {
+        
+        if (response == null) {
+            throw new WebApplicationException(cause);
+        }
+        throw response.getStatus() >= 500 ? new ServerErrorException(response, cause) 
+            : new ClientErrorException(response, cause);
+    }
+    
+    private static Response checkResponse(Response r, int status) {
+        if (r == null) {
+            return JAXRSUtils.toResponse(status);
+        } else {
+            return r;
+        }
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/SpecExceptions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/SpecExceptions.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java Mon Feb 10 22:43:44 2014
@@ -27,8 +27,6 @@ import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.NotSupportedException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 
@@ -41,6 +39,7 @@ import org.apache.cxf.jaxrs.ext.multipar
 import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.FormUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.phase.PhaseInterceptorChain;
@@ -141,8 +140,8 @@ public final class AttachmentUtils {
                                                            id.value(),
                                                            mt.toString());
                 LOG.warning(errorMsg.toString());
-                throw new BadRequestException(
-                          new MultipartReadException(id.value(), id.type(), errorMsg.toString()));
+                throw ExceptionUtils.toBadRequestException(
+                          new MultipartReadException(id.value(), id.type(), errorMsg.toString()), null);
             } else {
                 return null;
             }
@@ -230,7 +229,7 @@ public final class AttachmentUtils {
     
     private static void checkMediaTypes(MediaType mt1, String mt2) {
         if (!mt1.isCompatible(JAXRSUtils.toMediaType(mt2))) {                                            
-            throw new NotSupportedException();
+            throw ExceptionUtils.toNotSupportedException(null, null);
         }
     }
 }

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java (original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java Mon Feb 10 22:43:44 2014
@@ -31,7 +31,6 @@ import java.util.WeakHashMap;
 import java.util.logging.Handler;
 
 import javax.ws.rs.GET;
-import javax.ws.rs.NotFoundException;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -48,6 +47,7 @@ import org.apache.cxf.jaxrs.ext.search.P
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
 import org.apache.cxf.jaxrs.ext.search.SearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.SearchContext;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.management.web.logging.LogLevel;
 import org.apache.cxf.management.web.logging.LogRecord;
 import org.apache.cxf.management.web.logging.ReadWriteLogStorage;
@@ -228,7 +228,7 @@ public class AtomPullServer extends Abst
             list.add(records.get(index));
         }
         if (list.size() != 1) { 
-            throw new NotFoundException();
+            throw ExceptionUtils.toNotFoundException(null, null);
         }
         return list;
     }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Mon Feb 10 22:43:44 2014
@@ -73,6 +73,7 @@ import org.apache.cxf.jaxrs.impl.UriBuil
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -463,9 +464,9 @@ public abstract class AbstractClient imp
     }
     
     protected WebApplicationException convertToWebApplicationException(Response r) {
-        Class<?> exceptionClass = JAXRSUtils.getWebApplicationExceptionClass(r, 
-                                       WebApplicationException.class);
         try {
+            Class<?> exceptionClass = ExceptionUtils.getWebApplicationExceptionClass(r, 
+                                       WebApplicationException.class);
             Constructor<?> ctr = exceptionClass.getConstructor(Response.class);
             return (WebApplicationException)ctr.newInstance(r);
         } catch (Throwable ex2) {

Modified: cxf/trunk/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java (original)
+++ cxf/trunk/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java Mon Feb 10 22:43:44 2014
@@ -47,8 +47,6 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Logger;
 
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.HttpHeaders;
@@ -103,6 +101,7 @@ import org.apache.cxf.jaxrs.model.Resour
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -276,7 +275,7 @@ public class WadlGenerator implements Co
         try {
             return StaxUtils.read(new StringReader(entity));
         } catch (Exception ex) {
-            throw new InternalServerErrorException(ex);
+            throw ExceptionUtils.toInternalServerErrorException(ex, null);
         }
     }
 
@@ -991,7 +990,7 @@ public class WadlGenerator implements Co
 
                     }
                 } catch (Exception ex) {
-                    throw new InternalServerErrorException(ex);
+                    throw ExceptionUtils.toInternalServerErrorException(ex, null); 
                 }
             }
         }
@@ -1035,7 +1034,7 @@ public class WadlGenerator implements Co
                         .build();
                 }
             } catch (Exception ex) {
-                throw new BadRequestException();
+                throw ExceptionUtils.toBadRequestException(null, null);
             }
 
         }

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java (original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java Mon Feb 10 22:43:44 2014
@@ -27,9 +27,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 
-import javax.ws.rs.BadRequestException;
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -43,6 +41,7 @@ import org.apache.cxf.aegis.AegisContext
 import org.apache.cxf.aegis.AegisReader;
 import org.apache.cxf.aegis.AegisWriter;
 import org.apache.cxf.aegis.type.AegisType;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 
 @Provider
@@ -71,12 +70,12 @@ public class AegisElementProvider<T> ext
             xmlStreamReader = createStreamReader(typeToRead, is);
             return type.cast(aegisReader.read(xmlStreamReader, typeToRead));
         } catch (Exception e) {
-            throw new BadRequestException(e);
+            throw ExceptionUtils.toBadRequestException(e, null);
         } finally {
             try {
                 StaxUtils.close(xmlStreamReader);
             } catch (XMLStreamException e) {
-                throw new BadRequestException(e);
+                throw ExceptionUtils.toBadRequestException(e, null);
             }
         }
     }
@@ -120,7 +119,7 @@ public class AegisElementProvider<T> ext
             xmlStreamWriter.writeEndDocument();
             xmlStreamWriter.close();
         } catch (Exception e) {
-            throw new InternalServerErrorException(e);
+            throw ExceptionUtils.toInternalServerErrorException(e, null);
         }
     }
     

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java (original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java Mon Feb 10 22:43:44 2014
@@ -29,7 +29,6 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -45,6 +44,7 @@ import org.apache.cxf.aegis.AegisWriter;
 import org.apache.cxf.aegis.type.AegisType;
 import org.apache.cxf.jaxrs.provider.json.utils.JSONUtils;
 import org.apache.cxf.jaxrs.provider.json.utils.PrefixCollectingXMLStreamWriter;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 import org.codehaus.jettison.mapped.Configuration;
@@ -121,7 +121,7 @@ public final class AegisJSONProvider<T> 
             xmlStreamWriter.flush();
             xmlStreamWriter.close();
         } catch (Exception e) {
-            throw new InternalServerErrorException(e);
+            throw ExceptionUtils.toInternalServerErrorException(e, null);
         }
     }
 

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java (original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java Mon Feb 10 22:43:44 2014
@@ -26,7 +26,6 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.logging.Logger;
 
-import javax.ws.rs.NotSupportedException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -39,6 +38,7 @@ import org.apache.abdera.parser.Parser;
 import org.apache.abdera.parser.ParserOptions;
 import org.apache.abdera.writer.Writer;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 
 public abstract class AbstractAtomProvider<T extends Element> 
     implements MessageBodyWriter<T>, MessageBodyReader<T> {
@@ -58,7 +58,7 @@ public abstract class AbstractAtomProvid
         if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mt)) {
             Writer w = createWriter("json");
             if (w == null) {
-                throw new NotSupportedException();
+                throw ExceptionUtils.toNotSupportedException(null, null);
             }
             element.writeTo(w, os);   
         } else if (formattedOutput) {

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java?rev=1566780&r1=1566779&r2=1566780&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java (original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java Mon Feb 10 22:43:44 2014
@@ -35,11 +35,8 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.logging.Logger;
 
-import javax.ws.rs.ClientErrorException;
 import javax.ws.rs.Consumes;
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
-import javax.ws.rs.ServerErrorException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
@@ -63,6 +60,7 @@ import org.apache.cxf.common.logging.Log
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 
 @Produces({"application/atom+xml", "application/atom+xml;type=feed", "application/atom+xml;type=entry" })
@@ -174,7 +172,7 @@ public class AtomPojoProvider extends Ab
                 atomElement = createEntryFromObject(factory, o, cls);
             }
         } catch (Exception ex) {
-            throw new InternalServerErrorException(ex);
+            throw ExceptionUtils.toInternalServerErrorException(ex, null);
         }
         
         try {
@@ -551,11 +549,7 @@ public class AtomPojoProvider extends Ab
     private void reportError(String message, Exception ex, int status) {
         LOG.warning(message);
         Response response = Response.status(status).type("text/plain").entity(message).build();
-        if (ex == null) {
-            throw status < 500 ? new ClientErrorException(response) : new ServerErrorException(response);
-        } else {
-            throw status < 500 ? new ClientErrorException(response, ex) : new ServerErrorException(response, ex);
-        }
+        throw ExceptionUtils.toHttpException(ex, response);
     }
     private void reportError(String message, Exception ex) {
         reportError(message, ex, 500);