当前位置: 首页>>代码示例>>Java>>正文


Java ContainerRequest类代码示例

本文整理汇总了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
                }
            }
        }
    }
}
 
开发者ID:stevespringett,项目名称:Alpine,代码行数:25,代码来源:AuthorizationFilter.java

示例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
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:21,代码来源:TimingApplicationEventListener.java

示例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";
  }
}
 
开发者ID:dpinney,项目名称:essence,代码行数:23,代码来源:DetectionRuleResource.java

示例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.");
		}
	});
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:23,代码来源:ServiceRequestHandler.java

示例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();
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:17,代码来源:ServiceRequestHandlerTest.java

示例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());
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:25,代码来源:GatewayRequestHandler.java

示例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();
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:17,代码来源:GatewayRequestHandlerTest.java

示例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.");
		}
	});
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:22,代码来源:SnsRequestHandler.java

示例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();
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:17,代码来源:SnsRequestHandlerTest.java

示例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);
		}
	});
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:22,代码来源:FnRequestHandler.java

示例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;
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:31,代码来源:JRestlessHandlerContainer.java

示例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());
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:26,代码来源:JRestlessHandlerContainerTest.java

示例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));
}
 
开发者ID:servicecatalog,项目名称:development,代码行数:19,代码来源:RestTriggerResourceTest.java

示例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;
	}
	
}
 
开发者ID:geneontology,项目名称:minerva,代码行数:24,代码来源:LoggingApplicationEventListener.java

示例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);
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:18,代码来源:JaxRsRequestDstu3Test.java


注:本文中的org.glassfish.jersey.server.ContainerRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。