Java Code Examples for org.glassfish.jersey.server.ContainerRequest#setRequestScopedInitializer()

The following examples show how to use org.glassfish.jersey.server.ContainerRequest#setRequestScopedInitializer() . 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: ServiceRequestHandler.java    From jrestless with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: GatewayRequestHandler.java    From jrestless with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: SnsRequestHandler.java    From jrestless with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: FnRequestHandler.java    From jrestless with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: WebActionRequestHandler.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: DefaultJerseyStreamingHttpRouter.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private void handle0(final HttpServiceContext serviceCtx, final StreamingHttpRequest req,
                     final StreamingHttpResponseFactory factory,
                     final Subscriber<? super StreamingHttpResponse> subscriber,
                     final DelayedCancellable delayedCancellable) {

    final CharSequence baseUri = baseUriFunction.apply(serviceCtx, req);
    final CharSequence path = ensureNoLeadingSlash(req.rawPath());

    // Jersey needs URI-unsafe query chars to be encoded
    @Nullable
    final String encodedQuery = req.rawQuery().isEmpty() ? null : encodeUnsafeCharacters(req.rawQuery());

    final StringBuilder requestUriBuilder =
            new StringBuilder(baseUri.length() + path.length() +
                    (encodedQuery != null ? 1 + encodedQuery.length() : 0))
                    .append(baseUri)
                    .append(path);

    if (encodedQuery != null) {
        requestUriBuilder.append('?').append(encodedQuery);
    }

    final ContainerRequest containerRequest = new ContainerRequest(
            URI.create(baseUri.toString()),
            URI.create(requestUriBuilder.toString()),
            req.method().name(),
            UNAUTHENTICATED_SECURITY_CONTEXT,
            new MapPropertiesDelegate());

    req.headers().forEach(h ->
            containerRequest.getHeaders().add(h.getKey().toString(), h.getValue().toString()));

    final BufferPublisherInputStream entityStream = new BufferPublisherInputStream(req.payloadBody(),
            publisherInputStreamQueueCapacity);
    containerRequest.setEntityStream(entityStream);
    initRequestProperties(entityStream, containerRequest);

    final DefaultContainerResponseWriter responseWriter = new DefaultContainerResponseWriter(containerRequest,
            req.version(), serviceCtx, factory, subscriber);

    containerRequest.setWriter(responseWriter);

    containerRequest.setRequestScopedInitializer(injectionManager -> {
        injectionManager.<Ref<ConnectionContext>>getInstance(CONNECTION_CONTEXT_REF_TYPE).set(serviceCtx);
        injectionManager.<Ref<StreamingHttpRequest>>getInstance(HTTP_REQUEST_REF_TYPE).set(req);
    });

    delayedCancellable.delayedCancellable(responseWriter::dispose);

    applicationHandler.handle(containerRequest);
}