Search in sources :

Example 6 with WebApplicationExceptionMapper

use of org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper in project cxf by apache.

the class ProviderFactoryTest method testRegisterInFeature.

@Test
public void testRegisterInFeature() {
    ServerProviderFactory pf = ServerProviderFactory.getInstance();
    final Object provider = new WebApplicationExceptionMapper();
    pf.registerUserProvider((Feature) context -> {
        context.register(provider);
        return true;
    });
    ExceptionMapper<WebApplicationException> em = pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
    assertSame(provider, em);
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) Priorities(javax.ws.rs.Priorities) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) ParamConverter(javax.ws.rs.ext.ParamConverter) ContextResolver(javax.ws.rs.ext.ContextResolver) JAXBContextProvider2(org.apache.cxf.jaxrs.JAXBContextProvider2) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) ParamConverterProvider(javax.ws.rs.ext.ParamConverterProvider) JAXBContextProvider(org.apache.cxf.jaxrs.JAXBContextProvider) SuperBook(org.apache.cxf.jaxrs.resources.SuperBook) Collection(java.util.Collection) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Customer(org.apache.cxf.jaxrs.Customer) Priority(javax.annotation.Priority) List(java.util.List) WriterInterceptorContext(javax.ws.rs.ext.WriterInterceptorContext) Response(javax.ws.rs.core.Response) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) Bus(org.apache.cxf.Bus) MessageImpl(org.apache.cxf.message.MessageImpl) Feature(javax.ws.rs.core.Feature) DataHandler(javax.activation.DataHandler) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) Status(javax.ws.rs.core.Response.Status) JAXBContext(javax.xml.bind.JAXBContext) WebApplicationExceptionMapper(org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper) Before(org.junit.Before) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) CustomerParameterHandler(org.apache.cxf.jaxrs.CustomerParameterHandler) Message(org.apache.cxf.message.Message) IOUtils(org.apache.cxf.helpers.IOUtils) IOException(java.io.IOException) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Book(org.apache.cxf.jaxrs.resources.Book) Exchange(org.apache.cxf.message.Exchange) File(java.io.File) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BusFactory(org.apache.cxf.BusFactory) DataSource(javax.activation.DataSource) Comparator(java.util.Comparator) Assert(org.junit.Assert) Collections(java.util.Collections) InputStream(java.io.InputStream) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) WebApplicationExceptionMapper(org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper) WebApplicationException(javax.ws.rs.WebApplicationException) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 7 with WebApplicationExceptionMapper

use of org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper in project cxf by apache.

the class ProviderFactoryTest method testExceptionMappersHierarchy5.

@Test
public void testExceptionMappersHierarchy5() throws Exception {
    Message m = new MessageImpl();
    ServerProviderFactory pf = ServerProviderFactory.getInstance();
    ExceptionMapper<WebApplicationException> em = pf.createExceptionMapper(WebApplicationException.class, m);
    assertTrue(em instanceof WebApplicationExceptionMapper);
}
Also used : WebApplicationExceptionMapper(org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper) Message(org.apache.cxf.message.Message) WebApplicationException(javax.ws.rs.WebApplicationException) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 8 with WebApplicationExceptionMapper

use of org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper in project cxf by apache.

the class ProviderFactoryTest method testExceptionMappersHierarchy1.

@Test
public void testExceptionMappersHierarchy1() throws Exception {
    ServerProviderFactory pf = ServerProviderFactory.getInstance();
    WebApplicationExceptionMapper wm = new WebApplicationExceptionMapper();
    pf.registerUserProvider(wm);
    assertSame(wm, pf.createExceptionMapper(WebApplicationException.class, new MessageImpl()));
    assertNull(pf.createExceptionMapper(RuntimeException.class, new MessageImpl()));
    TestRuntimeExceptionMapper rm = new TestRuntimeExceptionMapper();
    pf.registerUserProvider(rm);
    assertSame(wm, pf.createExceptionMapper(WebApplicationException.class, new MessageImpl()));
    assertSame(rm, pf.createExceptionMapper(RuntimeException.class, new MessageImpl()));
}
Also used : WebApplicationExceptionMapper(org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper) WebApplicationException(javax.ws.rs.WebApplicationException) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 9 with WebApplicationExceptionMapper

use of org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper in project cxf by apache.

the class ProviderFactoryTest method testExceptionMappersHierarchy2.

@Test
public void testExceptionMappersHierarchy2() throws Exception {
    ServerProviderFactory pf = ServerProviderFactory.getInstance();
    TestRuntimeExceptionMapper rm = new TestRuntimeExceptionMapper();
    pf.registerUserProvider(rm);
    ExceptionMapper<WebApplicationException> em = pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
    assertTrue(em instanceof WebApplicationExceptionMapper);
    assertSame(rm, pf.createExceptionMapper(RuntimeException.class, new MessageImpl()));
    WebApplicationExceptionMapper wm = new WebApplicationExceptionMapper();
    pf.registerUserProvider(wm);
    assertSame(wm, pf.createExceptionMapper(WebApplicationException.class, new MessageImpl()));
    assertSame(rm, pf.createExceptionMapper(RuntimeException.class, new MessageImpl()));
}
Also used : WebApplicationExceptionMapper(org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper) WebApplicationException(javax.ws.rs.WebApplicationException) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Aggregations

WebApplicationExceptionMapper (org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper)9 MessageImpl (org.apache.cxf.message.MessageImpl)8 Test (org.junit.Test)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 Message (org.apache.cxf.message.Message)5 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Annotation (java.lang.annotation.Annotation)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 DataHandler (javax.activation.DataHandler)2