本文整理汇总了Java中org.glassfish.jersey.server.ContainerRequest类的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequest类的具体用法?Java ContainerRequest怎么用?Java ContainerRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContainerRequest类属于org.glassfish.jersey.server包,在下文中一共展示了ContainerRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) {
if (requestContext instanceof ContainerRequest) {
final Principal principal = (Principal) requestContext.getProperty("Principal");
if (principal == null) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
return;
}
final PermissionRequired annotation = resourceInfo.getResourceMethod().getDeclaredAnnotation(PermissionRequired.class);
try (AlpineQueryManager qm = new AlpineQueryManager()) {
if (principal instanceof LdapUser) {
final LdapUser user = qm.getLdapUser(((LdapUser) principal).getUsername());
final String[] permissions = annotation.value();
for (String permission: permissions) {
// todo check if user has one of these required permissions
}
}
}
}
}
示例2: onEvent
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@Override
public void onEvent(RequestEvent event) {
switch (event.getType()) {
case RESOURCE_METHOD_START:
callId = ticker.nextId();
ticker.tick("callRes", callId);
break;
case RESOURCE_METHOD_FINISHED:
ticker.tock("callRes", callId);
break;
case FINISHED:
ticker.tock("req", reqEId);
ContainerRequest req = event.getContainerRequest();
String endpoint = req.getMethod() + " " + req.getRequestUri().toString().substring(req.getBaseUri().toString().length());
ticker.log(reqId, endpoint);
Timer.release();
break;
default: // do nothing
}
}
示例3: newDetectionRule
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces(MediaType.TEXT_HTML)
public Response newDetectionRule(@Context ContainerRequest request, DetectionRule rule){
OrganizationDAO pd = DAOUtil.getOrganizationDAO();
List<OrganizationProfile> os = pd.getAllActiveOrganizations();
assert(os != null && !os.isEmpty());
rule.setOrganizationId(os.get(0).getId());
DetectionRuleDAO dao = DAOUtil.getDetectionRuleDAO();
try {
Integer id = dao.addDetectionRule(rule);
String url = request.getUriInfo().getRequestUri().toASCIIString();
return Response.status(Response.Status.CREATED)// 201
.entity("A new detection rule has been created")
.header("Location", url + "/" + String.valueOf(id)).build();
} catch (Exception ex) {
// TODO: error handling
return Response.serverError().build();
//return "Failure";
}
}
示例4: extendActualJerseyContainerRequest
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@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.");
}
});
}
示例5: getSetRequestScopedInitializer
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private RequestScopedInitializer getSetRequestScopedInitializer(Context context, ServiceRequest request) {
ServiceRequestAndLambdaContext reqAndContext = new ServiceRequestAndLambdaContext(request, context);
ArgumentCaptor<Consumer> containerEnhancerCaptor = ArgumentCaptor.forClass(Consumer.class);
serviceHandler.delegateRequest(reqAndContext);
verify(container).handleRequest(any(), any(), any(), containerEnhancerCaptor.capture());
ContainerRequest containerRequest = mock(ContainerRequest.class);
containerEnhancerCaptor.getValue().accept(containerRequest);
ArgumentCaptor<RequestScopedInitializer> requestScopedInitializerCaptor = ArgumentCaptor.forClass(RequestScopedInitializer.class);
verify(containerRequest).setRequestScopedInitializer(requestScopedInitializerCaptor.capture());
return requestScopedInitializerCaptor.getValue();
}
示例6: extendActualJerseyContainerRequest
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@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());
}
示例7: getSetRequestScopedInitializer
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private RequestScopedInitializer getSetRequestScopedInitializer(Context context, GatewayRequest request) {
GatewayRequestAndLambdaContext reqAndContext = new GatewayRequestAndLambdaContext(request, context);
ArgumentCaptor<Consumer<ContainerRequest>> containerEnhancerCaptor = ArgumentCaptor.forClass(Consumer.class);
gatewayHandler.delegateRequest(reqAndContext);
verify(container).handleRequest(any(), any(), any(), containerEnhancerCaptor.capture());
ContainerRequest containerRequest = mock(ContainerRequest.class);
containerEnhancerCaptor.getValue().accept(containerRequest);
ArgumentCaptor<RequestScopedInitializer> requestScopedInitializerCaptor = ArgumentCaptor.forClass(RequestScopedInitializer.class);
verify(containerRequest).setRequestScopedInitializer(requestScopedInitializerCaptor.capture());
return requestScopedInitializerCaptor.getValue();
}
示例8: extendActualJerseyContainerRequest
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@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.");
}
});
}
示例9: getSetRequestScopedInitializer
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private RequestScopedInitializer getSetRequestScopedInitializer(Context context, SNSRecord snsRecord) {
SnsRecordAndLambdaContext reqAndContext = new SnsRecordAndLambdaContext(snsRecord, context);
ArgumentCaptor<Consumer> containerEnhancerCaptor = ArgumentCaptor.forClass(Consumer.class);
snsHandler.delegateRequest(reqAndContext);
verify(container).handleRequest(any(), any(), any(), containerEnhancerCaptor.capture());
ContainerRequest containerRequest = mock(ContainerRequest.class);
containerEnhancerCaptor.getValue().accept(containerRequest);
ArgumentCaptor<RequestScopedInitializer> requestScopedInitializerCaptor = ArgumentCaptor.forClass(RequestScopedInitializer.class);
verify(containerRequest).setRequestScopedInitializer(requestScopedInitializerCaptor.capture());
return requestScopedInitializerCaptor.getValue();
}
示例10: extendActualJerseyContainerRequest
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
/**
* 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);
}
});
}
示例11: createContainerRequest
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
/**
* Creates a new {@link ContainerRequest} for the given input.
*
* @param request
* @param containerResponseWriter
* @param securityContext
* @return
*/
@Nonnull
protected ContainerRequest createContainerRequest(@Nonnull RequestT request,
@Nonnull ContainerResponseWriter containerResponseWriter, @Nonnull SecurityContext securityContext) {
requireNonNull(request, "request may not be null");
URI baseUri = request.getBaseUri();
URI requestUri = requireNonNull(request.getRequestUri(), "request.getRequestUri() may not be null");
String httpMethod = requireNonNull(request.getHttpMethod(), "request.getHttpMethod() may not be null");
InputStream entityStream = requireNonNull(request.getEntityStream(),
"request.getEntityStream() may not be null");
Map<String, List<String>> headers = requireNonNull(request.getHeaders(),
"request.getHeaderParams() may not be null");
requireNonNull(containerResponseWriter, "containerResponseWriter may not be null");
requireNonNull(securityContext, "securityContext may not be null");
ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, httpMethod, securityContext,
new MapPropertiesDelegate());
requestContext.setEntityStream(entityStream);
requestContext.getHeaders().putAll(headers);
requestContext.setWriter(containerResponseWriter);
return requestContext;
}
示例12: ByteArrayInputStream
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@Test
public void createContainerRequest_RequestAndContainerResponseWriterAndSecurityContextGiven_ShouldCreateContainerRequestUsingValues() {
URI baseUri = URI.create("/");
URI requestUri = URI.create("/entity");
String httpMethod = "POST";
ByteArrayInputStream entityStream = new ByteArrayInputStream(new byte[0]);
MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
headers.add("hk0", "hv0_0");
headers.add("hk0", "hv0_1");
headers.add("hk1", "hv1_0");
JRestlessContainerRequest request = createRequest(baseUri, requestUri, httpMethod, entityStream, headers);
ContainerResponseWriter containerResponseWriter = mock(ContainerResponseWriter.class);
SecurityContext securityContext = mock(SecurityContext.class);
ContainerRequest containerRequest = container.createContainerRequest(request, containerResponseWriter, securityContext);
assertEquals(baseUri, containerRequest.getBaseUri());
assertEquals(requestUri, containerRequest.getRequestUri());
assertEquals(httpMethod, containerRequest.getMethod());
assertSame(entityStream, containerRequest.getEntityStream());
assertEquals(headers, containerRequest.getHeaders());
assertSame(containerResponseWriter, containerRequest.getResponseWriter());
assertSame(securityContext, containerRequest.getSecurityContext());
}
示例13: testAction
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@Test
public void testAction() throws Exception {
RestTriggerResource.Action action = new RestTriggerResource()
.redirectToAction();
TriggerParameters params = new TriggerParameters();
params.setId(new Long(1L));
ContainerRequest request = Mockito.mock(ContainerRequest.class);
Mockito.when(request.getProperty(Mockito.anyString()))
.thenReturn(new Integer(CommonParams.VERSION_1));
Response response = action.getCollection(request, params);
assertThat(response.getEntity(),
IsInstanceOf.instanceOf(RepresentationCollection.class));
assertNull(action.getItem(request, params));
}
示例14: onEvent
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
@Override
public void onEvent(RequestEvent event) {
switch (event.getType()) {
case RESOURCE_METHOD_START:
ExtendedUriInfo uriInfo = event.getUriInfo();
ResourceMethod method = uriInfo.getMatchedResourceMethod();
ContainerRequest containerRequest = event.getContainerRequest();
LOG.info(requestNumber+" Resource method " + method.getHttpMethod() + " started for request " + requestNumber);
LOG.info(requestNumber+" Headers: "+ render(containerRequest.getHeaders()));
LOG.info(requestNumber+" Path: "+uriInfo.getPath());
LOG.info(requestNumber+" PathParameters: "+ render(uriInfo.getPathParameters()));
LOG.info(requestNumber+" QueryParameters: "+ render(uriInfo.getQueryParameters()));
LOG.info(requestNumber+" Body: "+getBody(containerRequest));
break;
case FINISHED:
LOG.info("Request " + requestNumber + " finished. Processing time "
+ (System.currentTimeMillis() - startTime) + " ms.");
break;
default:
break;
}
}
示例15: createRequestDetails
import org.glassfish.jersey.server.ContainerRequest; //导入依赖的package包/类
public JaxRsRequest createRequestDetails() throws URISyntaxException {
//headers
headers = new ContainerRequest(new URI(BASEURI), new URI(REQUESTURI), HttpMethod.GET, null, new MapPropertiesDelegate());
//uri info
UriInfo uriInfo = mock(UriInfo.class);
when(uriInfo.getQueryParameters()).thenReturn(queryParameters);
//mocks
provider = spy(TestJaxRsDummyPatientProviderDstu3.class);
doReturn(uriInfo).when(provider).getUriInfo();
doReturn(BASEURI).when(provider).getBaseForRequest();
doReturn(BASEURI).when(provider).getBaseForServer();
doReturn(headers).when(provider).getHeaders();
return new JaxRsRequest(provider, RESOURCE_STRING, RequestTypeEnum.GET, RestOperationTypeEnum.HISTORY_TYPE);
}