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;
}
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);
}
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));
}
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);
}
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);
}
Aggregations