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


Java ResourceMethod类代码示例

本文整理汇总了Java中org.glassfish.jersey.server.model.ResourceMethod的典型用法代码示例。如果您正苦于以下问题:Java ResourceMethod类的具体用法?Java ResourceMethod怎么用?Java ResourceMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResourceMethod类属于org.glassfish.jersey.server.model包,在下文中一共展示了ResourceMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: annotations

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
private Set<Timed> annotations(RequestEvent event) {
    final Set<Timed> timed = new HashSet<>();

    final ResourceMethod matchingResourceMethod = event.getUriInfo().getMatchedResourceMethod();
    if (matchingResourceMethod != null) {
        // collect on method level
        timed.addAll(timedFinder.findTimedAnnotations(matchingResourceMethod.getInvocable().getHandlingMethod()));

        // fallback on class level
        if (timed.isEmpty()) {
            timed.addAll(timedFinder.findTimedAnnotations(matchingResourceMethod.getInvocable().getHandlingMethod()
                .getDeclaringClass()));
        }
    }
    return timed;
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:17,代码来源:MetricsRequestEventListener.java

示例2: map_ProducesPrecedence_WithValidData

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
@Test
public void map_ProducesPrecedence_WithValidData() throws IOException {
  // Arrange
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.TEXT_PLAIN).path("/breweries",
      new Path().get(new Operation().vendorExtensions(
          ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
              DBEERPEDIA.BREWERIES.stringValue())).produces(MediaType.APPLICATION_JSON).response(
                  Status.OK.getStatusCode(), new Response().schema(mock(Property.class)))));
  when(informationProductResourceProviderMock.get(DBEERPEDIA.BREWERIES)).thenReturn(
      informationProductMock);

  // Act
  requestMapper.map(httpConfigurationMock);

  // Assert
  verify(httpConfigurationMock).registerResources(resourceCaptor.capture());
  ResourceMethod method = resourceCaptor.getValue().getResourceMethods().get(0);
  assertThat(method.getProducedTypes(), hasSize(1));
  assertThat(method.getProducedTypes().get(0), equalTo(MediaType.APPLICATION_JSON_TYPE));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:21,代码来源:OpenApiRequestMapperTest.java

