Java 类javax.ws.rs.ext.Provider 实例源码

项目:oryx2    文件:OryxApplication.java   
private Set<Class<?>> doGetClasses() {
  String packages =
      servletContext.getInitParameter(OryxApplication.class.getName() + ".packages");
  log.info("Creating JAX-RS from endpoints in package(s) {}", packages);
  Objects.requireNonNull(packages);
  Set<Class<?>> classes = new HashSet<>();
  for (String thePackage : packages.split(",")) {
    Reflections reflections = new Reflections(thePackage);
    classes.addAll(getClassesInPackageAnnotatedBy(thePackage, reflections, Path.class));
    classes.addAll(getClassesInPackageAnnotatedBy(thePackage, reflections, Produces.class));
    classes.addAll(getClassesInPackageAnnotatedBy(thePackage, reflections, Provider.class));
  }
  // Want to configure these globally, but not depend on Jersey, even though it's
  // what will be used in practice by the provided apps.
  for (String optionalJerseyClass : new String[] {
        "org.glassfish.jersey.message.DeflateEncoder",
        "org.glassfish.jersey.message.GZipEncoder",
        "org.glassfish.jersey.server.filter.EncodingFilter"}) {
    if (ClassUtils.classExists(optionalJerseyClass)) {
      classes.add(ClassUtils.loadClass(optionalJerseyClass));
    }
  }
  log.debug("Found JAX-RS resources: {}", classes);
  return classes;
}
项目:redpipe    文件:FCSPlugin.java   
@Override
public Single<Void> deployToResteasy(VertxResteasyDeployment deployment) {
    JsonArray packages = AppGlobals.get().getConfig().getJsonArray("scan");
    if(packages == null) {
        System.err.println("Not scanning any packages, please specify the 'scan' array of packages in configuration");
    }else {
        String[] packagesToScan = (String[]) packages.getList().toArray(new String[packages.size()+1]);
        packagesToScan[packagesToScan.length-1] = "net.redpipe.engine";
        new FastClasspathScanner(packagesToScan)
            .matchClassesWithAnnotation(Path.class, klass -> {
                if(!Modifier.isAbstract(klass.getModifiers()))
                    deployment.getActualResourceClasses().add(klass);
            })
            .matchClassesWithAnnotation(Provider.class, klass -> {
                if(!Modifier.isAbstract(klass.getModifiers()))
                    deployment.getActualProviderClasses().add(klass);
            })
            .scan();
    }
    return Single.just(null);
}
项目:redpipe    文件:Server.java   
protected Single<VertxResteasyDeployment> setupResteasy(Class<?>... resourceOrProviderClasses) {
    // Build the Jax-RS hello world deployment
    VertxResteasyDeployment deployment = new VertxResteasyDeployment();
    deployment.getDefaultContextObjects().put(Vertx.class, AppGlobals.get().getVertx());
    deployment.getDefaultContextObjects().put(AppGlobals.class, AppGlobals.get());

    return doOnPlugins(plugin -> plugin.deployToResteasy(deployment)).map(v -> {
        for(Class<?> klass : resourceOrProviderClasses) {
            if(klass.isAnnotationPresent(Path.class))
                deployment.getActualResourceClasses().add(klass);
            if(klass.isAnnotationPresent(Provider.class))
                deployment.getActualProviderClasses().add(klass);
        }
        try {
            deployment.start();
        }catch(ExceptionInInitializerError err) {
            // rxjava behaves badly on LinkageError
            rethrow(err.getCause());
        }
        return deployment;
    }).doOnError(t -> t.printStackTrace());
}
项目:holon-jaxrs    文件:JerseyResourcesPostProcessor.java   
/**
 * Check whether given bean definition is a valid {@link Provider} or {@link Path} resource.
 * @param definition Bean definition
 * @param beanClass Bean class
 * @return <code>true</code> if it is a valid JAX-RS resource class
 */
