org.glassfish.jersey.internal.inject.Injections Java Examples

The following examples show how to use org.glassfish.jersey.internal.inject.Injections. 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: AbstractAnnotatedEndpointMeta.java    From ameba with MIT License 6 votes vote down vote up
protected ServerEndpointConfig buildServerEndpointConfig(
        String path,
        WebSocket wseAnnotation,
        Class<?> annotatedClass,
        String[] subProtocols,
        List<Class<? extends Encoder>> encoderClasses,
        List<Class<? extends Decoder>> decoderClasses) {
    ServerEndpointConfig.Builder builder =
            ServerEndpointConfig.Builder
                    .create(annotatedClass, path)
                    .encoders(encoderClasses)
                    .decoders(decoderClasses)
                    .subprotocols(Arrays.asList(subProtocols));
    if (!wseAnnotation.configurator().equals(ServerEndpointConfig.Configurator.class)) {
        builder = builder.configurator(Injections.getOrCreate(manager, wseAnnotation.configurator()));
    }
    return builder.build();
}
 
Example #2
Source File: RestApplication.java    From jerseyoauth2 with MIT License 6 votes vote down vote up
@Inject
   public RestApplication(ServiceLocator serviceLocator) {
	DynamicConfiguration dc = Injections.getConfiguration(serviceLocator);

       Injections.addBinding(Injections.newBinder(DatabaseClientService.class).to(IClientService.class),dc);
       Injections.addBinding(Injections.newBinder(Configuration.class).to(IConfiguration.class),dc);
       Injections.addBinding(Injections.newBinder(Configuration.class).to(IRSConfiguration.class),dc);
       Injections.addBinding(Injections.newBinder(DefaultPrincipalUserService.class).to(IUserService.class),dc);
       Injections.addBinding(Injections.newBinder(CachingAccessTokenStorage.class).to(IAccessTokenStorageService.class),dc);
       Injections.addBinding(Injections.newBinder(IntegratedAccessTokenVerifier.class).to(IAccessTokenVerifier.class),dc);
       Injections.addBinding(Injections.newBinder(RequestFactory.class).to(IRequestFactory.class),dc);
       Injections.addBinding(Injections.newBinder(MD5TokenGenerator.class).to(ITokenGenerator.class),dc);
       Injections.addBinding(Injections.newBinder(UUIDClientIdGenerator.class).to(IClientIdGenerator.class),dc);
	
	EntityManagerFactory emf = new PersistenceProvider().get();
       Injections.addBinding(Injections.newBinder(emf).to(EntityManagerFactory.class),dc);
       
       CacheManager cacheManager = new DefaultCacheManagerProvider().get();
       Injections.addBinding(Injections.newBinder(cacheManager).to(CacheManager.class),dc);
       
       dc.commit();
}
 
Example #3
Source File: TypeFactory.java    From shiro-jersey with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(DynamicConfiguration config) {
  Injections.addBinding(
          Injections.newFactoryBinder(this).to(type).in(Singleton.class),
          config);
  Injections.addBinding(
          Injections.newBinder(this).to(ValueFactoryProvider.class),
          config);
}
 
Example #4
Source File: TypeFactory.java    From shiro-jersey with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(DynamicConfiguration config) {
  Injections.addBinding(
          Injections.newFactoryBinder(this).to(type).in(Singleton.class),
          config);
  Injections.addBinding(
          Injections.newBinder(this).to(ValueFactoryProvider.class),
          config);
}
 
Example #5
Source File: AbstractAnnotatedEndpointMeta.java    From ameba with MIT License 4 votes vote down vote up
protected <T> Object getEndpointInstance(Class<T> endpointClass) {
    return Injections.getOrCreate(manager, endpointClass);
}
 
Example #6
Source File: DefaultServerEndpointConfig.java    From ameba with MIT License 4 votes vote down vote up
/**
 * <p>Constructor for DefaultServerEndpointConfig.</p>
 *
 * @param manager a manager
 * @param endpointClass  a {@link java.lang.Class} endpoint class.
 * @param webSocketConf  a {@link ameba.websocket.WebSocket} object.
 */
public DefaultServerEndpointConfig(final InjectionManager manager,
                                   Class endpointClass,
                                   final WebSocket webSocketConf) {
    path = webSocketConf.path();
    subprotocols = Arrays.asList(webSocketConf.subprotocols());
    encoders = Lists.newArrayList(webSocketConf.encoders());
    decoders = Lists.newArrayList(webSocketConf.decoders());
    for (Class<? extends Extension> extensionClass : webSocketConf.extensions()) {
        extensions.add(Injections.getOrCreate(manager, extensionClass));
    }
    final WebSocketEndpointProvider provider = manager.getInstance(WebSocketEndpointProvider.class);

    final EndpointMeta endpointMeta = provider.parseMeta(endpointClass, webSocketConf);

    final ServerEndpointConfig.Configurator cfgr =
            Injections.getOrCreate(manager, webSocketConf.configurator());
    serverEndpointConfigurator = new ServerEndpointConfig.Configurator() {

        @Override
        public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) {
            return cfgr.getNegotiatedSubprotocol(supported, requested);
        }

        @Override
        public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) {
            return cfgr.getNegotiatedExtensions(installed, requested);
        }

        @Override
        public boolean checkOrigin(String originHeaderValue) {
            return cfgr.checkOrigin(originHeaderValue);
        }

        @Override
        public void modifyHandshake(ServerEndpointConfig sec,
                                    HandshakeRequest request, HandshakeResponse response) {
            cfgr.modifyHandshake(sec, request, response);
        }

        @Override
        public <T> T getEndpointInstance(Class<T> eClass) throws InstantiationException {
            if (EndpointDelegate.class.equals(eClass)) {
                return eClass.cast(new EndpointDelegate(endpointMeta));
            }
            return cfgr.getEndpointInstance(eClass);
        }
    };
}