示例3: initialize_RegistersErrorResource_WhenCalled

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
@Test
public void initialize_RegistersErrorResource_WhenCalled() {
  // Act
  errorModule.initialize(httpConfigurationMock);

  // Assert
  verify(httpConfigurationMock).registerResources(resourceCaptor.capture());
  assertThat(resourceCaptor.getAllValues(), hasSize(1));

  Resource resource = resourceCaptor.getValue();
  assertThat(resource.getPath(), equalTo("/{domain}/__errors/{statusCode:\\d{3}}"));
  assertThat(resource.getResourceMethods(), hasSize(1));

  ResourceMethod method = resource.getResourceMethods().get(0);
  assertThat(method.getHttpMethod(), CoreMatchers.equalTo(HttpMethod.GET));
  assertThat(method.getProducedTypes(), contains(MediaType.TEXT_PLAIN_TYPE));

  Object handler = resource.getHandlerInstances().iterator().next();
  assertThat(handler, instanceOf(ServletErrorHandler.class));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:21,代码来源:ErrorModuleTest.java

示例4: loadRepresentations_MapRepresentation_WithValidData

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
@Test
public void loadRepresentations_MapRepresentation_WithValidData() {
  // Arrange
  when(supportedMediaTypesScanner.getMediaTypes(any())).thenReturn(
      new MediaType[] {MediaType.valueOf("text/turtle")});

  // Act
  ldRepresentationRequestMapper.loadRepresentations(httpConfiguration);

  // Assert
  Resource resource = (Resource) httpConfiguration.getResources().toArray()[0];
  final ResourceMethod method = resource.getResourceMethods().get(0);
  assertThat(httpConfiguration.getResources(), hasSize(1));
  assertThat(resource.getPath(), equalTo("/" + DBEERPEDIA.ORG_HOST
      + DBEERPEDIA.BASE_PATH.getLabel() + DBEERPEDIA.URL_PATTERN_VALUE));
  assertThat(resource.getResourceMethods(), hasSize(1));
  assertThat(method.getHttpMethod(), equalTo(HttpMethod.GET));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:19,代码来源:LdRepresentationRequestMapperTest.java

示例5: processResource

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
/**
 * Updates the default {@code @Produces} list of every controller method whose list is empty.
 * The new list contains a single media type: "text/html".
 *
 * @param r resource to process.
 * @return newly updated resource.
 */
private static Resource processResource(Resource r) {
    final boolean isControllerClass = isController(r);
    Resource.Builder rb = Resource.builder(r);
    r.getAllMethods().forEach(
            (ResourceMethod m) -> {
                if ((isController(m) || isControllerClass) && m.getProducedTypes().isEmpty()) {
                    final ResourceMethod.Builder rmb = rb.updateMethod(m);
                    rmb.produces(MediaType.TEXT_HTML_TYPE);
                    rmb.build();
                }
            }
    );
    r.getChildResources().forEach(cr -> {
        rb.replaceChildResource(cr, processResource(cr));
    });
    return rb.build();
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:25,代码来源:OzarkModelProcessor.java

示例6: prepareAppEvent

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
private void prepareAppEvent(final String resourceMethodName) throws NoSuchMethodException {
    final Resource.Builder builder = Resource.builder();
    final MockResource mockResource = new MockResource();
    final Method handlingMethod = mockResource.getClass().getMethod(resourceMethodName);

    Method definitionMethod = handlingMethod;
    final Class<?> interfaceClass = mockResource.getClass().getInterfaces()[0];
    if (this.methodDefinedOnInterface(resourceMethodName, interfaceClass.getMethods())) {
        definitionMethod = interfaceClass.getMethod(resourceMethodName);
    }

    final ResourceMethod resourceMethod = builder.addMethod()
            .handlingMethod(handlingMethod)
            .handledBy(mockResource, definitionMethod).build();
    final Resource resource = builder.build();
    final ResourceModel model = new ResourceModel.Builder(false).addResource(resource).build();

    when(this.appEvent.getResourceModel()).thenReturn(model);
    when(this.uriInfo.getMatchedResourceMethod()).thenReturn(resourceMethod);
}
 
开发者ID:mtakaki,项目名称:CredentialStorageService-dw-hibernate,代码行数:21,代码来源:UnitOfWorkApplicationListenerTest.java

示例7: getMockRouter

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
private Router getMockRouter(String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {

        Invocable mockInvocable = PowerMock.createMock(Invocable.class);
        expect(mockInvocable.getHandlingMethod())
                .andReturn(DummyController.class.getDeclaredMethod(methodName, parameterTypes))
                .anyTimes();

        expect(mockInvocable.getHandler())
                .andReturn(MethodHandler.create(DummyController.class))
                .anyTimes();

        org.lambadaframework.jaxrs.model.ResourceMethod mockResourceMethod = PowerMock.createMock(org.lambadaframework.jaxrs.model.ResourceMethod
                .class);
        expect(mockResourceMethod.getInvocable())
                .andReturn(mockInvocable)
                .anyTimes();

        Router mockRouter = PowerMock.createMock(Router.class);
        expect(mockRouter.route(anyObject()))
                .andReturn(mockResourceMethod)
                .anyTimes();

        PowerMock.replayAll();
        return mockRouter;
    }
 
开发者ID:lambadaframework,项目名称:lambadaframework,代码行数:26,代码来源:HandlerTest.java

示例8: onEvent

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的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

示例9: prepareAppEvent

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
private void prepareAppEvent(String resourceMethodName) throws NoSuchMethodException {
    final Resource.Builder builder = Resource.builder();
    final MockResource mockResource = new MockResource();
    final Method handlingMethod = mockResource.getClass().getMethod(resourceMethodName);

    Method definitionMethod = handlingMethod;
    Class<?> interfaceClass = mockResource.getClass().getInterfaces()[0];
    if (methodDefinedOnInterface(resourceMethodName, interfaceClass.getMethods())) {
        definitionMethod = interfaceClass.getMethod(resourceMethodName);
    }

    final ResourceMethod resourceMethod = builder.addMethod()
            .handlingMethod(handlingMethod)
            .handledBy(mockResource, definitionMethod).build();
    final Resource resource = builder.build();
    final ResourceModel model = new ResourceModel.Builder(false).addResource(resource).build();

    when(appEvent.getResourceModel()).thenReturn(model);
    when(uriInfo.getMatchedResourceMethod()).thenReturn(resourceMethod);
}
 
开发者ID:scottescue,项目名称:dropwizard-entitymanager,代码行数:21,代码来源:UnitOfWorkApplicationListenerTest.java

示例10: registerCircuitBreakerAnnotations

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
/**
 * Registers all the given {@link ResourceMethod} into the meter map and in
 * the {@link MetricRegistry}.
 *
 * @param resourceMethods
 *            A list of {@link ResourceMethod} that will be metered for
 *            failures.
 */
private void registerCircuitBreakerAnnotations(final List<ResourceMethod> resourceMethods) {
    resourceMethods.parallelStream()
            .filter(Objects::nonNull)
            .forEach(resourceMethod -> {
                this.getCircuitBreakerName(resourceMethod)
                        .ifPresent(actualCircuitName -> {
                            this.meterMap.put(actualCircuitName,
                                    this.circuitBreaker.getMeter(
                                            actualCircuitName,
                                            this.customThresholds.containsKey(actualCircuitName)
                                                    ? this.customThresholds
                                                            .get(actualCircuitName)
                                                    : this.defaultThreshold));

                            final String openCircuitName = new StringBuilder(actualCircuitName)
                                    .append(OPEN_CIRCUIT_SUFFIX).toString();
                            this.meterMap.put(openCircuitName,
                                    this.metricRegistry.meter(openCircuitName));
                        });
            });
}
 
开发者ID:mtakaki,项目名称:dropwizard-circuitbreaker,代码行数:30,代码来源:CircuitBreakerApplicationEventListener.java

示例11: getCircuitBreakerName

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
/**
 * Builds the circuit breaker name with the given {@link ResourceMethod}. It
 * the method is {@code null} or the method is not annotated with
 * {@link CircuitBreaker} it will return {@code Optional.empty()}.
 *
 * @param resourceMethod
 *            The method that may contain a {@link CircuitBreaker}
 *            annotation and will be monitored.
 * @return An Optional of the circuit breaker name or
 *         {@code Optional.empty()} if it's not annotated.
 */
private Optional<String> getCircuitBreakerName(final ResourceMethod resourceMethod) {
    // Apparently resourceMethod can be null.
    if (resourceMethod == null) {
        return Optional.empty();
    }

    try (Timer.Context context = this.requestOverheadTimer.time()) {
        final Invocable invocable = resourceMethod.getInvocable();
        Method method = invocable.getDefinitionMethod();
        CircuitBreaker circuitBreaker = method.getAnnotation(CircuitBreaker.class);

        // In case it's a child class with a parent method annotated.
        if (circuitBreaker == null) {
            method = invocable.getHandlingMethod();
            circuitBreaker = method.getAnnotation(CircuitBreaker.class);
        }

        if (circuitBreaker != null) {
            return Optional.of(StringUtils.defaultIfBlank(circuitBreaker.name(),
                    name(invocable.getHandler().getHandlerClass(), method.getName())));
        } else {
            return Optional.empty();
        }
    }
}
 
开发者ID:mtakaki,项目名称:dropwizard-circuitbreaker,代码行数:37,代码来源:CircuitBreakerApplicationEventListener.java

示例12: getName

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
private static String getName(final ResourceMethod method,
                              final PerformanceMetric annotation, String metric) {
  StringBuilder builder = new StringBuilder();
  boolean prefixed = false;
  if (annotation != null && !annotation.value().equals(PerformanceMetric.DEFAULT_NAME)) {
    builder.append(annotation.value());
    builder.append('.');
    prefixed = true;
  }
  if (!prefixed && method != null) {
    String className = method.getInvocable().getDefinitionMethod()
        .getDeclaringClass().getSimpleName();
    String methodName = method.getInvocable().getDefinitionMethod().getName();
    builder.append(className);
    builder.append('.');
    builder.append(methodName);
    builder.append('.');
  }
  builder.append(metric);
  return builder.toString();
}
 
开发者ID:confluentinc,项目名称:rest-utils,代码行数:22,代码来源:MetricsResourceMethodApplicationListener.java

示例13: prepareAppEvent

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
private void prepareAppEvent(String resourceMethodName) throws NoSuchMethodException {
    final Resource.Builder builder = Resource.builder();
    final MockResource mockResource = new MockResource();
    final Method handlingMethod = mockResource.getClass().getMethod(resourceMethodName);

    Method definitionMethod = handlingMethod;
    Class<?> interfaceClass = mockResource.getClass().getInterfaces()[0];
    if (methodDefinedOnInterface(resourceMethodName, interfaceClass.getMethods())) {
        definitionMethod = interfaceClass.getMethod(resourceMethodName);
    }

    final ResourceMethod resourceMethod = builder.addMethod().handlingMethod(handlingMethod)
            .handledBy(mockResource, definitionMethod).build();
    final Resource resource = builder.build();
    final ResourceModel model = new ResourceModel.Builder(false).addResource(resource).build();

    when(appEvent.getResourceModel()).thenReturn(model);
    when(uriInfo.getMatchedResourceMethod()).thenReturn(resourceMethod);
}
 
开发者ID:Astonish-Results,项目名称:dropwizard-routing,代码行数:20,代码来源:RoutingUnitOfWorkApplicationListenerTest.java

示例14: rebuildResource

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
/**
    * Builds new {@link Resource} from passed one with new
    * {@link org.glassfish.jersey.process.Inflector} implementation
    * {@link RestInflector} and with all child resources
    * 
    * @param resource
    * @return {@link Resource}
    * @throws IOException
    */
   public static Resource rebuildResource(Resource resource)
    throws IOException {

Resource rebuiltResource;

Resource.Builder builder = Resource.builder(resource.getPath());
builder.name(resource.getName());
MetaData metaData = getMetaData(resource);

List<ResourceMethod> methods = resource.getAllMethods();
for (ResourceMethod method : methods) {
    addMethod(builder, method, metaData);
}
// Registers children resources recursively
registerChildren(resource, builder);

rebuiltResource = builder.build();

return rebuiltResource;
   }
 
开发者ID:levants,项目名称:lightmare,代码行数:30,代码来源:ResourceBuilder.java

示例15: rebuildResource

import org.glassfish.jersey.server.model.ResourceMethod; //导入依赖的package包/类
/**
 * Builds new {@link Resource} from passed one with new
 * {@link org.glassfish.jersey.process.Inflector} implementation
 * {@link RestInflector} and with all child resources
 * 
 * @param resource
 * @return {@link Resource}
 * @throws IOException
 */
public static Resource rebuildResource(Resource resource) throws IOException {

    Resource rebuiltResource;

    Resource.Builder builder = Resource.builder(resource.getPath());
    builder.name(resource.getName());
    MetaData metaData = getMetaData(resource);

    List<ResourceMethod> methods = resource.getAllMethods();
    for (ResourceMethod method : methods) {
        addMethod(builder, method, metaData);
    }
    // Registers children resources recursively
    registerChildren(resource, builder);
    rebuiltResource = builder.build();

    return rebuiltResource;
}
 
开发者ID:levants,项目名称:lightmare,代码行数:28,代码来源:ResourceBuilder.java


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