private static boolean isJaxrsResourceClass(BeanDefinition definition, Class<?> beanClass) {
    // check Provider
    if (beanClass.isAnnotationPresent(Provider.class)) {
        if (!definition.isSingleton()) {
            throw new BeanDefinitionValidationException("Invalid JAX-RS @Provider bean definition for bean class ["
                    + beanClass + "]: JAX-RS providers must be singleton beans");
        }
        return true;
    }
    // check Path resource
    Class<?> pathClass = AnnotationUtils.getClassWithAnnotation(beanClass, Path.class);
    if (pathClass != null) {
        return true;
    }
    return false;
}
项目:oasp-tutorial-sources    文件:ServiceConfig.java   
@Bean
public Server jaxRsServer() {

  // List<Object> restServiceBeans = new
  // ArrayList<>(this.applicationContext.getBeansOfType(RestService.class).values());
  Collection<Object> restServices = findRestServices();
  if (restServices.isEmpty()) {
    LOG.info("No REST Services have been found. Rest Endpoint will not be enabled in CXF.");
    return null;
  }
  Collection<Object> providers = this.applicationContext.getBeansWithAnnotation(Provider.class).values();

  JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
  factory.setBus(springBus());
  factory.setAddress(URL_FOLDER_REST);
  // factory.set
  factory.setServiceBeans(new ArrayList<>(restServices));
  factory.setProviders(new ArrayList<>(providers));

  return factory.create();
}
项目:coco    文件:CocoRestServer.java   
public void start() {

        ResteasyDeployment dp = new ResteasyDeployment();

        Collection<Object> providers = ac.getBeansWithAnnotation(Provider.class).values();
        Collection<Object> controllers = ac.getBeansWithAnnotation(Controller.class).values();

        Assert.notEmpty(controllers);

        // extract providers
        if (providers != null) {
            dp.getProviders().addAll(providers);
        }
        // extract only controller annotated beans
        dp.getResources().addAll(controllers);

        netty = new NettyJaxrsServer();
        netty.setDeployment(dp);
        netty.setIoWorkerCount(ioWorkerCount);
        netty.setExecutorThreadCount(executorThreadCount);
        netty.setPort(port);
        netty.setRootResourcePath(rootResourcePath);
        netty.setSecurityDomain(null);
        netty.start();
        LOGGER.info("rest-netty-server started , port {}", port);
    }
项目:Cheddar    文件:RestResourceConfig.java   
@Autowired
public RestResourceConfig(final ApplicationContext applicationContext) {
    property("contextConfig", applicationContext);
    scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.resetFilters(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Path.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(Provider.class));
    register(RequestContextFilter.class);
    register(MultiPartFeature.class);
    register(ObjectMapperProvider.class);
    register(JacksonFeature.class);
    registerResources("com.clicktravel.cheddar.rest.exception.mapper", "com.clicktravel.cheddar.server.http.filter",
            "com.clicktravel.cheddar.server.rest.resource.status", "com.clicktravel.services",
            "com.clicktravel.cheddar.rest.body.writer");
    property(ServerProperties.LOCATION_HEADER_RELATIVE_URI_RESOLUTION_DISABLED, true);
}
项目:LICPRO-Android-Server-FileBox    文件:RestApplication.java   
/**
 * Default constructor
 */
