Esempio n. 1
0
  @Test
  public void resourceTest() {

    Resource.Builder builder = Resource.builder(LightMareBean.class);
    Resource resource = builder.build();
    System.out.println(resource.getName());
    System.out.println(resource);

    List<ResourceMethod> methods = resource.getAllMethods();
    // ResourceMethod.Builder methodBuilder;
    // String name = resource.getName();
    Collection<Class<?>> handlers = resource.getHandlerClasses();
    System.out.println(handlers);
    Class<?> beanClass;
    Method realMethod;
    List<Parameter> parameters;
    for (ResourceMethod method : methods) {
      System.out.println(method);
      realMethod = method.getInvocable().getHandlingMethod();
      realMethod.getParameterTypes();
      MethodHandler handler = method.getInvocable().getHandler();
      List<? extends ResourceModelComponent> components = method.getInvocable().getComponents();
      parameters = method.getInvocable().getParameters();
      MethodHandler methodHandler = method.getInvocable().getHandler();
      System.out.println(methodHandler);
      for (Parameter parameter : parameters) {
        System.out.println(parameter);
        System.out.println(parameter.getRawType());
      }
      System.out.println(components);
      beanClass = handler.getHandlerClass();
      System.out.println(beanClass);
      System.out.println(realMethod);
    }
  }
 @Override
 protected AbstractContainerRequestValueFactory<?> createValueFactory(Parameter parameter) {
   Class<?> classType = parameter.getRawType();
   if (classType == null || !classType.equals(AuthToken.class)) {
     return null;
   }
   return new AuthTokenValueFactory();
 }
Esempio n. 3
0
  @Override
  public Param createParam(
      org.glassfish.jersey.server.model.Resource r, ResourceMethod m, final Parameter p) {

    if (p.getSource() == Parameter.Source.UNKNOWN) return null;

    Param wadlParam = new Param();
    wadlParam.setName(p.getSourceName());

    switch (p.getSource()) {
      case FORM:
        wadlParam.setStyle(ParamStyle.QUERY);
        break;
      case QUERY:
        wadlParam.setStyle(ParamStyle.QUERY);
        break;
      case MATRIX:
        wadlParam.setStyle(ParamStyle.MATRIX);
        break;
      case PATH:
        wadlParam.setStyle(ParamStyle.TEMPLATE);
        break;
      case HEADER:
        wadlParam.setStyle(ParamStyle.HEADER);
        break;
      case COOKIE:
        // Generates name="Cookie" path="<name>"
        wadlParam.setStyle(ParamStyle.HEADER);
        wadlParam.setName("Cookie");
        wadlParam.setPath(p.getSourceName());
        break;
      default:
        break;
    }

    if (p.hasDefaultValue()) wadlParam.setDefault(p.getDefaultValue());
    Class<?> pClass = p.getRawType();
    if (pClass.isArray()) {
      wadlParam.setRepeating(true);
      pClass = pClass.getComponentType();
    }
    if (pClass.equals(int.class) || pClass.equals(Integer.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "int", "xs"));
    else if (pClass.equals(boolean.class) || pClass.equals(Boolean.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "boolean", "xs"));
    else if (pClass.equals(long.class) || pClass.equals(Long.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "long", "xs"));
    else if (pClass.equals(short.class) || pClass.equals(Short.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "short", "xs"));
    else if (pClass.equals(byte.class) || pClass.equals(Byte.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "byte", "xs"));
    else if (pClass.equals(float.class) || pClass.equals(Float.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "float", "xs"));
    else if (pClass.equals(double.class) || pClass.equals(Double.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "double", "xs"));
    else wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "string", "xs"));
    return wadlParam;
  }
  /** {@inheritDoc} */
  @Override
  protected AbstractContainerRequestValueFactory<?> createValueFactory(Parameter parameter) {
    Class<?> classType = parameter.getRawType();

    if (classType == null || (!classType.equals(ProductSearchCriteria.class))) {
      return null;
    }
    return new ProductSearchCriteriaValueFactory();
  }
    @Override
    public Object provide() {
      final ContainerRequest requestContext = getContainerRequest();

      final Class<?> rawType = parameter.getRawType();

      Object value;
      if ((Request.class.isAssignableFrom(rawType)
              || ContainerRequestContext.class.isAssignableFrom(rawType))
          && rawType.isInstance(requestContext)) {
        value = requestContext;
      } else {
        value = requestContext.readEntity(rawType, parameter.getType(), parameter.getAnnotations());
        if (rawType.isPrimitive() && value == null) {
          throw new BadRequestException(
              Response.status(Response.Status.BAD_REQUEST)
                  .entity(LocalizationMessages.ERROR_PRIMITIVE_TYPE_NULL())
                  .build());
        }
      }
      return value;
    }