Search in sources :

Example 1 with WebApplicationExceptionMapper

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

the class ServerProviderFactory method createInstance.

public static ServerProviderFactory createInstance(Bus bus) {
    if (bus == null) {
        bus = BusFactory.getThreadDefaultBus();
    }
    ServerProviderFactory factory = new ServerProviderFactory(bus);
    ProviderFactory.initFactory(factory);
    factory.setProviders(false, false, new WebApplicationExceptionMapper(), new NioMessageBodyWriter());
    factory.setBusProviders();
    return factory;
}
Also used : WebApplicationExceptionMapper(org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper) NioMessageBodyWriter(org.apache.cxf.jaxrs.nio.NioMessageBodyWriter)

Example 2 with WebApplicationExceptionMapper

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

the class ProviderFactoryTest method testRegisterFeatureInFeature.

@Test
public void testRegisterFeatureInFeature() {
    ServerProviderFactory pf = ServerProviderFactory.getInstance();
    final Object provider = new WebApplicationExceptionMapper();
    pf.registerUserProvider((Feature) context -> {
        context.register((Feature) context2 -> {
            context2.register(provider);
            return true;
        });
        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) Feature(javax.ws.rs.core.Feature) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 3 with WebApplicationExceptionMapper

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

the class ProviderFactoryTest method testExceptionMappersHierarchy3.

@Test
public void testExceptionMappersHierarchy3() throws Exception {
    Message m = new MessageImpl();
    m.put("default.wae.mapper.least.specific", true);
    ServerProviderFactory pf = ServerProviderFactory.getInstance();
    TestRuntimeExceptionMapper rm = new TestRuntimeExceptionMapper();
    pf.registerUserProvider(rm);
    ExceptionMapper<WebApplicationException> em = pf.createExceptionMapper(WebApplicationException.class, m);
    assertSame(rm, em);
    assertSame(rm, pf.createExceptionMapper(RuntimeException.class, m));
    WebApplicationExceptionMapper wm = new WebApplicationExceptionMapper();
    pf.registerUserProvider(wm);
    assertSame(wm, pf.createExceptionMapper(WebApplicationException.class, m));
    assertSame(rm, pf.createExceptionMapper(RuntimeException.class, m));
}
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 4 with WebApplicationExceptionMapper

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

the class ProviderFactoryTest method testExceptionMappersHierarchy4.

@Test
public void testExceptionMappersHierarchy4() throws Exception {
    Message m = new MessageImpl();
    m.put("default.wae.mapper.least.specific", true);
    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 5 with WebApplicationExceptionMapper

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

the class ProviderFactoryTest method testDefaultUserExceptionMappers.

@Test
public void testDefaultUserExceptionMappers() throws Exception {
    ServerProviderFactory pf = ServerProviderFactory.getInstance();
    ExceptionMapper<?> mapper = pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
    assertNotNull(mapper);
    WebApplicationExceptionMapper wm = new WebApplicationExceptionMapper();
    pf.registerUserProvider(wm);
    ExceptionMapper<?> mapper2 = pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
    assertNotSame(mapper, mapper2);
    assertSame(wm, mapper2);
}
Also used : WebApplicationExceptionMapper(org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper) 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