本文整理汇总了Java中javax.ws.rs.core.FeatureContext类的典型用法代码示例。如果您正苦于以下问题:Java FeatureContext类的具体用法?Java FeatureContext怎么用?Java FeatureContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FeatureContext类属于javax.ws.rs.core包,在下文中一共展示了FeatureContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
context.register(new AbstractBinder() {
@Override
protected void configure() {
Injector injector = ClientGuiceBridgeFeature.getInjector(context.getConfiguration());
ClientGuiceInjectInjector injectInjector = new ClientGuiceInjectInjector(injector);
bind(injectInjector).to(new TypeLiteral<InjectionResolver<com.google.inject.Inject>>() {
});
}
});
return true;
}
示例2: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public boolean configure(final FeatureContext context) {
PluginLoader.INSTANCE.plugins.get().stream()
.filter(module -> module.jacksonFeatureProperties()!=null)
.map(Plugin::jacksonFeatureProperties)
.map(fn->fn.apply(context))
.forEach(map -> {
addAll(map,context);
});
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(JacksonUtil.getMapper());
context.register(provider, new Class[]{MessageBodyReader.class, MessageBodyWriter.class});
return true;
}
示例3: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
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)) {
//DisableCircularReferenceDetect
FastJsonProvider fastJsonProvider = new FastJsonProvider();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
//fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.BrowserSecure);
fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
fastJsonProvider.setFastJsonConfig(fastJsonConfig);
context.register(fastJsonProvider, MessageBodyReader.class, MessageBodyWriter.class);
}
return true;
}
示例4: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public boolean configure(final FeatureContext featureContext) {
final UserRepository userRepo = CDI.current().select(UserRepository.class).get();
final Authenticator<String, User> authenticator = new GoogleAuthenticator(
authConfig.getClientId(), userRepo, authConfig.getHostedDomain()
);
final Authenticator<String, User> cachingAuthenticator = new CachingAuthenticator<>(
metricRegistry, authenticator, authConfig.getAuthenticationCachePolicy()
);
featureContext.register(new AuthDynamicFeature(
new OAuthCredentialAuthFilter.Builder<User>()
.setAuthenticator(cachingAuthenticator)
.setPrefix("Bearer")
.buildAuthFilter()));
featureContext.register(new AuthValueFactoryProvider.Binder<>(User.class));
return true;
}
示例5: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
List<Annotation> authzSpecs = new ArrayList<>();
Annotation classAuthzSpec =
resourceInfo.getResourceClass().getAnnotation(AppkeyAnnotation.class);
Annotation methodAuthzSpec =
resourceInfo.getResourceMethod().getAnnotation(AppkeyAnnotation.class);
if (classAuthzSpec != null)
authzSpecs.add(classAuthzSpec);
if (methodAuthzSpec != null)
authzSpecs.add(methodAuthzSpec);
if (!authzSpecs.isEmpty()) {
context.register(AppkeyFilter.class);
}
}
示例6: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
List<Annotation> authzSpecs = new ArrayList<>();
Annotation classAuthzSpec =
resourceInfo.getResourceClass().getAnnotation(AuthAnnotation.class);
Annotation methodAuthzSpec =
resourceInfo.getResourceMethod().getAnnotation(AuthAnnotation.class);
if (classAuthzSpec != null)
authzSpecs.add(classAuthzSpec);
if (methodAuthzSpec != null)
authzSpecs.add(methodAuthzSpec);
if (!authzSpecs.isEmpty()) {
// 需要拦截的api
context.register(AuthorizationFilter.class);
}
}
示例7: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
CacheFor cc = resourceInfo.getResourceClass().getAnnotation(CacheFor.class);
CacheFor mcc = resourceInfo.getResourceMethod().getAnnotation(CacheFor.class);
if( mcc!=null ) {
cc = mcc;
}
if (cc!=null) {
if( cc.value() == 0 ) {
context.register(NoCacheFilter.class);
} else if( cc.value() > 0 ) {
context.register(new CacheFilter("max-age= " + cc.unit().toSeconds(cc.value())));
}
} else {
context.register(NoCacheFilter.class);
}
}
示例8: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
if (context.getConfiguration().isEnabled(this.getClass())) {
return false;
}
switch (context.getConfiguration().getRuntimeType()) {
case SERVER:
context.register(new ServerFilter(tracer));
break;
case CLIENT:
context.register(new ClientFilter(tracer));
break;
default:
LOGGER.error("Unknown runtime ({}), not registering Haystack feature", context.getConfiguration().getRuntimeType());
return false;
}
return true;
}
示例9: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
if (context.getConfiguration().getProperties().containsKey(JacksonFeature.JAXRS_DISABLE_JACKSON_AUTO_CONFIG)) {
LOGGER.debug(() -> "Skip JacksonJsonProvider registration, ["
+ JacksonFeature.JAXRS_DISABLE_JACKSON_AUTO_CONFIG + "] property detected");
return false;
}
if (!context.getConfiguration().isRegistered(JacksonJsonPropertyBoxProvider.class)) {
LOGGER.debug(() -> "<Runtime: " + context.getConfiguration().getRuntimeType() + "> Registering provider ["
+ JacksonJsonPropertyBoxProvider.class.getName() + "]");
context.register(JacksonJsonPropertyBoxProvider.class);
}
return true;
}
示例10: registerJerseyJsonFeature
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
/**
* Register a Jersey JSON provider feature only if another JSON provider is not already registered, checking
* {@link #JERSEY_JSON_PROVIDER_PROPERTY} property value.
* @param context Feature context
* @param feature Feature to register
* @param featureName Feature name to register
* @return <code>true</code> if feature was registered, <code>false</code> otherwise
*/
private static boolean registerJerseyJsonFeature(FeatureContext context, Class<? extends Feature> feature,
String featureName) {
final Configuration config = context.getConfiguration();
final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
JERSEY_JSON_PROVIDER_PROPERTY, featureName, String.class);
if (!featureName.equalsIgnoreCase(jsonFeature)) {
// Other JSON providers registered
return false;
}
// Disable other JSON providers
context.property(
PropertiesHelper.getPropertyNameForRuntime(JERSEY_JSON_PROVIDER_PROPERTY, config.getRuntimeType()),
featureName);
// Register
if (!config.isRegistered(feature)) {
context.register(feature);
}
return true;
}
示例11: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public boolean configure(final FeatureContext context) {
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
return (String) context.getConfiguration().getProperty(key);
}
};
boot.setPropertiesProvider(propertiesProvider);
boot.addModule(new JaxrsModule(securityContext));
boot.boot();
parameterProviderRegistry = buildParameterProviderRegistry();
CrnkFilter crnkFilter = createCrnkFilter();
context.register(crnkFilter);
registerActionRepositories(context, boot);
return true;
}
示例12: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
// limit to SERVER runtime
if (RuntimeType.SERVER == context.getConfiguration().getRuntimeType()) {
// check disabled
if (context.getConfiguration().getProperties().containsKey(DISABLE_AUTHENTICATION)) {
LOGGER.debug(() -> "Skip AuthenticationFeature registration, [" + DISABLE_AUTHENTICATION
+ "] property detected");
return false;
}
if (!context.getConfiguration().isRegistered(AuthenticationDynamicFeature.class)) {
context.register(AuthenticationDynamicFeature.class);
}
return true;
}
return false;
}
示例13: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
// 获取资源方法
Method resourceMethod = resourceInfo.getResourceMethod();
if (resourceMethod != null) {
// 获取FormatJson注解
ResponseFormat formatJson = resourceMethod.getAnnotation(ResponseFormat.class);
if (formatJson == null || formatJson.type().equals(FormatType.JSON)) {
context.register(DefaultWebFilter.class);
}
}
}
示例14: TestChain
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
public TestChain(TestServiceRunnerBase serviceRunner) {
this.actions = ImmutableList.of();
this.serviceLocator = new ServiceLocatorHolder();
Feature lifecycleListener = new Feature() {
@Inject
public void setServiceLocator(ServiceLocator s) {
serviceLocator.set(s);
}
@Override
public boolean configure(FeatureContext context) {
return false;
}
};
this.serviceRunner = serviceRunner
.serviceConfig(serviceRunner.getServiceConfig()
.registerInstance(lifecycleListener)
);
}
示例15: configure
import javax.ws.rs.core.FeatureContext; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
boolean modified = false;
AccessControlAllowOriginRequestFilter accessControlAllowOriginRequestFilter = new AccessControlAllowOriginRequestFilter(
originFilter);
if (!context.getConfiguration().isRegistered(accessControlAllowOriginRequestFilter)) {
context.register(accessControlAllowOriginRequestFilter);
modified = true;
}
AccessControlAllowOriginResponseFilter accessControlAllowOriginResponseFilter = new AccessControlAllowOriginResponseFilter(
originFilter);
if (!context.getConfiguration().isRegistered(accessControlAllowOriginResponseFilter)) {
context.register(accessControlAllowOriginResponseFilter);
modified = true;
}
SimpleAccessControlAllowHeaderFilter simpleAccessControlAllowHeaderFilter = new SimpleAccessControlAllowHeaderFilter(
allowedHeaders);
if (!context.getConfiguration().isRegistered(simpleAccessControlAllowHeaderFilter)) {
context.register(simpleAccessControlAllowHeaderFilter);
modified = true;
}
return modified;
}