Skip to content
Permalink
Browse files
[CXF-5556] Initial updates to get 2.0 exception API not interfering w…
…ith 1.1 API

git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1566780 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sergey Beryozkin committed Feb 10, 2014
1 parent 707c179 commit dcddfbbdbf21b7da7f76fc54a5effdbff0b54cf3
Show file tree
Hide file tree
Showing 50 changed files with 488 additions and 310 deletions.
@@ -28,7 +28,6 @@
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.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 Object invoke(Exchange exchange, Object request, Object resourceObject) {
BUNDLE,
subResourcePath);
LOG.severe(errorM.toString());
throw new NotFoundException();
throw ExceptionUtils.toNotFoundException(null, null);
}

OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(
@@ -335,7 +335,7 @@ private Object handleFault(Fault ex, Message inMessage,
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 @@ private static Object checkResultObject(Object result, String subResourcePath) {
BUNDLE,
subResourcePath);
LOG.info(errorM.toString());
throw new NotFoundException();
throw ExceptionUtils.toNotFoundException(null, null);
}

return result;
@@ -27,7 +27,6 @@

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 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 <T> T getObject(Class<T> cls) {
return mbr.readFrom(cls, cls, new Annotation[]{}, getContentType(),
headers, getDataHandler().getInputStream());
} catch (Exception ex) {
throw new InternalServerErrorException(ex);
ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
}
@@ -27,9 +27,6 @@
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.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 @@ private void processRequest(Message message) {
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 @@ private void processRequest(Message message) {
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 @@ private void convertExceptionToResponseIfPossible(Throwable ex, Message message)
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);
}
@@ -25,12 +25,13 @@
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 @@ protected Object createInstance(Message m) {
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}
*/
@@ -38,8 +38,6 @@
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.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 @@ protected static void handleExceptionEnd(Throwable t, String message, boolean re
? 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 @@ protected DocumentDepthProperties getDepthProperties() {
? Integer.valueOf(innerElementCountStr) : -1;
return new DocumentDepthProperties(totalElementCount, elementLevel, innerElementCount);
} catch (Exception ex) {
throw new InternalServerErrorException(ex);
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
}
@@ -26,13 +26,14 @@
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 @@ protected MessageBodyReader<T> getReader(Class<?> type, Type gType, Annotation[]
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;
}
@@ -26,13 +26,14 @@
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 @@ protected MessageBodyWriter<T> getWriter(Class<?> type, Type gType, Annotation[]
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;
}
@@ -24,9 +24,7 @@
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 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 T readFrom(Class<T> clazz, Type genericType, Annotation[] annotations, Me
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 void writeTo(T o, Class<?> clazz, Type genericType, Annotation[] annotati
writer = createWriter(clazz, genericType, os);
writeToWriter(writer, o);
} catch (Exception ex) {
throw new InternalServerErrorException(ex);
throw ExceptionUtils.toInternalServerErrorException(ex, null);
} finally {
StaxUtils.close(writer);
}
@@ -25,7 +25,6 @@
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.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 T readFrom(
} catch (WebApplicationException e) {
throw e;
} catch (Exception e) {
throw new BadRequestException(e);
throw ExceptionUtils.toBadRequestException(e, null);
}
}

@@ -34,9 +34,7 @@
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.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 T readFrom(Class<T> type, Type genericType, Annotation[] anns, MediaType
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 @@ protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaTy
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 @@ protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream
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 void writeTo(T obj, Class<?> cls, Type genericType, Annotation[] anns,
throw e;
} catch (Exception e) {
e.printStackTrace();
throw new InternalServerErrorException(e);
throw ExceptionUtils.toInternalServerErrorException(e, null);
}
}

@@ -559,8 +558,8 @@ protected XMLStreamWriter getStreamWriter(Object obj, OutputStream os, MediaType
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 @@ protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os,
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();

0 comments on commit dcddfbb

Please sign in to comment.