Java Code Examples for javax.ws.rs.core.Configurable#register()

The following examples show how to use javax.ws.rs.core.Configurable#register() . 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: JaxRSDistributionProvider.java    From JaxRSProviders with Apache License 2.0 6 votes vote down vote up
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 2
Source File: MockApplication.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
@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 3
Source File: CXFJaxRSServerContainer.java    From JaxRSProviders with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: ApplicationTest.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
@Override
public void register(final Configurable<?> config, final TestApp app) {
  final TestRestConfig restConfig = app.getConfiguration();
  assertNotNull(restConfig);

  config.register(new RestResource());
}
 
Example 5
Source File: Application.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: Application.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: RequestScopedMetricsIntegrationTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  resourceConfig = config;
  config.register(TimestampResource.class);
  config.register(new Filter());
}
 
Example 8
Source File: GzipHandlerIntegrationTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  resourceConfig = config;
  config.register(ZerosResource.class);
}
 
Example 9
Source File: TestCustomizedHttpResponseHeaders.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  config.register(new RestResource());
}
 
Example 10
Source File: ShutdownTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  config.register(resource);
}
 
Example 11
Source File: ExceptionHandlingTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  resourceConfig = config;
  config.register(ExceptionResource.class);
}
 
Example 12
Source File: StaticResourcesTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  this.resourceConfig = config;
  config.register(DynamicResource.class);
  config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/(index\\.html|)");
}
 
Example 13
Source File: Application.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
/**
 * Register handlers for translating exceptions into responses.
 * @param config The config to register the mappers with
 * @param restConfig The application's configuration
 */
protected void registerExceptionMappers(Configurable<?> config, T restConfig) {
  config.register(ConstraintViolationExceptionMapper.class);
  config.register(new WebApplicationExceptionMapper(restConfig));
  config.register(new GenericExceptionMapper(restConfig));
}
 
Example 14
Source File: CustomInitTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  config.register(new CustomRestResource());
}
 
Example 15
Source File: SslTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  config.register(new SslTestResource());
}
 
Example 16
Source File: JaxRSServerContainer.java    From JaxRSProviders with Apache License 2.0 4 votes vote down vote up
protected void registerExtensions(Configurable<?> configurable, RSARemoteServiceRegistration registration) {
	configurable.register(new ObjectMapperContextResolver(), ContextResolver.class);
	configurable.register(new JaxRSServerJacksonFeature(registration), jacksonPriority);
}
 
Example 17
Source File: JaxRSServerContainer.java    From JaxRSProviders with Apache License 2.0 4 votes vote down vote up
protected void registerService(Configurable<?> configurable, RSARemoteServiceRegistration registration) {
	configurable.register(registration.getService());
}
 
Example 18
Source File: JerseyServerContainer.java    From JaxRSProviders with Apache License 2.0 4 votes vote down vote up
@Override
protected void registerExtensions(Configurable<?> configurable, RSARemoteServiceRegistration registration) {
	super.registerExtensions(configurable, registration);
	configurable.register(new JerseyBinder(registration), bindingPriority);
}
 
Example 19
Source File: RequestMetricsFilterRegistry.java    From cf-java-logging-support with Apache License 2.0 4 votes vote down vote up
public static void registerContainerFilters(Configurable<ResourceConfig> config) {
    config.register(RequestMetricsContainerRequestFilter.class);
    config.register(RequestMetricsContainerResponseFilter.class);
}
 
Example 20
Source File: ApiHeadersTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Override
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
  config.register(new TestResource());
}