private static ApacheConnector getConnector(final Configurable<?> component) { if (!(component instanceof Initializable)) { throw new IllegalArgumentException( LocalizationMessages.INVALID_CONFIGURABLE_COMPONENT_TYPE(component.getClass().getName())); } final Initializable<?> initializable = (Initializable<?>) component; Connector connector = initializable.getConfiguration().getConnector(); if (connector == null) { initializable.preInitialize(); connector = initializable.getConfiguration().getConnector(); } if (connector instanceof ApacheConnector) { return (ApacheConnector) connector; } else { throw new IllegalArgumentException(LocalizationMessages.EXPECTED_CONNECTOR_PROVIDER_NOT_USED()); } }
@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: ObjectMapper jsonMapper = getJsonMapper(); new SchemaMapper().registerToObjectMapper(jsonMapper); JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(jsonMapper); 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 (enableQuickstartPage) { config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "^/quickstart\\.html$"); } }
@Override public void setupResources(Configurable<?> config, KsqlRestConfig appConfig) { config.register(serverInfoResource); config.register(statusResource); config.register(ksqlResource); config.register(streamedQueryResource); config.register(new KsqlExceptionMapper()); }
@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); }
/** * We need this implementation because of * https://issues.apache.org/jira/browse/CXF-5252 <p> TODO remove when CXF * 3.0.0 is released. */ public void configure(ResourceInfo resourceInfo, Configurable context) { if (resourceInfo.getResourceMethod().isAnnotationPresent( RequiresAuthentication.class)) { context.register(new SecurityFilter(authService)); } }
/** * 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(metrics, "jersey", metricTags, restConfig.getTime())); config.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true); }
/** * 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); } }
@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); }
public static void registerContainerFilters(Configurable<ResourceConfig> config) { config.register(RequestMetricsContainerRequestFilter.class); config.register(RequestMetricsContainerResponseFilter.class); }
@Override public Configurable<Configurable> property(String name, Object value) { config.property(name, value); return this; }
@Override public Configurable<Configurable> register(Class<?> componentClass) { config.register(componentClass); return this; }
@Override public Configurable<Configurable> register(Class<?> componentClass, int priority) { config.register(componentClass, priority); return this; }
@Override public Configurable<Configurable> register(Class<?> componentClass, Class<?>... contracts) { config.register(componentClass, contracts); return this; }
@Override public Configurable<Configurable> register(Class<?> componentClass, Map<Class<?>, Integer> contracts) { config.register(componentClass, contracts); return this; }
@Override public Configurable<Configurable> register(Object component) { config.register(component); return this; }
@Override public Configurable<Configurable> register(Object component, int priority) { config.register(component, priority); return this; }
@Override public Configurable<Configurable> register(Object component, Class<?>... contracts) { config.register(component, contracts); return this; }
@Override public Configurable<Configurable> register(Object component, Map<Class<?>, Integer> contracts) { config.register(component, contracts); return this; }
public Configurable<?> configurable() { return commonConfig; }
@Override public void setupResources(Configurable<?> config, HelloWorldRestConfig appConfig) { config.register(new HelloWorldResource(appConfig)); config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/(static/.*|.*\\.html|)"); }
public void configureBaseApplication(Configurable<?> config) { configureBaseApplication(config, null); }
/** * 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)); }
@Override public void setupResources(Configurable<?> config, TestRestConfig appConfig) { this.resourceConfig = config; config.register(DynamicResource.class); config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/(index\\.html|)"); }
@Override public void setupResources(Configurable<?> config, TestRestConfig appConfig) { resourceConfig = config; config.register(ExceptionResource.class); }
@Override public void setupResources(Configurable<?> config, TestRestConfig appConfig) { config.register(resource); }
@Override public void setupResources(Configurable<?> config, TestRestConfig appConfig) { config.register(new SaslTestResource()); }
@Override public void setupResources(Configurable<?> config, TestRestConfig appConfig) { config.register(new SslTestResource()); }
/** * Retrieve the underlying Apache {@link HttpClient} instance from * {@link org.glassfish.jersey.client.JerseyClient} or {@link org.glassfish.jersey.client.JerseyWebTarget} * configured to use {@code ApacheConnectorProvider}. * * @param component {@code JerseyClient} or {@code JerseyWebTarget} instance that is configured to use * {@code ApacheConnectorProvider}. * @return underlying Apache {@code HttpClient} instance. * * @throws java.lang.IllegalArgumentException in case the {@code component} is neither {@code JerseyClient} * nor {@code JerseyWebTarget} instance or in case the component * is not configured to use a {@code ApacheConnectorProvider}. * @since 2.8 */ public static HttpClient getHttpClient(final Configurable<?> component) { return getConnector(component).getHttpClient(); }
/** * Retrieve the underlying Apache {@link CookieStore} instance from * {@link org.glassfish.jersey.client.JerseyClient} or {@link org.glassfish.jersey.client.JerseyWebTarget} * configured to use {@code ApacheConnectorProvider}. * * @param component {@code JerseyClient} or {@code JerseyWebTarget} instance that is configured to use * {@code ApacheConnectorProvider}. * @return underlying Apache {@code CookieStore} instance. * @throws java.lang.IllegalArgumentException in case the {@code component} is neither {@code JerseyClient} * nor {@code JerseyWebTarget} instance or in case the component * is not configured to use a {@code ApacheConnectorProvider}. * @since 2.16 */ public static CookieStore getCookieStore(final Configurable<?> component) { return getConnector(component).getCookieStore(); }
/** * Register resources or additional Providers, ExceptionMappers, and other JAX-RS components with * the Jersey application. This, combined with your Configuration class, is where you can * customize the behavior of the application. */ public abstract void setupResources(Configurable<?> config, T appConfig);
/** * Register server features * @param config The config to register the features with * @param restConfig The application's configuration */ protected void registerFeatures(Configurable<?> config, T restConfig) { config.register(ValidationFeature.class); }
void apply(Configurable<?> builder);