Java Code Examples for javax.ws.rs.core.FeatureContext#getConfiguration()
The following examples show how to use
javax.ws.rs.core.FeatureContext#getConfiguration() .
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: ServiceTalkJacksonSerializerFeature.java From servicetalk with Apache License 2.0 | 6 votes |
@Override public boolean configure(final FeatureContext context) { final Configuration config = context.getConfiguration(); final String jsonFeature = getValue(config.getProperties(), config.getRuntimeType(), JSON_FEATURE, ST_JSON_FEATURE, String.class); // Do not register our JSON feature if another one is already registered if (!ST_JSON_FEATURE.equalsIgnoreCase(jsonFeature)) { LOGGER.warn("Skipping registration of: {} as JSON support is already provided by: {}", ST_JSON_FEATURE, jsonFeature); return false; } // Prevent other not yet registered JSON features to register themselves context.property(getPropertyNameForRuntime(JSON_FEATURE, config.getRuntimeType()), ST_JSON_FEATURE); if (!config.isRegistered(JacksonSerializerMessageBodyReaderWriter.class)) { context.register(SerializationExceptionMapper.class); context.register(JacksonSerializerMessageBodyReaderWriter.class); } return true; }
Example 2
Source File: FastJsonFeature.java From fastjson-jaxrs-json-provider with Apache License 2.0 | 6 votes |
public boolean configure(final FeatureContext context) { final Configuration config = context.getConfiguration(); final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class); // Other JSON providers registered. if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) { return false; } // Disable other JSON providers. context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE); // Register FastJson. if (!config.isRegistered(FastJsonProvider.class)) { context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class); } return true; }
Example 3
Source File: DACJacksonJaxbJsonFeature.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override public boolean configure(FeatureContext context) { final Configuration config = context.getConfiguration(); final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE_CLASSNAME, String.class); // Other JSON providers registered. if (!JSON_FEATURE_CLASSNAME.equalsIgnoreCase(jsonFeature)) { LOGGER.error("Another JSON provider has been registered: {}", jsonFeature); return false; } // Disable other JSON providers. context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE_CLASSNAME); context.register(DACJacksonJaxbJsonProvider.class); return true; }
Example 4
Source File: EntityFieldsFilteringFeature.java From ameba with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public boolean configure(final FeatureContext context) { final Configuration config = context.getConfiguration(); if (!config.isRegistered(EntityFieldsProcessor.class)) { // register EntityFilteringFeature if (!config.isRegistered(EntityFilteringFeature.class)) { context.register(EntityFilteringFeature.class); } // Entity Processors. context.register(EntityFieldsProcessor.class); // Scope Resolver. context.register(EntityFieldsScopeResolver.class); return true; } return false; }
Example 5
Source File: TestResourcesFeature.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override public boolean configure(FeatureContext context) { Configuration configuration = context.getConfiguration(); Boolean enabled = PropertyHelper.getProperty(configuration, RestServerV2.TEST_API_ENABLE); // Default is not enabled if (enabled == null || !enabled) { return false; } for (Class<?> resource : scanResult.getAnnotatedClasses(RestResourceUsedForTesting.class)) { context.register(resource); } return true; }
Example 6
Source File: DACAuthFilterFeature.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override public boolean configure(FeatureContext context) { final Configuration configuration = context.getConfiguration(); Boolean disabled = PropertyHelper.getProperty(configuration, RestServerV2.DAC_AUTH_FILTER_DISABLE); // Default is not disabled if (disabled != null && disabled) { return false; } context.register(DACAuthFilter.class); if (!configuration.isRegistered(RolesAllowedDynamicFeature.class)) { context.register(RolesAllowedDynamicFeature.class); } return true; }
Example 7
Source File: ParsecMoxyFeature.java From parsec-libraries with Apache License 2.0 | 6 votes |
@Override public boolean configure(FeatureContext context) { final Configuration config = context.getConfiguration(); if (CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), CommonProperties.MOXY_JSON_FEATURE_DISABLE, Boolean.FALSE, Boolean.class)) { return false; } final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class); // Other JSON providers registered. if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) { return false; } // Disable other JSON providers. context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE); final int workerPriority = Priorities.USER + 3000; context.register(ParsecMoxyProvider.class, workerPriority); return true; }
Example 8
Source File: ParsecValidationAutoDiscoverable.java From parsec-libraries with Apache License 2.0 | 6 votes |
@Override public void configure(FeatureContext context) { final int priorityInc = 3000; // Jersey MOXY provider have higher priority(7000), so we need set higher than it int priority = Priorities.USER + priorityInc; Configuration config = context.getConfiguration(); if (!config.isRegistered(ParsecValidationExceptionMapper.class)) { context.register(ParsecValidationExceptionMapper.class, priority); } if (!config.isRegistered(ValidationConfigurationContextResolver.class)) { context.register(ValidationConfigurationContextResolver.class, priority); } if (!config.isRegistered(ParsecMoxyFeature.class)) { context.register(ParsecMoxyFeature.class, priority); } if (!config.isRegistered(JaxbExceptionMapper.class)) { context.register(JaxbExceptionMapper.class, priority); } }
Example 9
Source File: SysFilteringFeature.java From ameba with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public boolean configure(FeatureContext context) { Configuration configuration = context.getConfiguration(); if (!configuration.isRegistered(UriConnegFilter.class)) { context.register(UriConnegFilter.class, Priorities.AUTHENTICATION - 100); } if (!context.getConfiguration().isRegistered(DownloadEntityFilter.class)) { context.register(DownloadEntityFilter.class); } if (!configuration.isRegistered(LoadBalancerRequestFilter.class)) { context.register(LoadBalancerRequestFilter.class); } return true; }
Example 10
Source File: ServerProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
private void doApplyDynamicFeatures(ClassResourceInfo cri) { Set<OperationResourceInfo> oris = cri.getMethodDispatcher().getOperationResourceInfos(); for (OperationResourceInfo ori : oris) { String nameBinding = DEFAULT_FILTER_NAME_BINDING + ori.getClassResourceInfo().getServiceClass().getName() + "." + ori.getMethodToInvoke().toString(); for (DynamicFeature feature : dynamicFeatures) { FeatureContext featureContext = createServerFeatureContext(); feature.configure(new ResourceInfoImpl(ori), featureContext); Configuration cfg = featureContext.getConfiguration(); for (Object provider : cfg.getInstances()) { Map<Class<?>, Integer> contracts = cfg.getContracts(provider.getClass()); if (contracts != null && !contracts.isEmpty()) { Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider); registerUserProvider(new FilterProviderInfo<Object>(provider.getClass(), providerCls, provider, getBus(), Collections.singleton(nameBinding), true, contracts)); ori.addNameBindings(Collections.singletonList(nameBinding)); } } } } Collection<ClassResourceInfo> subs = cri.getSubResources(); for (ClassResourceInfo sub : subs) { if (sub != cri) { doApplyDynamicFeatures(sub); } } }
Example 11
Source File: QueryDslFeature.java From ameba with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public boolean configure(FeatureContext context) { Configuration cfg = context.getConfiguration(); if (!cfg.isRegistered(CommonExprTransformer.class)) context.register(CommonExprTransformer.class); if (!cfg.isRegistered(CommonExprArgTransformer.class)) context.register(CommonExprArgTransformer.class); if (!cfg.isRegistered(QuerySyntaxExceptionMapper.class)) context.register(QuerySyntaxExceptionMapper.class); return true; }
Example 12
Source File: JacksonFilteringFeature.java From ameba with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public boolean configure(final FeatureContext context) { final Configuration config = context.getConfiguration(); if (!config.isRegistered(JacksonFilteringFeature.Binder.class)) { context.register(new Binder()); return true; } return false; }
Example 13
Source File: DACExceptionMapperFeature.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public boolean configure(FeatureContext context) { Configuration configuration = context.getConfiguration(); Boolean property = PropertyHelper.getProperty(configuration, RestServerV2.ERROR_STACKTRACE_ENABLE); // Default is false boolean includeStackTraces = property != null && property; context.register(new UserExceptionMapper(includeStackTraces)); context.register(new GenericExceptionMapper(includeStackTraces)); return true; }
Example 14
Source File: FastJsonFeature.java From uavstack with Apache License 2.0 | 5 votes |
@Override public boolean configure(final FeatureContext context) { try { final Configuration config = context.getConfiguration(); final String jsonFeature = CommonProperties.getValue( config.getProperties() , config.getRuntimeType() , InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class ); // Other JSON providers registered. if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) { return false; } // Disable other JSON providers. context.property( PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()) , JSON_FEATURE); // Register FastJson. if (!config.isRegistered(FastJsonProvider.class)) { context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class); } } catch (NoSuchMethodError e) { // skip } return true; }
Example 15
Source File: FastJsonAutoDiscoverable.java From uavstack with Apache License 2.0 | 5 votes |
@Override public void configure(final FeatureContext context) { final Configuration config = context.getConfiguration(); // Register FastJson. if (!config.isRegistered(FastJsonFeature.class) && autoDiscover) { context.register(FastJsonFeature.class); } }
Example 16
Source File: ShiroAuthorizationFeature.java From aries-jax-rs-whiteboard with Apache License 2.0 | 4 votes |
@Override public boolean configure(FeatureContext fc) { Configuration configuration = fc.getConfiguration(); if(_LOG.isInfoEnabled()) { @SuppressWarnings("unchecked") Map<String, Object> applicationProps = (Map<String, Object>) configuration.getProperty(JAX_RS_APPLICATION_SERVICE_PROPERTIES); _LOG.info("Registering the Shiro Authorization feature with application {}", applicationProps.getOrDefault(JAX_RS_NAME, "<No Name found in application configuration>")); } Map<Class<?>, Integer> contracts = configuration.getContracts(ExceptionMapper.class); if(contracts.isEmpty()) { _LOG.debug("Registering the Shiro ExceptionMapper"); // Only register the ExceptionMapper if it isn't already registered fc.register(ExceptionMapper.class, AUTHORIZATION); } else if(AUTHORIZATION < contracts.getOrDefault(javax.ws.rs.ext.ExceptionMapper.class, USER)) { _LOG.debug("Updating the priority of the Shiro ExceptionMapper from {} to {}", contracts.getOrDefault(javax.ws.rs.ext.ExceptionMapper.class, USER), AUTHORIZATION); // Update the priority if it's registered too low contracts.put(javax.ws.rs.ext.ExceptionMapper.class, AUTHORIZATION); } contracts = configuration.getContracts(SubjectPrincipalRequestFilter.class); if(contracts.isEmpty()) { _LOG.debug("Registering the Shiro SubjectPrincipalRequestFilter"); // Only register the SubjectPrincipalRequestFilter if it isn't already registered fc.register(SubjectPrincipalRequestFilter.class, AUTHORIZATION); } else if(AUTHORIZATION < contracts.getOrDefault(ContainerRequestFilter.class, USER)) { _LOG.debug("Updating the priority of the Shiro SubjectPrincipalRequestFilter from {} to {}", contracts.getOrDefault(ContainerRequestFilter.class, USER), AUTHORIZATION); // Update the priority if it's registered too low contracts.put(ContainerRequestFilter.class, AUTHORIZATION); } _LOG.debug("Registering the Shiro ShiroAnnotationFilterFeature"); fc.register(ShiroAnnotationFilterFeature.class, Priorities.AUTHORIZATION); return true; }
Example 17
Source File: ShiroAuthenticationFeature.java From aries-jax-rs-whiteboard with Apache License 2.0 | 4 votes |
@Override public boolean configure(FeatureContext fc) { Configuration configuration = fc.getConfiguration(); if(_LOG.isInfoEnabled()) { @SuppressWarnings("unchecked") Map<String, Object> applicationProps = (Map<String, Object>) configuration.getProperty(JAX_RS_APPLICATION_SERVICE_PROPERTIES); _LOG.info("Registering the Shiro Authentication feature with application {}", applicationProps.getOrDefault(JAX_RS_NAME, "<No Name found in application configuration>")); } if(realms.isEmpty()) { _LOG.warn("There are no authentication realms available. Users may not be able to authenticate."); } else { _LOG.debug("Using the authentication realms {}.", realms); } _LOG.debug("Registering the Shiro SecurityManagerAssociatingFilter"); fc.register(new SecurityManagerAssociatingFilter(manager), AUTHENTICATION); Map<Class<?>, Integer> contracts = configuration.getContracts(ExceptionMapper.class); if(contracts.isEmpty()) { _LOG.debug("Registering the Shiro ExceptionMapper"); // Only register the ExceptionMapper if it isn't already registered fc.register(ExceptionMapper.class, AUTHENTICATION); } else if(AUTHENTICATION < contracts.getOrDefault(javax.ws.rs.ext.ExceptionMapper.class, USER)) { _LOG.debug("Updating the priority of the Shiro ExceptionMapper from {} to {}", contracts.getOrDefault(javax.ws.rs.ext.ExceptionMapper.class, USER), AUTHORIZATION); // Update the priority if it's registered too low contracts.put(javax.ws.rs.ext.ExceptionMapper.class, AUTHENTICATION); } contracts = configuration.getContracts(SubjectPrincipalRequestFilter.class); if(contracts.isEmpty()) { _LOG.debug("Registering the Shiro SubjectPrincipalRequestFilter"); // Only register the SubjectPrincipalRequestFilter if it isn't already registered // and make sure it always comes after the SecurityManagerAssociatingFilter fc.register(SubjectPrincipalRequestFilter.class, AUTHENTICATION + 1); } else if(AUTHENTICATION < contracts.getOrDefault(ContainerRequestFilter.class, USER)) { _LOG.debug("Updating the priority of the Shiro SubjectPrincipalRequestFilter from {} to {}", contracts.getOrDefault(ContainerRequestFilter.class, USER), AUTHENTICATION + 1); // Update the priority if it's registered too low contracts.put(ContainerRequestFilter.class, AUTHENTICATION + 1); } return true; }
Example 18
Source File: OzarkInitializer.java From ozark with Apache License 2.0 | 4 votes |
/** * Registers all required provides for Ozark. Please note that the initialization is * only performed if at least one controller is detected for the application and if the * initialization hasn't been triggered before. So calling this method multiple times * won't result in duplicated providers registered. */ public static void initialize(FeatureContext context, ServletContext servletContext) { Objects.requireNonNull(context, "FeatureContext is required"); Configuration config = context.getConfiguration(); if (!isAlreadyInitialized(config) && isMvcApplication(servletContext)) { log.info("Initializing Ozark..."); for (ConfigProvider provider : ServiceLoaders.list(ConfigProvider.class)) { log.log(Level.FINE, "Executing: {0}", provider.getClass().getName()); provider.configure(context); } } }
Example 19
Source File: Initializer.java From krazo with Apache License 2.0 | 4 votes |
/** * Registers all required provides for Krazo. Please note that the initialization is * only performed if at least one controller is detected for the application and if the * initialization hasn't been triggered before. So calling this method multiple times * won't result in duplicated providers registered. */ public static void initialize(FeatureContext context, ServletContext servletContext) { Objects.requireNonNull(context, "FeatureContext is required"); Configuration config = context.getConfiguration(); if (!isAlreadyInitialized(config) && isMvcApplication(servletContext)) { log.info("Initializing Eclipse Krazo..."); for (ConfigProvider provider : ServiceLoaders.list(ConfigProvider.class)) { log.log(Level.FINE, "Executing: {0}", provider.getClass().getName()); provider.configure(context); } } }