org.glassfish.jersey.internal.inject.InjectionManager Java Examples
The following examples show how to use
org.glassfish.jersey.internal.inject.InjectionManager.
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: Jersey2Module.java From dropwizard-guicey with MIT License | 6 votes |
@Override protected void configure() { checkHkFirstMode(); final EnumSet<DispatcherType> types = context.option(GuiceFilterRegistration); final boolean guiceServletSupport = !types.isEmpty(); // injector not available at this point, so using provider final InjectorProvider provider = new InjectorProvider(application); install(new GuiceBindingsModule(provider, guiceServletSupport)); final GuiceFeature component = new GuiceFeature(provider, context.stat(), context.lifecycle(), context.option(UseHkBridge)); bind(InjectionManager.class).toProvider(component); // avoid registration when called within guice report if (currentStage() != Stage.TOOL) { environment.jersey().register(component); } if (guiceServletSupport) { install(new GuiceWebModule(environment, types)); } }
Example #2
Source File: ServiceRequestHandlerTest.java From jrestless with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void delegateRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() { Context context = mock(Context.class); DefaultServiceRequest request = new DefaultServiceRequest(null, new HashMap<>(), URI.create("/"), "GET"); RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, request); Ref<ServiceRequest> serviceRequestRef = mock(Ref.class); Ref<Context> contextRef = mock(Ref.class); InjectionManager injectionManager = mock(InjectionManager.class); when(injectionManager.getInstance(SERVICE_REQUEST_TYPE)).thenReturn(serviceRequestRef); when(injectionManager.getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE)).thenReturn(contextRef); requestScopedInitializer.initialize(injectionManager); verify(serviceRequestRef).set(request); verify(contextRef).set(context); }
Example #3
Source File: GatewayRequestHandlerTest.java From jrestless with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void delegateRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() { Context context = mock(Context.class); DefaultGatewayRequest request = new DefaultGatewayRequest(); request.setPath("/"); request.setHttpMethod("GET"); RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, request); Ref<GatewayRequest> gatewayRequestRef = mock(Ref.class); Ref<Context> contextRef = mock(Ref.class); InjectionManager injectionManager = mock(InjectionManager.class); when(injectionManager.getInstance(GATEWAY_REQUEST_TYPE)).thenReturn(gatewayRequestRef); when(injectionManager.getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE)).thenReturn(contextRef); requestScopedInitializer.initialize(injectionManager); verify(gatewayRequestRef).set(request); verify(contextRef).set(context); }
Example #4
Source File: SnsRequestHandlerTest.java From jrestless with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void delegateRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() { Context context = mock(Context.class); SNS sns = new SNS(); sns.setTopicArn(":t"); SNSRecord snsRecord = new SNSRecord(); snsRecord.setSns(sns); RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, snsRecord); Ref<SNSRecord> snsRef = mock(Ref.class); Ref<Context> contextRef = mock(Ref.class); InjectionManager injectionManager = mock(InjectionManager.class); when(injectionManager.getInstance(SNS_RECORD_TYPE)).thenReturn(snsRef); when(injectionManager.getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE)).thenReturn(contextRef); requestScopedInitializer.initialize(injectionManager); verify(snsRef).set(snsRecord); verify(contextRef).set(context); }
Example #5
Source File: ModelInterceptor.java From ameba with MIT License | 6 votes |
/** * /path?filter=p.in(1,2)c.eq('ddd')d.startWith('a')or(f.eq('a')g.startWith(2)) * * @param queryParams uri query params * @param query query * @param manager a {@link InjectionManager} object. * @param <T> a T object. */ public static <T> void applyFilter(MultivaluedMap<String, String> queryParams, SpiQuery<T> query, InjectionManager manager) { List<String> wheres = queryParams.get(FILTER_PARAM_NAME); if (wheres != null && wheres.size() > 0) { EbeanExprInvoker invoker = new EbeanExprInvoker(query, manager); WhereExprApplier<T> applier = WhereExprApplier.create(query.where()); for (String w : wheres) { QueryDSL.invoke( w, invoker, applier ); } } }
Example #6
Source File: ModelInterceptor.java From ameba with MIT License | 6 votes |
/** * apply uri query parameter on query * * @param queryParams uri query params * @param query Query * @param needPageList need page list * @param manager a {@link InjectionManager} object. * @return page list count or null * @see #applyFetchProperties * @see #applyFilter * @see #applyOrderBy * @see #applyPageList */ @SuppressWarnings("unchecked") public static FutureRowCount applyUriQuery(MultivaluedMap<String, String> queryParams, SpiQuery query, InjectionManager manager, boolean needPageList) { Set<String> inv = query.validate(); applyFetchProperties(queryParams, query); applyFilter(queryParams, query, manager); applyOrderBy(queryParams, query); EbeanUtils.checkQuery( (SpiQuery<?>) query, inv, null, manager ); if (needPageList) return applyPageList(queryParams, query); return null; }
Example #7
Source File: BackendServiceFactory.java From jrestless-examples with Apache License 2.0 | 6 votes |
@Inject public BackendServiceFactory(InjectionManager serviceLocator) { awsLambdaClient = new AWSLambdaClient(); awsLambdaClient.configureRegion(BACKEND_SERVICE_REGION); backendService = Feign.builder() .client(FeignLambdaServiceInvokerClient.builder() .setRegion(BACKEND_SERVICE_REGION) .setFunctionName(BACKEND_SERVICE_FUNCTION_NAME) .build()) .decoder(new JacksonDecoder()) .encoder(new JacksonEncoder()) .logger(new Slf4jLogger()) .target(new LambdaServiceFunctionTarget<BackendService>(BackendService.class) { @Override public Request apply(RequestTemplate input) { // TODO inject the context directly => requires the context to be bound as proxy Context lambdaContext = serviceLocator.getInstance(Context.class); // propagate the AWS request ID => the called service can log the original AWS request ID input.header("X-Base-Aws-Request-Id", lambdaContext.getAwsRequestId()); return super.apply(input); } }); }
Example #8
Source File: GuiceFeature.java From jrestless-examples with Apache License 2.0 | 6 votes |
@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; }
Example #9
Source File: JerseyComponentProvider.java From dropwizard-guicey with MIT License | 5 votes |
@Override @SuppressWarnings("unchecked") public T get() { // HK2 by default proxy instances to delay actual instance creation, which could harm guice scopes logic // for example: if guice request scope transfer used ServletScopes.transferRequest and we try to obtain // it will try to use proxy instance in separate thread which will perform HK2 checks for request scope // and fail. Instead, we always resolve actual instance and let guice properly control scoping final T res = injector.get().getInstance(InjectionManager.class).getInstance(type); return res instanceof ProxyCtl ? (T) ((ProxyCtl) res).__make() : res; }
Example #10
Source File: DefaultContainerLifecycleListener.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onStartup(Container container) { InjectionManager injectionManager = container.getApplicationHandler().getInjectionManager(); if (injectionManager instanceof ImmediateHk2InjectionManager) { app.serviceLocator = ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator(); } else if (injectionManager instanceof DelayedHk2InjectionManager) { app.serviceLocator = ((DelayedHk2InjectionManager) injectionManager).getServiceLocator(); } else { throw new ApplicationException("unknown injection manager"); } app.onStartup(); }
Example #11
Source File: MessageHelper.java From ameba with MIT License | 5 votes |
/** * <p>getStreamingProcess.</p> * * @param entity a T object. * @param manager manager * @param <T> a T object. * @return a {@link ameba.message.internal.StreamingProcess} object. */ @SuppressWarnings("unchecked") public static <T> StreamingProcess<T> getStreamingProcess(T entity, InjectionManager manager) { for (StreamingProcess process : getStreamingProcesses(manager)) { if (process.isSupported(entity)) { return process; } } return null; }
Example #12
Source File: EbeanUtils.java From ameba with MIT License | 5 votes |
/** * <p>checkQuery.</p> * * @param query a {@link io.ebean.Query} object. * @param whitelist a {@link java.util.Set} object. * @param blacklist a {@link java.util.Set} object. * @param manager a {@link InjectionManager} object. */ public static void checkQuery(Query<?> query, Set<String> whitelist, Set<String> blacklist, InjectionManager manager) { ResourceInfo resource = manager.getInstance(ResourceInfo.class); Class<?> rc = resource.getResourceClass(); Set<String> wl = null, bl = null; if (rc != null) { Filter filter = rc.getAnnotation(Filter.class); if (filter != null) { if (filter.whitelist().length > 0) { wl = Sets.newLinkedHashSet(); Collections.addAll(wl, filter.whitelist()); } if (filter.blacklist().length > 0) { bl = Sets.newLinkedHashSet(); Collections.addAll(bl, filter.blacklist()); } } } if (whitelist != null) { if (wl == null) { wl = Sets.newLinkedHashSet(); } wl.addAll(whitelist); } if (blacklist != null) { if (bl == null) { bl = Sets.newLinkedHashSet(); } bl.addAll(blacklist); } checkQuery((SpiQuery) query, wl, bl, manager.getInstance(Application.Mode.class).isProd()); }
Example #13
Source File: RxJerseyBinder.java From rx-jersey with MIT License | 5 votes |
protected InjectionManager getInjectionManager() { try { return (InjectionManager) injectionManagerField.get(this); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
Example #14
Source File: WebActionRequestHandlerTest.java From jrestless with Apache License 2.0 | 5 votes |
@Test public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() { JsonObject jsonRequest = new WebActionRequestBuilder() .setHttpMethod("GET") .setPath("/") .buildJson(); RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(jsonRequest); InjectionManager injectionManager = mock(InjectionManager.class); requestScopedInitializer.initialize(injectionManager); }
Example #15
Source File: ConfigHelper.java From ameba with MIT License | 5 votes |
@Override public void onShutdown(final Container container) { final ApplicationHandler handler = container.getApplicationHandler(); final InjectionManager injectionManager = handler.getInjectionManager(); // Call @PreDestroy method on Application. injectionManager.preDestroy(getWrappedApplication(handler.getConfiguration())); // Shutdown ServiceLocator. injectionManager.shutdown(); }
Example #16
Source File: OptionsMethodProcessor.java From ameba with MIT License | 5 votes |
/** * Creates new instance. * * @param manager a {@link InjectionManager} object. */ @Inject public OptionsMethodProcessor(InjectionManager manager) { methodList = Lists.newArrayList(); methodList.add(new ModelProcessorUtil.Method(HttpMethod.OPTIONS, WILDCARD_TYPE, WILDCARD_TYPE, GenericOptionsInflector.class)); generators = Providers.getAllRankedSortedProviders(manager, OptionsResponseGenerator.class); }
Example #17
Source File: SnsRequestHandlerTest.java From jrestless with Apache License 2.0 | 5 votes |
@Test public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() { Context context = mock(Context.class); SNS sns = new SNS(); sns.setTopicArn(":t"); SNSRecord snsRecord = new SNSRecord(); snsRecord.setSns(sns); RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, snsRecord); InjectionManager injectionManager = mock(InjectionManager.class); requestScopedInitializer.initialize(injectionManager); }
Example #18
Source File: GatewayRequestHandlerTest.java From jrestless with Apache License 2.0 | 5 votes |
@Test public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() { Context context = mock(Context.class); DefaultGatewayRequest request = new DefaultGatewayRequest(); request.setPath("/"); request.setHttpMethod("GET"); RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, request); InjectionManager injectionManager = mock(InjectionManager.class); requestScopedInitializer.initialize(injectionManager); }
Example #19
Source File: ServiceRequestHandlerTest.java From jrestless with Apache License 2.0 | 5 votes |
@Test public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() { Context context = mock(Context.class); DefaultServiceRequest request = new DefaultServiceRequest(null, new HashMap<>(), URI.create("/"), "GET"); RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, request); InjectionManager injectionManager = mock(InjectionManager.class); requestScopedInitializer.initialize(injectionManager); }
Example #20
Source File: GuiceComponentProvider.java From seed with Mozilla Public License 2.0 | 5 votes |
public void initialize(InjectionManager injectionManager) { if (injectionManager instanceof ImmediateHk2InjectionManager) { initialize(((ImmediateHk2InjectionManager) injectionManager).getServiceLocator()); } else if (injectionManager instanceof DelayedHk2InjectionManager) { initialize(((DelayedHk2InjectionManager) injectionManager).getServiceLocator()); } else { throw SeedException.createNew(Jersey2ErrorCode.UNSUPPORTED_JERSEY_DEPENDENCY_INJECTION); } }
Example #21
Source File: DefaultServerEndpointConfig.java From ameba with MIT License | 4 votes |
/** * <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); } }; }
Example #22
Source File: AbstractAnnotatedEndpointMeta.java From ameba with MIT License | 4 votes |
public AbstractAnnotatedEndpointMeta(Class endpointClass, InjectionManager manager) { super(endpointClass); this.manager = manager; }
Example #23
Source File: GuiceBridgeActivator.java From dropwizard-guicey with MIT License | 4 votes |
public GuiceBridgeActivator(final InjectionManager injectionManager, final Injector injector) { this.injectionManager = injectionManager; this.injector = injector; }
Example #24
Source File: JerseyConfigRenderer.java From dropwizard-guicey with MIT License | 4 votes |
public JerseyConfigRenderer(final InjectionManager manager, final boolean guiceFirstMode) { this.manager = manager; this.guiceFirstMode = guiceFirstMode; }
Example #25
Source File: JerseyLambdaContainerHandler.java From aws-serverless-java-container with Apache License 2.0 | 4 votes |
public InjectionManager getInjectionManager() { if (!initialized) { initialize(); } return jerseyFilter.getApplicationHandler().getInjectionManager(); }
Example #26
Source File: AbstractLambdaContextReferencingBinderIntTest.java From jrestless with Apache License 2.0 | 4 votes |
@Inject public LambdaContextSetter(LambdaContextProvider lambdaContextProvider, InjectionManager injectionManager) { this.lambdaContextProvider = lambdaContextProvider; this.injectionManager = injectionManager; }
Example #27
Source File: WebActionRequestHandlerTest.java From jrestless with Apache License 2.0 | 4 votes |
@Test public void delegateJsonRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() { WebActionRequestBuilder requestBuilder = new WebActionRequestBuilder() .setHttpMethod("GET") .setPath("/"); JsonObject jsonRequest = requestBuilder.buildJson(); DefaultWebActionRequest request = requestBuilder.build(); RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(jsonRequest); @SuppressWarnings("unchecked") Ref<WebActionRequest> gatewayRequestRef = mock(Ref.class); InjectionManager injectionManager = mock(InjectionManager.class); when(injectionManager.getInstance(WEB_ACTION_REQUEST_TYPE)).thenReturn(gatewayRequestRef); requestScopedInitializer.initialize(injectionManager); verify(gatewayRequestRef).set(request); }
Example #28
Source File: RemoteResolver.java From rx-jersey with MIT License | 4 votes |
public RemoteResolver(InjectionManager injectionManager, ClientMethodInvoker methodInvoker, Client client) { this.injectionManager = injectionManager; this.clientMethodInvoker = methodInvoker; this.client = client; }
Example #29
Source File: GuiceFeature.java From dropwizard-guicey with MIT License | 4 votes |
@Override public InjectionManager get() { return Preconditions.checkNotNull(injectionManager, "Jersey InjectionManager is not yet available"); }
Example #30
Source File: LifecycleSupport.java From dropwizard-guicey with MIT License | 4 votes |
public void jerseyConfiguration(final InjectionManager injectionManager) { this.context.setInjectionManager(injectionManager); broadcast(new JerseyConfigurationEvent(context)); }