public RestApplication() {
    List<Class<?>> classes = CPScanner.scanClasses(new ClassFilter().packageName("fr.devnied.filebox.*").annotation(Provider.class));
    for (Class<?> clazz : classes) {
        try {
            Object obj = null;
            try {
                obj = SpringContextHolder.getApplicationContext().getBean(clazz);
            } catch (BeansException e) {
                // do nothing
            }
            if (obj == null) {
                obj = clazz.newInstance();
            }
            singletons.add(obj);
        } catch (InstantiationException | IllegalAccessException ex) {
            Logger.getLogger(RestApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
项目:shiro-guice-async-webapp    文件:BootstrapRestPackagesModule.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void configure() {
    logger.entry();
    String[] pkgs = GenericBootstrapConstants.REST_EASY_REST_PACKAGES.split(",");

    for(String pkg:pkgs){
        //if(pkg.trim().endsWith(GenericBootstrapConstants.REST_EASY_REST_PACKAGES_SUFFIX)){
            logger.info("found RESTful package: {}",pkg.trim());
            Class[] lst = null;
            try {
                lst = getClasses(pkg.trim());
            } catch (ClassNotFoundException | IOException e) {
                logger.error("{}, {}", e.getClass().getName() ,e.getMessage());
                e.printStackTrace();
            }
            for (Class c: lst){
                if(c.isAnnotationPresent(Path.class) || c.isAnnotationPresent(Provider.class)){
                    logger.info("found RestEasy Resource: {}",c.getName());
                    bind(c);
                }
            }
        //}
    }
    logger.exit();
}
项目:git-server    文件:GitServerModule.java   
@Override
protected void configure() {
    install(new RequestScopeModule());
    install(new JaxrsModule());
    requireBinding(ObjectMapper.class);

    findResourcesWith(Path.class);
    findResourcesWith(Provider.class);

    bind(BaseApi.class).to(BaseApiImpl.class);
    bind(UsersApi.class).to(UsersApiImpl.class);
    bind(GroupsApi.class).to(GroupsApiImpl.class);
    bind(RepositoriesApi.class).to(RepositoriesApiImpl.class);
    bind(RepositoryFacadeFactory.class).to(JGitRepositoryFacadeFactory.class);

    bindSubResourceFactory(GroupApi.class, GroupApiImpl.class, GroupApiFactory.class);
    bindSubResourceFactory(CommitApi.class, CommitApiImpl.class, CommitApiFactory.class);
    bindSubResourceFactory(BranchApi.class, BranchApiImpl.class, BranchApiFactory.class);
    bindSubResourceFactory(RepositoryApi.class, RepositoryApiImpl.class, RepositoryApiFactory.class);

    bind(Config.class).toInstance(config);
}
项目:shiro-guice-resteasy-webapp    文件:GuiceRestEasyFilterDispatcher.java   
@Override
public void init(FilterConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    Registry registry = getDispatcher().getRegistry();
    ResteasyProviderFactory providerFactory = getDispatcher().getProviderFactory();

    for (final Binding<?> binding : injector.getBindings().values()) {
        Type type = binding.getKey().getTypeLiteral().getType();
        if (type instanceof Class) {
            Class<?> beanClass = (Class<?>) type;
            if (GetRestful.isRootResource(beanClass)) {
                ResourceFactory resourceFactory = new GuiceResourceFactory(binding.getProvider(), beanClass);
                log.info("registering factory for {}", beanClass.getName());
                registry.addResourceFactory(resourceFactory);
            }

            if (beanClass.isAnnotationPresent(Provider.class)) {
                log.info("registering provider instance for {}", beanClass.getName());
                providerFactory.registerProviderInstance(binding.getProvider().get());
            }
        }
    }
}
项目:camunda-bpm-platform    文件:CXFServerBootstrap.java   
private void separateProvidersAndResources(Application application, List<Class<?>> resourceClasses, List<Object> providerInstances) {
  Set<Class<?>> classes = application.getClasses();

  for (Class<?> clazz : classes) {
    Annotation[] annotations = clazz.getAnnotations();
    for (Annotation annotation : annotations) {
      if (annotation.annotationType().equals(Provider.class)) {
        // for providers we have to create an instance
        try {
          providerInstances.add(clazz.newInstance());
          break;
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      } else if (annotation.annotationType().equals(Path.class)) {
        resourceClasses.add(clazz);
        break;
      }
    }
  }
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:ComponentTestCase.java   
@Test
public void testConfiguration() throws Exception {
    logger.info("start REST Configuration test");
    Client client = newClient();
    Configuration configuration = client.getConfiguration();
    Set<Class<?>> classes = configuration.getClasses();
    for (Class<?> clazz : classes) {
        assertTrue("verify if the class is a rest component or provider",
                MessageBodyReader.class.isAssignableFrom(clazz) || MessageBodyWriter.class.isAssignableFrom(clazz)
                        || clazz.isAnnotationPresent(Provider.class)
                        || DynamicFeature.class.isAssignableFrom(clazz));
        Map<Class<?>, Integer> contracts = configuration.getContracts(clazz);
        assertFalse("each class has different contracts", contracts.isEmpty());
        for (Class<?> contract : contracts.keySet()) {
            int value = contracts.get(contract);
            assertTrue("verify if the contract is a rest component or provider",
                    value == 5000 || value == 4000 || value == 3000 || value == 0);
        }
    }
    Set<Object> instances = configuration.getInstances();
    assertTrue("by default there are not instances", instances.isEmpty());
    Map<String, Object> properties = configuration.getProperties();
    assertTrue("by default there are not properties", properties.isEmpty());
    MyComponent myComponent = new MyComponent();
    client.register(myComponent);
    instances = configuration.getInstances();
    assertFalse("Added instance", instances.isEmpty());
    for (Object instance : instances) {
        if (instance instanceof MyComponent)
            assertTrue("MyComponent is registered and active", configuration.isEnabled((Feature) instance));
    }
    assertEquals("Added property through MyComponent", 1, properties.size());
    boolean property = (Boolean) properties.get("configured_myComponent");
    assertEquals("configured_myComponent ok!", true, property);
    assertEquals("type CLIENT by default", CLIENT, configuration.getRuntimeType());
}
项目:act-platform    文件:RestModule.java   
@Override
protected void configure() {
  bindAnnotatedClasses(API_PACKAGE, Path.class);
  bindAnnotatedClasses(MAPPINGS_PACKAGE, Provider.class);
  bindSwagger();
  bind(ApiServer.class).in(Scopes.SINGLETON);
}
项目:didi-eureka-server    文件:EurekaServerAutoConfiguration.java   
/**
 * Construct a Jersey {@link javax.ws.rs.core.Application} with all the resources
 * required by the Eureka server.
 */
@Bean
public javax.ws.rs.core.Application jerseyApplication(Environment environment,
        ResourceLoader resourceLoader) {

    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
            false, environment);

    // Filter to include only classes that have a particular annotation.
    //
    provider.addIncludeFilter(new AnnotationTypeFilter(Path.class));
    provider.addIncludeFilter(new AnnotationTypeFilter(Provider.class));

    // Find classes in Eureka packages (or subpackages)
    //
    Set<Class<?>> classes = new HashSet<Class<?>>();
    for (String basePackage : EUREKA_PACKAGES) {
        Set<BeanDefinition> beans = provider.findCandidateComponents(basePackage);
        for (BeanDefinition bd : beans) {
            Class<?> cls = ClassUtils.resolveClassName(bd.getBeanClassName(),
                    resourceLoader.getClassLoader());
            classes.add(cls);
        }
    }

    // Construct the Jersey ResourceConfig
    //
    Map<String, Object> propsAndFeatures = new HashMap<String, Object>();
    propsAndFeatures.put(
            // Skip static content used by the webapp
            ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX,
            EurekaConstants.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*");

    DefaultResourceConfig rc = new DefaultResourceConfig(classes);
    rc.setPropertiesAndFeatures(propsAndFeatures);

    return rc;
}
项目:payara-micro-docker-starter-kit    文件:RestApplication.java   
@Override
public Set<Class<?>> getClasses() {
    Set<Class<?>> resources = new HashSet<>();
    String PACKAGE_NAME = RestApplication.class.getPackage().getName();
    resources.addAll(getTypesAnnotatedWith(PACKAGE_NAME, Path.class));
    resources.addAll(getTypesAnnotatedWith(PACKAGE_NAME, Provider.class));
    resources.add(JacksonFeature.class);
    return resources;
}
项目:osgi-jaxrs-extracted    文件:AddonsServiceTrackerCustomizer.java   
@Override
public CXFJaxRsServiceRegistrator addingService(
    ServiceReference<CXFJaxRsServiceRegistrator> reference) {

    Thread thread = Thread.currentThread();

    ClassLoader contextClassLoader =
        thread.getContextClassLoader();

    CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator =
        _bundleContext.getService(reference);

    try {
        thread.setContextClassLoader(_classLoader);

        if (_serviceClass.isAnnotationPresent(Provider.class)) {
            cxfJaxRsServiceRegistrator.addProvider(_service);
        } else {
            cxfJaxRsServiceRegistrator.addService(_service);
        }


        return cxfJaxRsServiceRegistrator;
    }
    catch (Exception e) {
        _bundleContext.ungetService(reference);

        throw e;
    }
    finally {
        thread.setContextClassLoader(contextClassLoader);
    }
}
项目:osgi-jaxrs-extracted    文件:AddonsServiceTrackerCustomizer.java   
@Override
public void removedService(
    ServiceReference<CXFJaxRsServiceRegistrator> reference,
    CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator) {

    if (_serviceClass.isAnnotationPresent(Provider.class)) {
        cxfJaxRsServiceRegistrator.removeProvider(_service);
    } else {
        cxfJaxRsServiceRegistrator.removeService(_service);
    }

    _bundleContext.ungetService(reference);
}
项目:openregister-java    文件:ConsistencyFilter.java   
@Inject
public ConsistencyFilter(final javax.inject.Provider<RegisterName> registerPrimaryKey,
                         final UriInfo uriInfo,
                         javax.inject.Provider<RegisterContext> registerContext) {
    this.registerPrimaryKey = registerPrimaryKey;
    this.uriInfo = uriInfo;
    this.registerContext = registerContext;
}
项目:Netty-Resteasy-Spring    文件:NettyServer.java   
public void start() {
    ResteasyDeployment dp = new ResteasyDeployment();
    Collection<Object> providers = ac.getBeansWithAnnotation(Provider.class).values();
    Collection<Object> controllers = ac.getBeansWithAnnotation(Controller.class).values();
    Assert.notEmpty(controllers);
    // extract providers
    if (providers != null) {
        dp.getProviders().addAll(providers);
    }
    // extract only controller annotated beans
    dp.getResources().addAll(controllers);
    Map<String, Object> channelOptions = new HashMap<String, Object>();
    channelOptions.put("reuseAddress", true);
    List<ChannelHandler> channelHandlerList = new ArrayList<ChannelHandler>();
    channelHandlerList.add(channelHandler);
    channelHandlerList.add(idleStateHandler);
    channelHandlerList.add(healthCheckHandler);
    netty = new NettyJaxrsServer();
    netty.setChannelOptions(channelOptions);
    netty.setDeployment(dp);
    netty.setPort(port);
    netty.setRootResourcePath("/resteasy");
    netty.setIoWorkerCount(ioWorkerCount);
    netty.setExecutorThreadCount(executorThreadCount);
    netty.setMaxRequestSize(maxRequestSize);
    netty.setSSLContext(sslContext);
    netty.setKeepAlive(true);
    netty.setChannelHandlers(channelHandlerList);
    netty.setSecurityDomain(null);
    netty.start();
}
项目:sample.consulservicediscovery    文件:RestModule.java   
public RestModule(String host, int port, String contextRoot, WebAnnotations webAnnotations) {
    try {
        InfoStore infoStore = webAnnotations.getInfoStore();

        webAnnotations.openInfoStore();

        // Ignore all complexities like @Parent annotations for the moment,
        // and also inheritance.

        AnnotationTargets_Targets annotationTargets = webAnnotations.getAnnotationTargets();

        String applicationPath = "";
        Set<String> classesWithApplicationPath = annotationTargets
                .getAnnotatedClasses(ApplicationPath.class.getName(), POLICY_SEED);
        if (classesWithApplicationPath.size() == 0) {
            System.err.println("The REST application path must be set using annotations. ");
        } else if (classesWithApplicationPath.size() > 1) {
            System.err.println("There should only be one REST application path per application.");
        } else {
            applicationPath = getValue(infoStore, ApplicationPath.class,
                    classesWithApplicationPath.iterator().next());
        }

        // Scan annotation for @Provider, @Path
        processAnnotations(host, port, contextRoot, infoStore, annotationTargets, Provider.class, applicationPath);
        processAnnotations(host, port, contextRoot, infoStore, annotationTargets, Path.class, applicationPath);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:webshooters    文件:GuiceRestEasyFilterDispatcher.java   
@Override
public void init(FilterConfig servletConfig) throws ServletException {
    logger.entry();
    servletContainerDispatcher = new ServletContainerDispatcher();
    FilterBootstrap bootstrap = new FilterBootstrap(servletConfig);
    servletContext = servletConfig.getServletContext();
    servletContainerDispatcher.init(servletContext, bootstrap, this, this);
    servletContainerDispatcher.getDispatcher().getDefaultContextObjects().put(FilterConfig.class, servletConfig);

    if (injector == null)
        injector = (Injector) servletConfig.getServletContext().getAttribute(Injector.class.getName());

    Registry registry = getDispatcher().getRegistry();
    ResteasyProviderFactory providerFactory = getDispatcher().getProviderFactory();

    for (final Binding<?> binding : injector.getBindings().values()) {
        Type type = binding.getKey().getTypeLiteral().getType();
        if (type instanceof Class) {
            Class<?> beanClass = (Class<?>) type;
            if (GetRestful.isRootResource(beanClass)) {
                ResourceFactory resourceFactory = new GuiceResourceFactory(binding.getProvider(), beanClass);
                logger.info("registering factory for {}", beanClass.getName());
                registry.addResourceFactory(resourceFactory);
            }

            if (beanClass.isAnnotationPresent(Provider.class)) {
                logger.info("registering provider instance for {}", beanClass.getName());
                providerFactory.registerProviderInstance(binding.getProvider().get());
            }
        }
    }
    logger.exit();
}
项目:resteasy-spring-boot    文件:ResteasyEmbeddedServletInitializer.java   
private void findJaxrsResourcesAndProviderClasses(ConfigurableListableBeanFactory beanFactory) {
    logger.debug("Finding JAX-RS resources and providers Spring bean classes");

    String[] resourceBeans = beanFactory.getBeanNamesForAnnotation(Path.class);
    String[] providerBeans = beanFactory.getBeanNamesForAnnotation(Provider.class);

    if(resourceBeans != null) {
        for(String resourceBean : resourceBeans) {
            allResources.add(beanFactory.getType(resourceBean));
        }
    }

    if(providerBeans != null) {
        for(String providerBean : providerBeans) {
            providers.add(beanFactory.getType(providerBean));
        }
    }

    if(logger.isDebugEnabled()) {
        for (Object resourceClass : allResources.toArray()) {
            logger.debug("JAX-RS resource class found: {}", ((Class) resourceClass).getName());
        }
    }
    if(logger.isDebugEnabled()) {
        for (Object providerClass: providers.toArray()) {
            logger.debug("JAX-RS provider class found: {}", ((Class) providerClass).getName());
        }
    }
}
项目:robe    文件:ProviderScanner.java   
@Override
public void scanAndAdd(Environment environment, Injector injector, Reflections reflections) {
    Set<Class<?>> providerClasses = reflections.getTypesAnnotatedWith(Provider.class);
    for (Class<?> provider : providerClasses) {
        environment.jersey().register(provider);
        LOGGER.info("Added provider class: " + provider);
    }
}
项目:jaxrs-unit    文件:JaxrsServer.java   
public Collection<Class<?>> getProviders() {
    List<Class<?>> providers = new ArrayList<>();
    for (Class<?> classObject : classes) {
        if (classObject.isAnnotationPresent(Provider.class)) {
            providers.add(classObject);
        }
    }
    return providers;
}
项目:dohko    文件:ApplicationConfig.java   
/**
 * Register JAX-RS application components.
 */
public ApplicationConfig()
{
    Reflections reflections = new Reflections("org.excalibur");
    RESOURCES = Collections.unmodifiableList(new ArrayList<Class<?>>(reflections.getTypesAnnotatedWith(Path.class)));

    register(RequestContextFilter.class);
    registerResources(RESOURCES);
    registerResources(reflections.getTypesAnnotatedWith(Provider.class));


}
项目:spring-cloud-netflix    文件:EurekaServerAutoConfiguration.java   
/**
 * Construct a Jersey {@link javax.ws.rs.core.Application} with all the resources
 * required by the Eureka server.
 */
@Bean
public javax.ws.rs.core.Application jerseyApplication(Environment environment,
        ResourceLoader resourceLoader) {

    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
            false, environment);

    // Filter to include only classes that have a particular annotation.
    //
    provider.addIncludeFilter(new AnnotationTypeFilter(Path.class));
    provider.addIncludeFilter(new AnnotationTypeFilter(Provider.class));

    // Find classes in Eureka packages (or subpackages)
    //
    Set<Class<?>> classes = new HashSet<>();
    for (String basePackage : EUREKA_PACKAGES) {
        Set<BeanDefinition> beans = provider.findCandidateComponents(basePackage);
        for (BeanDefinition bd : beans) {
            Class<?> cls = ClassUtils.resolveClassName(bd.getBeanClassName(),
                    resourceLoader.getClassLoader());
            classes.add(cls);
        }
    }

    // Construct the Jersey ResourceConfig
    //
    Map<String, Object> propsAndFeatures = new HashMap<>();
    propsAndFeatures.put(
            // Skip static content used by the webapp
            ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX,
            EurekaConstants.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*");

    DefaultResourceConfig rc = new DefaultResourceConfig(classes);
    rc.setPropertiesAndFeatures(propsAndFeatures);

    return rc;
}
项目:shiro-guice-async-webapp    文件:GuiceRestEasyFilterDispatcher.java   
@Override
public void init(FilterConfig servletConfig) throws ServletException {
    logger.entry();
    servletContainerDispatcher = new ServletContainerDispatcher();
    FilterBootstrap bootstrap = new FilterBootstrap(servletConfig);
    servletContext = servletConfig.getServletContext();
    servletContainerDispatcher.init(servletContext, bootstrap, this, this);
    servletContainerDispatcher.getDispatcher().getDefaultContextObjects().put(FilterConfig.class, servletConfig);

    if(injector == null)
        injector = (Injector) servletConfig.getServletContext().getAttribute(Injector.class.getName());

    Registry registry = getDispatcher().getRegistry();
    ResteasyProviderFactory providerFactory = getDispatcher().getProviderFactory();

    for (final Binding<?> binding : injector.getBindings().values()) {
        Type type = binding.getKey().getTypeLiteral().getType();
        if (type instanceof Class) {
            Class<?> beanClass = (Class<?>) type;
            if (GetRestful.isRootResource(beanClass)) {
                ResourceFactory resourceFactory = new GuiceResourceFactory(binding.getProvider(), beanClass);
                logger.info("registering factory for {}", beanClass.getName());
                registry.addResourceFactory(resourceFactory);
            }

            if (beanClass.isAnnotationPresent(Provider.class)) {
                logger.info("registering provider instance for {}", beanClass.getName());
                providerFactory.registerProviderInstance(binding.getProvider().get());
            }
        }
    }
    logger.exit();
}
项目:hammock    文件:JerseyCdiExtension.java   
public <T> void observeProviders(@WithAnnotations({ Provider.class }) @Observes ProcessAnnotatedType<T> event) {
    AnnotatedType<T> annotatedType = event.getAnnotatedType();

    if (!annotatedType.getJavaClass().isInterface()) {
        this.providers.add(annotatedType.getJavaClass());
    }
}
项目:pi    文件:SpringResourceConfigTest.java   
@SuppressWarnings("unchecked")
@Before
public void doBefore() throws IOException {
    resourceConfig = new SpringResourceConfig("com.bt.pi.ops.website");

    myPathClass = new MyPathClass();
    myProviderClass = new MyProviderClass();
    appContext = mock(ApplicationContext.class);
    objectMap = mock(Map.class);
    beans = new ArrayList<Object>();

    when(objectMap.values()).thenReturn(beans);
    when(appContext.getBeansWithAnnotation(Path.class)).thenReturn(objectMap);
    when(appContext.getBeansWithAnnotation(Provider.class)).thenReturn(objectMap);
}
项目:tomee    文件:RESTService.java   
private static <T> boolean isProvider(final Class<T> clazz) {
    return MessageBodyReader.class.isAssignableFrom(clazz) ||
            MessageBodyWriter.class.isAssignableFrom(clazz) ||
            ParamConverter.class.isAssignableFrom(clazz) ||
            ContainerRequestFilter.class.isAssignableFrom(clazz) ||
            ContainerResponseFilter.class.isAssignableFrom(clazz) ||
            ReaderInterceptor.class.isAssignableFrom(clazz) ||
            WriterInterceptor.class.isAssignableFrom(clazz) ||
            ParamConverterProvider.class.isAssignableFrom(clazz) ||
            ContextResolver.class.isAssignableFrom(clazz) ||
            new MetaAnnotatedClass<>(clazz).isAnnotationPresent(Provider.class);
}
项目:enviroCar-server    文件:PhenomenonRDFEncoder.java   
@Override
protected String getURI(Phenomenon t,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get()
            .path(RootResource.class)
            .path(RootResource.PHENOMENONS)
            .path(PhenomenonsResource.PHENOMENON)
            .build(t.getName())
            .toASCIIString();
}
项目:enviroCar-server    文件:GroupRDFEncoder.java   
@Override
protected String getURI(Group t,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get().path(RootResource.class)
            .path(RootResource.GROUPS)
            .path(GroupsResource.GROUP)
            .build(t.getName()).toASCIIString();
}
项目:enviroCar-server    文件:GroupsRDFEncoder.java   
@Override
protected String getURI(Group v,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get().path(RootResource.class)
            .path(RootResource.GROUPS)
            .path(GroupsResource.GROUP)
            .build(v.getName()).toASCIIString();
}
项目:enviroCar-server    文件:PhenomenonsRDFEncoder.java   
@Override
protected String getURI(Phenomenon t,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get()
            .path(RootResource.class)
            .path(RootResource.PHENOMENONS)
            .path(PhenomenonsResource.PHENOMENON)
            .build(t.getName())
            .toASCIIString();
}
项目:enviroCar-server    文件:SensorRDFEncoder.java   
@Override
protected String getURI(Sensor t,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get()
            .path(RootResource.class)
            .path(RootResource.SENSORS)
            .path(SensorsResource.SENSOR)
            .build(t.getIdentifier())
            .toASCIIString();
}
项目:enviroCar-server    文件:FuelingsRDFEncoder.java   
@Override
protected String getURI(Fueling v,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get().path(RootResource.class)
            .path(RootResource.USERS)
            .path(UsersResource.USER)
            .path(UserResource.FUELINGS)
            .path(FuelingsResource.FUELING)
            .build(v.getUser().getName(),
                   v.getIdentifier()).toASCIIString();
}
项目:enviroCar-server    文件:SensorsRDFEncoder.java   
@Override
protected String getURI(Sensor t,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get()
            .path(RootResource.class)
            .path(RootResource.SENSORS)
            .path(SensorsResource.SENSOR)
            .build(t.getIdentifier())
            .toASCIIString();
}
项目:enviroCar-server    文件:MeasurementRDFEncoder.java   
@Override
protected String getURI(Measurement t,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get()
            .path(RootResource.class)
            .path(RootResource.MEASUREMENTS)
            .path(MeasurementsResource.MEASUREMENT)
            .build(t.getIdentifier())
            .toASCIIString();
}
项目:enviroCar-server    文件:UserRDFEncoder.java   
@Override
protected String getURI(User t,
                        com.google.inject.Provider<UriBuilder> uri) {
    return uri.get()
            .path(RootResource.class)
            .path(RootResource.USERS)
            .path(UsersResource.USER)
            .build(t.getName())
            .toASCIIString();
}