use of javax.ws.rs.core.Feature in project jersey by jersey.
the class CommonConfig method processFeatureRegistration.
private void processFeatureRegistration(final Object component, final Class<?> componentClass) {
final ContractProvider model = componentBag.getModel(componentClass);
if (model.getContracts().contains(Feature.class)) {
@SuppressWarnings("unchecked") final FeatureRegistration registration = (component != null) ? new FeatureRegistration((Feature) component) : new FeatureRegistration((Class<? extends Feature>) componentClass);
newFeatureRegistrations.add(registration);
}
}
use of javax.ws.rs.core.Feature in project cxf by apache.
the class BookServer20 method run.
protected void run() {
Bus bus = BusFactory.getDefaultBus();
setBus(bus);
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setBus(bus);
sf.setResourceClasses(BookStore.class);
List<Object> providers = new ArrayList<>();
providers.add(new PreMatchContainerRequestFilter2());
providers.add(new PreMatchContainerRequestFilter());
providers.add(new PostMatchContainerResponseFilter());
providers.add((Feature) context -> {
context.register(new PostMatchContainerResponseFilter3());
return true;
});
providers.add(new PostMatchContainerResponseFilter2());
providers.add(new CustomReaderBoundInterceptor());
providers.add(new CustomReaderInterceptor());
providers.add(new CustomWriterInterceptor());
providers.add(new CustomDynamicFeature());
providers.add(new PostMatchContainerRequestFilter());
providers.add(new FaultyContainerRequestFilter());
providers.add(new PreMatchReplaceStreamOrAddress());
providers.add(new ServerTestFeature());
providers.add(new JacksonJaxbJsonProvider());
providers.add(new IOExceptionMapper());
sf.setApplication(new Application());
sf.setProviders(providers);
sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
sf.setAddress("http://localhost:" + PORT + "/");
server = sf.create();
BusFactory.setDefaultBus(null);
BusFactory.setThreadDefaultBus(null);
}
use of javax.ws.rs.core.Feature 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);
}
use of javax.ws.rs.core.Feature in project cxf by apache.
the class ProviderFactoryTest method testRegisterMbrMbwProviderAsMbwOnly.
@Test
public void testRegisterMbrMbwProviderAsMbwOnly() {
ServerProviderFactory pf = ServerProviderFactory.getInstance();
JAXBElementProvider<Book> customProvider = new JAXBElementProvider<>();
pf.registerUserProvider((Feature) context -> {
context.register(customProvider, MessageBodyWriter.class);
return true;
});
MessageBodyWriter<Book> writer = pf.createMessageBodyWriter(Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
assertSame(writer, customProvider);
MessageBodyReader<Book> reader = pf.createMessageBodyReader(Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
assertTrue(reader instanceof JAXBElementProvider);
assertNotSame(reader, customProvider);
}
use of javax.ws.rs.core.Feature in project cxf by apache.
the class ConfigurableImpl method doRegister.
private C doRegister(Object provider, Map<Class<?>, Integer> contracts) {
if (!checkConstraints(provider)) {
return configurable;
}
if (provider instanceof Feature) {
Feature feature = (Feature) provider;
boolean enabled = feature.configure(new FeatureContextImpl(this));
config.setFeature(feature, enabled);
return configurable;
}
config.register(provider, contracts);
return configurable;
}
Aggregations