org.glassfish.jersey.internal.util.collection.Ref Java Examples
The following examples show how to use
org.glassfish.jersey.internal.util.collection.Ref.
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: 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 #2
Source File: ModelResourceStructure.java From ameba with MIT License | 6 votes |
/** * <p>fetchHistory.</p> * * @param id a URI_ID object. * @return a {@link javax.ws.rs.core.Response} object. * @throws java.lang.Exception if any. */ public Response fetchHistory(@PathParam("id") URI_ID id) throws Exception { final MODEL_ID mId = tryConvertId(id); matchedFetchHistory(mId); final Query<MODEL> query = server.find(modelType); defaultFindOrderBy(query); final Ref<FutureRowCount> rowCount = Refs.emptyRef(); Object entity = executeTx(t -> { configDefaultQuery(query); configFetchHistoryQuery(query, mId); applyUriQuery(query, false); applyPageConfig(query); List<Version<MODEL>> list = query.findVersions(); rowCount.set(fetchRowCount(query)); return processFetchedHistoryModelList(list, mId); }); if (isEmptyEntity(entity)) { return Response.noContent().build(); } Response response = Response.ok(entity).build(); applyRowCountHeader(response.getHeaders(), query, rowCount.get()); return response; }
Example #3
Source File: FnRequestHandler.java From jrestless with Apache License 2.0 | 6 votes |
/** * Hook that allows you to extend the actual containerRequest passed to the Jersey container. */ @Override protected void extendActualJerseyContainerRequest(ContainerRequest actualContainerRequest, JRestlessContainerRequest containerRequest, WrappedInput wrappedInput) { InputEvent event = wrappedInput.inputEvent; actualContainerRequest.setRequestScopedInitializer(locator -> { Ref<InputEvent> inputEventRef = locator .<Ref<InputEvent>>getInstance(INPUT_EVENT_TYPE); if (inputEventRef != null) { inputEventRef.set(event); } Ref<RuntimeContext> contextRef = locator .<Ref<RuntimeContext>>getInstance(RUNTIME_CONTEXT_TYPE); if (contextRef != null) { contextRef.set(rctx); } }); }
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: SnsRequestHandler.java From jrestless with Apache License 2.0 | 6 votes |
@Override protected void extendActualJerseyContainerRequest(ContainerRequest actualContainerRequest, JRestlessContainerRequest containerRequest, SnsRecordAndLambdaContext snsRecordAndContext) { SNSRecord snsRecord = snsRecordAndContext.getSnsRecord(); Context lambdaContext = snsRecordAndContext.getLambdaContext(); actualContainerRequest.setRequestScopedInitializer(locator -> { Ref<SNSRecord> snsRecordRef = locator.<Ref<SNSRecord>>getInstance(SNS_RECORD_TYPE); if (snsRecordRef != null) { snsRecordRef.set(snsRecord); } else { LOG.error("SnsFeature has not been registered. SNSRecord injection won't work."); } Ref<Context> contextRef = locator .<Ref<Context>>getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE); if (contextRef != null) { contextRef.set(lambdaContext); } else { LOG.error("AwsFeature has not been registered. Context injection won't work."); } }); }
Example #6
Source File: GatewayRequestHandler.java From jrestless with Apache License 2.0 | 6 votes |
@Override protected void extendActualJerseyContainerRequest(ContainerRequest actualContainerRequest, JRestlessContainerRequest containerRequest, GatewayRequestAndLambdaContext requestAndLambdaContext) { GatewayRequest request = requestAndLambdaContext.getGatewayRequest(); Context lambdaContext = requestAndLambdaContext.getLambdaContext(); actualContainerRequest.setRequestScopedInitializer(locator -> { Ref<GatewayRequest> gatewayRequestRef = locator .<Ref<GatewayRequest>>getInstance(GATEWAY_REQUEST_TYPE); if (gatewayRequestRef != null) { gatewayRequestRef.set(request); } else { LOG.error("GatewayFeature has not been registered. GatewayRequest injection won't work."); } Ref<Context> contextRef = locator .<Ref<Context>>getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE); if (contextRef != null) { contextRef.set(lambdaContext); } else { LOG.error("AwsFeature has not been registered. Context injection won't work."); } }); actualContainerRequest.setProperty(GatewayBinaryReadInterceptor.PROPERTY_BASE_64_ENCODED_REQUEST, request.isBase64Encoded()); }
Example #7
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 #8
Source File: ServiceRequestHandler.java From jrestless with Apache License 2.0 | 6 votes |
@Override protected void extendActualJerseyContainerRequest(ContainerRequest actualContainerRequest, JRestlessContainerRequest containerRequest, ServiceRequestAndLambdaContext requestAndLambdaContext) { ServiceRequest request = requestAndLambdaContext.getServiceRequest(); Context lambdaContext = requestAndLambdaContext.getLambdaContext(); actualContainerRequest.setRequestScopedInitializer(locator -> { Ref<ServiceRequest> serviceRequestRef = locator .<Ref<ServiceRequest>>getInstance(SERVICE_REQUEST_TYPE); if (serviceRequestRef != null) { serviceRequestRef.set(request); } else { LOG.error("ServiceFeature has not been registered. ServiceRequest injection won't work."); } Ref<Context> contextRef = locator .<Ref<Context>>getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE); if (contextRef != null) { contextRef.set(lambdaContext); } else { LOG.error("AwsFeature has not been registered. Context injection won't work."); } }); }
Example #9
Source File: AbstractRestClient.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Override public RestResult get(String path, Map<String, Object> params) { Ref<WebTarget> target = Refs.of(this.target); for (String key : params.keySet()) { Object value = params.get(key); if (value instanceof Collection) { for (Object i : (Collection<?>) value) { target.set(target.get().queryParam(key, i)); } } else { target.set(target.get().queryParam(key, value)); } } Response response = this.request(() -> { return target.get().path(path).request().get(); }); checkStatus(response, Response.Status.OK); return new RestResult(response); }
Example #10
Source File: EndpointEnhancingRequestFilter.java From servicetalk with Apache License 2.0 | 6 votes |
void enhance(final RequestScope requestScope, final Provider<Ref<ConnectionContext>> ctxRefProvider, final Provider<RouteStrategiesConfig> routeStrategiesConfigProvider, final UriRoutingContext urc) { if (urc.getResourceMethod() == null) { return; } EnhancedEndpoint enhanced = enhancements.get(urc.getResourceMethod()); if (enhanced == null) { // attempt get(..) first to avoid creating a capturing lambda per request in steady state enhanced = enhancements.computeIfAbsent(urc.getResourceMethod(), resourceMethod -> defineEndpoint(urc.getEndpoint(), requestScope, ctxRefProvider, routeStrategiesConfigProvider, urc.getResourceClass(), resourceMethod)); } if (enhanced != NOOP) { urc.setEndpoint(enhanced); } }
Example #11
Source File: EndpointEnhancingRequestFilter.java From servicetalk with Apache License 2.0 | 6 votes |
private AbstractWrappedEndpoint( final Endpoint delegate, final Class<?> resourceClass, final Method resourceMethod, final RequestScope requestScope, @Nullable final Provider<Ref<ConnectionContext>> ctxRefProvider, @Nullable final HttpExecutionStrategy routeExecutionStrategy) { this.delegate = delegate; this.resourceClass = resourceClass; this.resourceMethod = resourceMethod; this.requestScope = requestScope; this.ctxRefProvider = ctxRefProvider; this.routeExecutionStrategy = routeExecutionStrategy; if (routeExecutionStrategy != null) { final ExecutionContext executionContext = ctxRefProvider.get().get().executionContext(); // ExecutionStrategy and Executor shared for all routes in JerseyRouter final ExecutionStrategy executionStrategy = executionContext.executionStrategy(); executor = executionContext.executor(); effectiveRouteStrategy = calculateEffectiveStrategy(executionStrategy, executor); } else { effectiveRouteStrategy = null; executor = null; } }
Example #12
Source File: AsynchronousResources.java From servicetalk with Apache License 2.0 | 5 votes |
private void scheduleSseEventSend(final SseEmitter emmitter, final Sse sse, final Ref<Integer> iRef, final Executor executor) { executor.schedule(() -> { final int i = iRef.get(); emmitter.emit(sse.newEvent("foo" + i)).whenComplete((r, t) -> { if (t == null && i < 9) { iRef.set(i + 1); scheduleSseEventSend(emmitter, sse, iRef, executor); } else { emmitter.close(); } }); }, 10, MILLISECONDS); }
Example #13
Source File: ModelResourceStructure.java From ameba with MIT License | 5 votes |
/** * find model history between start to end timestamp versions * <p> * need model mark {@code @History} * * @param id model id * @param start start timestamp * @param end end timestamp * @return history versions * @throws java.lang.Exception any error */ public Response fetchHistory(@PathParam("id") URI_ID id, @PathParam("start") final Timestamp start, @PathParam("end") final Timestamp end) throws Exception { final MODEL_ID mId = tryConvertId(id); matchedFetchHistory(mId, start, end); final Query<MODEL> query = server.find(modelType); defaultFindOrderBy(query); final Ref<FutureRowCount> rowCount = Refs.emptyRef(); Object entity = executeTx(t -> { configDefaultQuery(query); configFetchHistoryQuery(query, mId, start, end); applyUriQuery(query, false); applyPageConfig(query); List<Version<MODEL>> list = query.findVersionsBetween(start, end); rowCount.set(fetchRowCount(query)); return processFetchedHistoryModelList(list, mId, start, end); }); if (isEmptyEntity(entity)) { return Response.noContent().build(); } Response response = Response.ok(entity).build(); applyRowCountHeader(response.getHeaders(), query, rowCount.get()); return response; }
Example #14
Source File: ModelResourceStructure.java From ameba with MIT License | 5 votes |
/** * Find the beans for this beanType. * <p> * This can use URL query parameters such as order and maxrows to configure * the query. * </p> * * @param includeDeleted a boolean. * @return a {@link javax.ws.rs.core.Response} object. * @throws java.lang.Exception if any. * @see javax.ws.rs.GET * @see AbstractModelResource#find */ public Response find(@QueryParam("include_deleted") final boolean includeDeleted) throws Exception { matchedFind(includeDeleted); final Query<MODEL> query = server.find(modelType); if (includeDeleted) { query.setIncludeSoftDeletes(); } defaultFindOrderBy(query); final Ref<FutureRowCount> rowCount = Refs.emptyRef(); Object entity = executeTx(t -> { configDefaultQuery(query); configFindQuery(query, includeDeleted); rowCount.set(applyUriQuery(query)); List<MODEL> list = query.findList(); return processFoundModelList(list, includeDeleted); }); if (isEmptyEntity(entity)) { return Response.noContent().build(); } Response response = Response.ok(entity).build(); applyRowCountHeader(response.getHeaders(), query, rowCount.get()); return response; }
Example #15
Source File: TemplateHelper.java From ameba with MIT License | 5 votes |
/** * Get media types for which the {@link org.glassfish.jersey.server.mvc.spi.ResolvedViewable resolved viewable} could be * produced. * * @param containerRequest request to obtain acceptable media types. * @param extendedUriInfo uri info to obtain resource method from and its producible media types. * @param varyHeaderValue Vary header reference. * @return list of producible media types. */ public static List<MediaType> getProducibleMediaTypes(final ContainerRequest containerRequest, final ExtendedUriInfo extendedUriInfo, final Ref<String> varyHeaderValue) { final List<MediaType> producedTypes = getResourceMethodProducibleTypes(extendedUriInfo); final MediaType[] mediaTypes = producedTypes.toArray(new MediaType[producedTypes.size()]); final List<Variant> variants = VariantSelector.selectVariants(containerRequest, Variant.mediaTypes(mediaTypes) .build(), varyHeaderValue == null ? Refs.emptyRef() : varyHeaderValue); return Lists.transform(variants, variant -> MediaTypes.stripQualityParams(variant.getMediaType())); }
Example #16
Source File: AbstractReferencingBinder.java From jrestless with Apache License 2.0 | 5 votes |
/** * Binds the referencingFactory to the referenceType in the request scope * and allows proxying the reference type but not for the same scope. * <p> * It also binds a referencing factory to the referenceTypeLiteral in the * requestScope. * * @param referenceType * @param referencingFacatory * @param referenceTypeLiteral */ public final <T> void bindReferencingFactory(Class<T> referenceType, Class<? extends ReferencingFactory<T>> referencingFacatory, GenericType<Ref<T>> referenceTypeLiteral) { bindFactory(referencingFacatory) .to(referenceType) .proxy(true) .proxyForSameScope(false) .in(RequestScoped.class); bindFactory(ReferencingFactory.<T>referenceFactory()) .to(referenceTypeLiteral) .in(RequestScoped.class); }
Example #17
Source File: WebActionRequestHandler.java From jrestless with Apache License 2.0 | 5 votes |
@Override protected void extendActualJerseyContainerRequest(ContainerRequest actualContainerRequest, JRestlessContainerRequest containerRequest, WebActionRequest request) { actualContainerRequest.setRequestScopedInitializer(locator -> { Ref<WebActionRequest> webActionRequestRef = locator .<Ref<WebActionRequest>>getInstance(WEB_ACTION_REQUEST_TYPE); if (webActionRequestRef != null) { webActionRequestRef.set(request); } else { LOG.error("WebActionBinder has not been registered. WebActionRequest injection won't work."); } }); }
Example #18
Source File: FnRequestHandler.java From jrestless with Apache License 2.0 | 5 votes |
@Override public void configure() { bindReferencingFactory(InputEvent.class, ReferencingInputEventFactory.class, new GenericType<Ref<InputEvent>>() { } ); bindReferencingFactory(RuntimeContext.class, ReferencingRuntimeContextFactory.class, new GenericType<Ref<RuntimeContext>>() { } ); }
Example #19
Source File: EndpointEnhancingRequestFilter.java From servicetalk with Apache License 2.0 | 5 votes |
private static EnhancedEndpoint defineEndpoint(final Endpoint delegate, final RequestScope requestScope, final Provider<Ref<ConnectionContext>> ctxRefProvider, final Provider<RouteStrategiesConfig> routeStratConfigProvider, final Class<?> resourceClass, final Method resourceMethod) { final HttpExecutionStrategy routeExecutionStrategy = getRouteExecutionStrategy( resourceMethod, resourceClass, routeStratConfigProvider.get()); final Class<?> returnType = resourceMethod.getReturnType(); if (Single.class.isAssignableFrom(returnType)) { return new SingleAwareEndpoint( delegate, resourceClass, resourceMethod, requestScope, ctxRefProvider, routeExecutionStrategy); } if (Completable.class.isAssignableFrom(returnType)) { return new CompletableAwareEndpoint( delegate, resourceClass, resourceMethod, requestScope, ctxRefProvider, routeExecutionStrategy); } final ExecutionContext executionContext = ctxRefProvider.get().get().executionContext(); final HttpExecutionStrategy difference = difference(executionContext.executor(), (HttpExecutionStrategy) executionContext.executionStrategy(), routeExecutionStrategy); if (difference != null) { return new ExecutorOffloadingEndpoint( delegate, resourceClass, resourceMethod, requestScope, ctxRefProvider, routeExecutionStrategy); } return NOOP; }
Example #20
Source File: EndpointEnhancingRequestFilter.java From servicetalk with Apache License 2.0 | 5 votes |
private SingleAwareEndpoint(final Endpoint delegate, final Class<?> resourceClass, final Method resourceMethod, final RequestScope requestScope, final Provider<Ref<ConnectionContext>> ctxRefProvider, @Nullable final HttpExecutionStrategy routeExecutionStrategy) { super(delegate, resourceClass, resourceMethod, Single.class, requestScope, ctxRefProvider, routeExecutionStrategy); }
Example #21
Source File: EndpointEnhancingRequestFilter.java From servicetalk with Apache License 2.0 | 5 votes |
private ExecutorOffloadingEndpoint(final Endpoint delegate, final Class<?> resourceClass, final Method resourceMethod, final RequestScope requestScope, final Provider<Ref<ConnectionContext>> ctxRefProvider, @Nullable final HttpExecutionStrategy routeExecutionStrategy) { super(delegate, resourceClass, resourceMethod, requestScope, ctxRefProvider, routeExecutionStrategy); }
Example #22
Source File: EndpointEnhancingRequestFilterTest.java From servicetalk with Apache License 2.0 | 5 votes |
@Test public void shouldNotFilterNonStRequests() throws Exception { EndpointEnhancingRequestFilter filter = new EndpointEnhancingRequestFilter(); Provider<Ref<ConnectionContext>> ctxRefProvider = () -> Refs.of(null); Provider<RouteStrategiesConfig> routeStrategiesConfigProvider = () -> mock(RouteStrategiesConfig.class); RequestScope requestScope = mock(RequestScope.class); setField(filter, filter.getClass().getDeclaredField("ctxRefProvider"), ctxRefProvider); setField(filter, filter.getClass().getDeclaredField("routeStrategiesConfigProvider"), routeStrategiesConfigProvider); setField(filter, filter.getClass().getDeclaredField("requestScope"), requestScope); ContainerRequestContext context = mock(ContainerRequestContext.class); filter.filter(mock(ContainerRequestContext.class)); verifyZeroInteractions(context); }
Example #23
Source File: EndpointEnhancingRequestFilter.java From servicetalk with Apache License 2.0 | 5 votes |
private CompletableAwareEndpoint(final Endpoint delegate, final Class<?> resourceClass, final Method resourceMethod, final RequestScope requestScope, final Provider<Ref<ConnectionContext>> ctxRefProvider, @Nullable final HttpExecutionStrategy routeExecutionStrategy) { super(delegate, resourceClass, resourceMethod, Completable.class, requestScope, ctxRefProvider, routeExecutionStrategy); }
Example #24
Source File: AbstractRestClient.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Override public RestResult delete(String path, Map<String, Object> params) { Ref<WebTarget> target = Refs.of(this.target); for (String key : params.keySet()) { target.set(target.get().queryParam(key, params.get(key))); } Response response = this.request(() -> { return target.get().path(path).request().delete(); }); checkStatus(response, Response.Status.NO_CONTENT, Response.Status.ACCEPTED); return new RestResult(response); }
Example #25
Source File: EndpointEnhancingRequestFilter.java From servicetalk with Apache License 2.0 | 5 votes |
private AbstractSourceAwareEndpoint(final Endpoint delegate, final Class<?> resourceClass, final Method resourceMethod, final Class<T> sourceType, final RequestScope requestScope, final Provider<Ref<ConnectionContext>> ctxRefProvider, @Nullable final HttpExecutionStrategy routeExecutionStrategy) { super(delegate, resourceClass, resourceMethod, requestScope, ctxRefProvider, routeExecutionStrategy); this.sourceType = sourceType; }
Example #26
Source File: ServiceRequestHandler.java From jrestless with Apache License 2.0 | 4 votes |
@Override protected void configure() { bindReferencingLambdaContextFactory(); bindReferencingFactory(ServiceRequest.class, ReferencingServiceRequestFactory.class, new GenericType<Ref<ServiceRequest>>() { }); }
Example #27
Source File: Context.java From servicetalk with Apache License 2.0 | 4 votes |
@Inject ConnectionContextReferencingFactory(final Provider<Ref<ConnectionContext>> referenceFactory) { super(referenceFactory); }
Example #28
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 #29
Source File: WebActionRequestHandler.java From jrestless with Apache License 2.0 | 4 votes |
@Inject ReferencingWebActionRequestFactory(final Provider<Ref<WebActionRequest>> referenceFactory) { super(referenceFactory); }
Example #30
Source File: WebActionRequestHandler.java From jrestless with Apache License 2.0 | 4 votes |
@Override public void configure() { bindReferencingFactory(WebActionRequest.class, ReferencingWebActionRequestFactory.class, new GenericType<Ref<WebActionRequest>>() { }); }