Java 类javax.ws.rs.core.FeatureContext 实例源码

项目:bootique-jersey-client    文件:ClientGuiceBridgeFeature.java   
@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;
}
项目:GitHub    文件:Issue1341.java   
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;
}
项目:dust-api    文件:AuthenticatorFeature.java   
@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;
}
项目:wechat-mall    文件:AppkeyServiceFeature.java   
@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);
    }
}
项目:wechat-mall    文件:AuthServiceFeature.java   
@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);
    }
}
项目:syndesis    文件:CacheForFilter.java   
@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);
    }
}
项目:haystack-client-java    文件:HaystackFeature.java   
@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;
}
项目:holon-json    文件:JacksonProviderFeature.java   
@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;

}
项目:holon-json    文件:GsonAutoDiscoverable.java   
/**
 * 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;
}
项目:crnk-framework    文件:CrnkFeature.java   
@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;
}
项目:holon-jaxrs    文件:AuthenticationFeature.java   
@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;
}
项目:azeroth    文件:DefaultFilterDynamicFeature.java   
@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);
        }

    }
}
项目:servicebuilder    文件:TestChain.java   
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)
            );
}
项目:rest-jersey-utils    文件:CORSFeature.java   
@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;
}
项目:dremio-oss    文件:FirstTimeFeature.java   
@Override
public boolean configure(FeatureContext context) {
  Configuration configuration = context.getConfiguration();
  Boolean enabled = PropertyHelper.getProperty(configuration, RestServerV2.FIRST_TIME_API_ENABLE);
  Boolean testApiEnabled = PropertyHelper.getProperty(configuration, RestServerV2.TEST_API_ENABLE);

  // Default is not enabled
  if (enabled == null || !enabled) {
    return false;
  }

  boolean allowTestApis = testApiEnabled != null && testApiEnabled;

  // this is handled separately from firstTimeApi because we may enable the api only on master
  // but still register the filer on all nodes
  context.register(BootstrapResource.class);
  if (allowTestApis) {
    context.register(NoUserTestFilter.class);
  } else {
    context.register(NoUserFilter.class);
  }

  return true;
}
项目:dremio-oss    文件:TestResourcesFeature.java   
@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;
}
项目:dremio-oss    文件:DACAuthFilterFeature.java   
@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;
}
项目:JerseyRestful    文件:FastJsonFeature.java   
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;
}
项目:parsec-libraries    文件:ParsecValidationAutoDiscoverable.java   
@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(ParsecMoxyProvider.class)) {
        context.register(ParsecMoxyProvider.class, priority);
    }
    if (!config.isRegistered(JaxbExceptionMapper.class)) {
        context.register(JaxbExceptionMapper.class, priority);
    }
}
项目:mycore    文件:MCRJerseyDefaultFeature.java   
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    Class<?> resourceClass = resourceInfo.getResourceClass();
    Method resourceMethod = resourceInfo.getResourceMethod();
    if (isStaticContent(resourceClass, resourceMethod)) {
        // class or method is annotated with MCRStaticContent
        //   -> do not register any filter
        return;
    }
    String packageName = resourceClass.getPackage().getName();
    if (getPackages().contains(packageName)) {
        registerTransactionFilter(context);
        registerSessionHookFilter(context);
        registerAccessFilter(context, resourceClass, resourceMethod);
    }
}
项目:awplab-core    文件:BasicAuthKarafSecurityDynamicFeature.java   
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext featureContext) {

    AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());

    RequireBasicAuth requireBasicAuth = null;
    if (am.isAnnotationPresent(RequireBasicAuth.class)) {
        requireBasicAuth = am.getAnnotation(RequireBasicAuth.class);
    }
    else {
        requireBasicAuth = resourceInfo.getResourceClass().getAnnotation(RequireBasicAuth.class);
    }

    if (requireBasicAuth != null) {
        featureContext.register(new BasicAuthKarafSecurityRequestFilter(requireBasicAuth.limitToGroups(), requireBasicAuth.limitToRoles(), requireBasicAuth.karafRealm(), requireBasicAuth.requiresSecure(), requireBasicAuth.httpRealm()));
    }
}
项目:protox-webapp-archetype    文件:ConfigPropertyFeature.java   
@Override
public boolean configure(FeatureContext context) {
    Configuration configuration = context.getConfiguration();
    if (!configuration.isRegistered(ConfigPropertyResolver.class)) {
        LOGGER.debug("Register ConfigPropertyFeature");
        context.register(ConfigPropertyResolver.class);
        context.register(new AbstractBinder() {
            @Override
            protected void configure() {
                bind(ConfigPropertyResolver.class)
                        .to(new TypeLiteral<InjectionResolver<ConfigProperty>>() {})
                        .in(Singleton.class);
            }
        });
    }
    return true;
}
项目:openregister-java    文件:RegisterAuthDynamicFeature.java   
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
    final Annotation[][] parameterAnnotations = am.getParameterAnnotations();
    //@DenyAll shouldn't be attached to classes
    final boolean annotationOnClass = (resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class) != null) ||
            (resourceInfo.getResourceClass().getAnnotation(PermitAll.class) != null);
    final boolean annotationOnMethod = am.isAnnotationPresent(RolesAllowed.class) || am.isAnnotationPresent(DenyAll.class) ||
            am.isAnnotationPresent(PermitAll.class);

    if (annotationOnClass || annotationOnMethod) {
        context.register(filterClass);
    } else {
        for (Annotation[] annotations : parameterAnnotations) {
            for (Annotation annotation : annotations) {
                if (annotation instanceof Auth) {
                    context.register(filterClass);
                    return;
                }
            }
        }
    }
}
项目:jeesuite-libs    文件:DefaultFilterDynamicFeature.java   
@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);
        }

    }
}
项目:java-jaxrs    文件:ServerTracingDynamicFeature.java   
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    // TODO why it is called twice for the same endpoint
    if (!tracingDisabled(resourceInfo) && builder.allTraced) {
        log(resourceInfo);
        context.register(new ServerTracingFilter(
            builder.tracer,
            operationName(resourceInfo),
            builder.spanDecorators,
            builder.operationNameBuilder.build(resourceInfo.getResourceClass(), resourceInfo.getResourceMethod()),
            builder.skipPattern != null ? Pattern.compile(builder.skipPattern) : null),
            builder.priority);

        if (builder.traceSerialization) {
            context.register(new ServerTracingInterceptor(builder.tracer,
                builder.serializationSpanDecorators), builder.serializationPriority);
        }
    }
}
项目:java-dropwizard    文件:ServerTracingFeature.java   
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    Trace annotation = resourceInfo.getResourceMethod().getAnnotation(Trace.class);
    String operationName = this.operationName;
    if (annotation != null) {
        if (!annotation.operationName().equals("")) {
            operationName = annotation.operationName();
        }
        context.register(new ServerRequestTracingFilter(this.tracer, operationName,
            this.tracedAttributes, this.tracedProperties, this.decorator));
        context.register(new ServerResponseTracingFilter(this.tracer));  
    } else {
        if (traceAll) {
            context.register(new ServerRequestTracingFilter(this.tracer, operationName,
                this.tracedAttributes, this.tracedProperties, this.decorator));
            context.register(new ServerResponseTracingFilter(this.tracer));
        } 
    }
}
项目:syndesis-rest    文件:CacheForFilter.java   
@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);
    }
}
项目:jrestless-examples    文件:GuiceFeature.java   
@Override
public boolean configure(FeatureContext context) {
    InjectionManager injectionManager = InjectionManagerProvider.getInjectionManager(context);
    ServiceLocator locator;
    if (injectionManager instanceof ImmediateHk2InjectionManager) {
        locator = ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator();
    } else if (injectionManager instanceof DelayedHk2InjectionManager) {
        locator = ((DelayedHk2InjectionManager) injectionManager).getServiceLocator();
    } else {
        throw new IllegalStateException("expected an hk2 injection manager");
    }
    GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator);
    // register all your modules, here
    Injector injector = Guice.createInjector(new GreetingModule());
    GuiceIntoHK2Bridge guiceBridge = locator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(injector);
    return true;
}
项目:jersey-mvc-velocity    文件:VelocityMvcFeature.java   
@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();

    if (!config.isRegistered(VelocityViewProcessor.class)) {
        // Template Processor.
        context.register(VelocityViewProcessor.class);

        // MvcFeature.
        if (!config.isRegistered(MvcFeature.class)) {
            context.register(MvcFeature.class);
        }

        return true;
    }
    return false;
}
项目:rabbitframework    文件:FreemarkerMvcFeature.java   
@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();

    if (!config.isRegistered(FreemarkerViewProcessor.class)) {
        // Template Processor.
        context.register(FreemarkerViewProcessor.class);

        // MvcFeature.
        if (!config.isRegistered(MvcFeature.class)) {
            context.register(MvcFeature.class);
        }

        return true;
    }
    return false;
}
项目:drill    文件:AuthDynamicFeature.java   
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
  AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());

  // RolesAllowed on the method takes precedence over PermitAll
  RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
  if (ra != null) {
    configuration.register(AuthCheckFilter.INSTANCE);
    return;
  }

  // PermitAll takes precedence over RolesAllowed on the class
  // This avoids putting AuthCheckFilter in the request flow for all path's which
  // are defined under PermitAll annotation. That is requests for "/", "/login", "/mainLogin" and "/spnegoLogin"
  // path's doesn't go through AuthCheckFilter.
  if (am.isAnnotationPresent(PermitAll.class)) {
    // Do nothing.
    return;
  }

  // RolesAllowed on the class takes precedence over PermitAll
  ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
  if (ra != null) {
    configuration.register(AuthCheckFilter.INSTANCE);
  }
}
项目:sealion    文件:PermissionProvider.java   
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {

    if (resourceInfo.getResourceClass().getName()
            .startsWith(RootResource.class.getPackage().getName() + ".") == false) {
        return;
    }

    Permissions permissions = resourceInfo.getResourceMethod().getAnnotation(Permissions.class);
    if (permissions == null) {
        permissions = resourceInfo.getResourceClass().getAnnotation(Permissions.class);
    }
    if (permissions == null) {
        //TODO
        Logger.getLogger(PermissionProvider.class.getName())
                .warning(String.format("%s not annotated @Permissions",
                        resourceInfo.getResourceMethod().toGenericString()));
        return;
    }
    context.register(new PermissionTester(permissions));
}
项目:MyVidCoRe    文件:FrontendFeature.java   
@Override
public boolean configure(FeatureContext context) {
    context.register(MoxyJsonFeature.class);
    context.register(MoxyXmlFeature.class);
    context.register(MultiPartFeature.class);

    // internal features
    context.register(CacheFilter.class);
    context.register(GenericExceptionMapper.class);
    context.register(XmlMessageBodyReader.class);
    context.register(XmlMessageBodyWriter.class);

    Configuration.instance().getStrings("APP.Jersey.Features").forEach(cn -> {
        try {
            LOGGER.info("Register Jersey Feature: {}", cn);
            context.register(this.getClass().getClassLoader().loadClass(cn));
        } catch (ClassNotFoundException e) {
            LOGGER.error(e.getMessage(), e);
        }
    });

    return true;
}
项目:jee-user-auth    文件:AuthenticationFeatureTest.java   
@Test
public void shouldRegisterFilterWhenIsPermitAllReturnsFalse() throws Exception {
    // given
    AuthenticationFeature feature = new AuthenticationFeature() {
        @Override
        boolean isPermitAll(ResourceInfo resourceInfo) {
            return false;
        }
    };

    // when
    FeatureContext context = mock(FeatureContext.class);
    feature.configure(mock(ResourceInfo.class), context);

    // then
    verify(context).register(any(AuthenticationFilter.class));
}
项目:jee-user-auth    文件:AuthenticationFeatureTest.java   
@Test
public void shouldNotRegisterFilterWhenIsPermitAllReturnsTrue() throws Exception {
    // given
    AuthenticationFeature feature = new AuthenticationFeature() {
        @Override
        boolean isPermitAll(ResourceInfo resourceInfo) {
            return true;
        }
    };

    // when
    FeatureContext context = mock(FeatureContext.class);
    feature.configure(mock(ResourceInfo.class), context);

    // then
    verify(context, never()).register(any(AuthenticationFilter.class));
}
项目:micro-server    文件:JacksonFeature.java   
@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;
  }
项目:hawkular-commons    文件:TenantFeature.java   
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    Class<?> resourceClass = resourceInfo.getResourceClass();
    Method method = resourceInfo.getResourceMethod();

    boolean required = true;
    if (resourceClass.isAnnotationPresent(TenantRequired.class)) {
        required = resourceClass.getAnnotation(TenantRequired.class).value();
    }

    if (method.isAnnotationPresent(TenantRequired.class)) {
        required = method.getAnnotation(TenantRequired.class).value();
    }

    if (required) {
        context.register(TENANT_FILTER);
    }
}
项目:bootique-jersey    文件:GuiceBridgeFeature.java   
@Override
public boolean configure(FeatureContext context) {

    // for now only supporting Guice injection to resources

    // TODO: if we want to inject web environment objects back into Guice
    // services or to use JSR-330 annotations in Resources, we need
    // org.glassfish.hk2:guice-bridge integration

    // This feature can inject HK2 ServiceLocator in constructor, and then
    // we can bridge it both ways with Guice

    context.register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(GuiceInjectInjector.class).to(new TypeLiteral<InjectionResolver<com.google.inject.Inject>>() {
            }).in(Singleton.class);
        }
    });

    return true;
}
项目:soabase    文件:GuiceBundle.java   
private void applyInternalCommonConfig(FeatureContext context, InternalCommonConfig internalCommonConfig)
{
    for ( Class<?> clazz : internalCommonConfig.getClasses() )
    {
        log.info(String.format("Registering %s as a component", clazz));
        context.register(clazz);
    }
    for ( Object obj : internalCommonConfig.getInstances() )
    {
        log.info(String.format("Registering instance of %s as a component", obj.getClass()));
        context.register(obj);
    }
    for ( Map.Entry<String, Object> entry : internalCommonConfig.getProperties().entrySet() )
    {
        String key = entry.getKey();
        Object value = entry.getValue();
        log.info(String.format("Registering property key: %s\tvalue: %s", key, value));
        context.property(key, value);
    }
}
项目:soabase    文件:SoaBundle.java   
private void checkAdminGuiceFeature(final Environment environment, final JerseyEnvironment jerseyEnvironment)
{
    try
    {
        Feature feature = new Feature()
        {
            @Override
            public boolean configure(FeatureContext context)
            {
                for ( Object obj : environment.jersey().getResourceConfig().getSingletons() )
                {
                    if ( obj instanceof InternalFeatureRegistrations )
                    {
                        ((InternalFeatureRegistrations)obj).apply(context);
                    }
                }
                return true;
            }
        };
        jerseyEnvironment.register(feature);
    }
    catch ( Exception ignore )
    {
        // ignore - GuiceBundle not added
    }
}