javax.ws.rs.core.Configurable Java Examples
The following examples show how to use
javax.ws.rs.core.Configurable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplicationGroupTest.java From rest-utils with Apache License 2.0 | 6 votes |
@Test public void testExceptionMapperIsolation() throws Exception { TestApp app1 = new TestApp("/app1"); TestApp app2 = new TestApp("/app2") { @Override public void setupResources(final Configurable<?> config, final TestRestConfig appConfig) { config.register(RestResource.class); config.register(TestExceptionMapper.class); } }; server.registerApplication(app1); server.registerApplication(app2); server.start(); assertThat(makeGetRequest( "/app1/exception"), is(Code.INTERNAL_SERVER_ERROR)); assertThat(makeGetRequest("/app2/exception"), is(Code.ENHANCE_YOUR_CALM)); }
Example #2
Source File: ServerProviderFactory.java From cxf with Apache License 2.0 | 6 votes |
private FeatureContext createServerFeatureContext() { final FeatureContextImpl featureContext = new FeatureContextImpl(); final ServerConfigurableFactory factory = getBus().getExtension(ServerConfigurableFactory.class); final Configurable<FeatureContext> configImpl = (factory == null) ? new ServerFeatureContextConfigurable(featureContext) : factory.create(featureContext); featureContext.setConfigurable(configImpl); if (application != null) { Map<String, Object> appProps = application.getProvider().getProperties(); for (Map.Entry<String, Object> entry : appProps.entrySet()) { configImpl.property(entry.getKey(), entry.getValue()); } } return featureContext; }
Example #3
Source File: JaxRSDistributionProvider.java From JaxRSProviders with Apache License 2.0 | 6 votes |
protected Configurable<?> registerComponents(Configurable<?> configurable) { synchronized (components) { for (JaxRSComponent ext : components) { List<Class<?>> noPriorityContracts = new ArrayList<Class<?>>(); Map<Class<?>, Integer> priorityContracts = new HashMap<Class<?>, Integer>(); for (Iterator<Class<?>> it = ext.contracts.keySet().iterator(); it.hasNext();) { Class<?> contractClass = it.next(); Integer priority = ext.contracts.get(contractClass); if (priority.equals(NO_PRIORITY)) noPriorityContracts.add(contractClass); else priorityContracts.put(contractClass, priority); } if (noPriorityContracts.size() > 0) configurable.register(ext.component, noPriorityContracts.toArray(new Class<?>[noPriorityContracts.size()])); if (priorityContracts.size() > 0) configurable.register(ext.component, priorityContracts); } } return configurable; }
Example #4
Source File: ApplicationGroupTest.java From rest-utils with Apache License 2.0 | 6 votes |
@Test public void testStaticResourceIsolation() throws Exception { TestApp app1 = new TestApp("/app1"); TestApp app2 = new TestApp("/app2") { @Override public void setupResources(final Configurable<?> config, final TestRestConfig appConfig) { config.register(RestResource.class); config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/(index\\.html|)"); } @Override protected ResourceCollection getStaticResources() { return new ResourceCollection(Resource.newClassPathResource("static")); } }; server.registerApplication(app1); server.registerApplication(app2); server.start(); assertThat(makeGetRequest("/app1/index.html"), is(Code.NOT_FOUND)); assertThat(makeGetRequest("/app2/index.html"), is(Code.OK)); }
Example #5
Source File: KsqlRestApplication.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 6 votes |
@Override public void configureBaseApplication(Configurable<?> config, Map<String, String> metricTags) { // Would call this but it registers additional, unwanted exception mappers // super.configureBaseApplication(config, metricTags); // Instead, just copy+paste the desired parts from Application.configureBaseApplication() here: JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(getJsonMapper()); config.register(jsonProvider); config.register(JsonParseExceptionMapper.class); // Don't want to buffer rows when streaming JSON in a request to the query resource config.property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0); if (isUiEnabled) { loadUiWar(); config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/(static/.*|.*html)"); } }
Example #6
Source File: ConfigurationImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testClientFilterContractsOnServerFeatureIsRejected() { FeatureContextImpl featureContext = new FeatureContextImpl(); Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER); featureContext.setConfigurable(configurable); featureContext.register(TestFilter.class); Configuration config = configurable.getConfiguration(); Map<Class<?>, Integer> contracts = config.getContracts(TestFilter.class); assertFalse(contracts.containsKey(ClientRequestFilter.class)); assertFalse(contracts.containsKey(ClientResponseFilter.class)); assertTrue(contracts.containsKey(ContainerRequestFilter.class)); assertTrue(contracts.containsKey(ContainerResponseFilter.class)); }
Example #7
Source File: CXFJaxRSServerContainer.java From JaxRSProviders with Apache License 2.0 | 5 votes |
@Override protected Servlet createServlet(Configurable<?> configurable, RSARemoteServiceRegistration registration) { Map<Class<?>, Object> extensions = new HashMap<>(); DestinationRegistry destinationRegistry = new DestinationRegistryImpl(); HTTPTransportFactory httpTransportFactory = new HTTPTransportFactory(destinationRegistry); extensions.put(HTTPTransportFactory.class, httpTransportFactory); extensions.put(DestinationRegistry.class, destinationRegistry); Bus bus = new ExtensionManagerBus(extensions, null, getClass().getClassLoader()); org.apache.cxf.transport.DestinationFactoryManager destinationFactoryManager = bus .getExtension(org.apache.cxf.transport.DestinationFactoryManager.class); for (String url : HTTPTransportFactory.DEFAULT_NAMESPACES) { destinationFactoryManager.registerDestinationFactory(url, httpTransportFactory); } return new DPCXFNonSpringJaxrsServlet(registration, (CXFServerConfigurable) configurable, destinationRegistry, bus); }
Example #8
Source File: CXFJaxRSServerContainer.java From JaxRSProviders with Apache License 2.0 | 5 votes |
@Override protected void registerExtensions(Configurable<?> configurable, RSARemoteServiceRegistration registration) { // This overrides/replaces superclass implementation to setup // ObjectMapperContextResolver, and Jackson Jaxb Json parsing/writing configurable.register(new ObjectMapperContextResolver(), ContextResolver.class); configurable.register(JsonParseExceptionMapper.class); configurable.register(JsonMappingExceptionMapper.class); configurable.register(new JacksonJaxbJsonProvider(), jacksonPriority); }
Example #9
Source File: Application.java From rest-utils with Apache License 2.0 | 5 votes |
/** * Register a body provider and optional exception mapper for (de)serializing JSON in * request/response entities. * @param config The config to register the provider with * @param restConfig The application's configuration * @param registerExceptionMapper Whether or not to register an additional exception mapper for * handling errors in (de)serialization */ protected void registerJsonProvider( Configurable<?> config, T restConfig, boolean registerExceptionMapper ) { ObjectMapper jsonMapper = getJsonMapper(); JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(jsonMapper); config.register(jsonProvider); if (registerExceptionMapper) { config.register(JsonParseExceptionMapper.class); } }
Example #10
Source File: Application.java From rest-utils with Apache License 2.0 | 5 votes |
/** * Register standard components for a JSON REST application on the given JAX-RS configurable, * which can be either an ResourceConfig for a server or a ClientConfig for a Jersey-based REST * client. */ public void configureBaseApplication(Configurable<?> config, Map<String, String> metricTags) { T restConfig = getConfiguration(); registerJsonProvider(config, restConfig, true); registerFeatures(config, restConfig); registerExceptionMappers(config, restConfig); config.register(new MetricsResourceMethodApplicationListener(getMetrics(), "jersey", metricTags, restConfig.getTime())); config.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true); config.property(ServerProperties.WADL_FEATURE_DISABLE, true); }
Example #11
Source File: ConfigurationImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testFeatureDisabledInstance() { FeatureContextImpl featureContext = new FeatureContextImpl(); Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER); featureContext.setConfigurable(configurable); Feature feature = new DisablableFeature(); featureContext.register(feature); Configuration config = configurable.getConfiguration(); assertFalse(config.isEnabled(feature)); }
Example #12
Source File: ConfigurationImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testFeatureDisabledClass() { FeatureContextImpl featureContext = new FeatureContextImpl(); Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER); featureContext.setConfigurable(configurable); featureContext.register(DisablableFeature.class); Configuration config = configurable.getConfiguration(); assertFalse(config.isEnabled(DisablableFeature.class)); }
Example #13
Source File: MetricsResourceMethodApplicationListenerIntegrationTest.java From rest-utils with Apache License 2.0 | 5 votes |
@Override public void setupResources(Configurable<?> config, TestRestConfig appConfig) { resourceConfig = config; config.register(PrivateResource.class); // ensures the dispatch error message gets shown in the response // as opposed to a generic error page config.property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, true); }
Example #14
Source File: ConfigurationImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSubClassIsRegisteredOnConfigurable() { FeatureContextImpl featureContext = new FeatureContextImpl(); Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER); featureContext.setConfigurable(configurable); featureContext.register(ContainerResponseFilterSubClassImpl.class); Configuration config = configurable.getConfiguration(); Map<Class<?>, Integer> contracts = config.getContracts(ContainerResponseFilter.class); assertEquals(1, contracts.size()); assertTrue(contracts.containsKey(ContainerResponseFilter.class)); }
Example #15
Source File: ApplicationTest.java From rest-utils with Apache License 2.0 | 5 votes |
@Override public void register(final Configurable<?> config, final TestApp app) { final TestRestConfig restConfig = app.getConfiguration(); assertNotNull(restConfig); config.register(new RestResource()); }
Example #16
Source File: MockApplication.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 5 votes |
@Override public void setupResources(Configurable<?> configurable, KsqlRestConfig ksqlRestConfig) { configurable.register(new MockKsqlResources()); configurable.register(streamedQueryResource); configurable.register(new MockStatusResource()); configurable.property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0); }
Example #17
Source File: KsqlRestApplication.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 5 votes |
@Override public void setupResources(Configurable<?> config, KsqlRestConfig appConfig) { config.register(rootDocument); config.register(new ServerInfoResource(serverInfo)); config.register(statusResource); config.register(ksqlResource); config.register(streamedQueryResource); config.register(new KsqlExceptionMapper()); }
Example #18
Source File: FeatureContextImpl.java From cxf with Apache License 2.0 | 4 votes |
public void setConfigurable(Configurable<?> configurable) { this.cfg = configurable; }
Example #19
Source File: FeatureContextImpl.java From cxf with Apache License 2.0 | 4 votes |
public Configurable<?> getConfigurable() { return cfg; }
Example #20
Source File: FeatureContextImpl.java From cxf with Apache License 2.0 | 4 votes |
public FeatureContextImpl(Configurable<?> cfg) { this.cfg = cfg; }
Example #21
Source File: ApplicationGroupTest.java From rest-utils with Apache License 2.0 | 4 votes |
@Override public void setupResources(final Configurable<?> config, final TestRestConfig appConfig) { config.register(RestResource.class); }
Example #22
Source File: HelloWorldApplication.java From rest-utils with Apache License 2.0 | 4 votes |
@Override public void setupResources(Configurable<?> config, HelloWorldRestConfig appConfig) { config.register(new HelloWorldResource(appConfig)); config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/(static/.*|.*\\.html|)"); }
Example #23
Source File: Application.java From rest-utils with Apache License 2.0 | 4 votes |
public void configureBaseApplication(Configurable<?> config) { configureBaseApplication(config, null); }
Example #24
Source File: CdiServerConfigurableFactory.java From cxf with Apache License 2.0 | 4 votes |
@Override public Configurable<FeatureContext> create(FeatureContext context) { return new CdiServerFeatureContextConfigurable(context, beanManager); }
Example #25
Source File: JerseyClientDistributionProvider.java From JaxRSProviders with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") @Override protected Configurable createConfigurable() { return new ClientConfig(); }
Example #26
Source File: InternalCommonConfig.java From soabase with Apache License 2.0 | 4 votes |
@Override public Configurable<Configurable> property(String name, Object value) { config.property(name, value); return this; }
Example #27
Source File: ApplicationTest.java From rest-utils with Apache License 2.0 | 4 votes |
@Override public void register(final Configurable<?> config, final Application<?> app) { throw new IllegalArgumentException("Boom"); }
Example #28
Source File: ApplicationTest.java From rest-utils with Apache License 2.0 | 4 votes |
@Override public void register(final Configurable<?> config, final Application<?> app) { }
Example #29
Source File: GzipHandlerIntegrationTest.java From rest-utils with Apache License 2.0 | 4 votes |
@Override public void setupResources(Configurable<?> config, TestRestConfig appConfig) { resourceConfig = config; config.register(ZerosResource.class); }
Example #30
Source File: ApplicationTest.java From rest-utils with Apache License 2.0 | 4 votes |
@Override public void setupResources(final Configurable<?> config, final TestRestConfig appConfig) { }