예제 #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
  public AbstractContainerRequestValueFactory<?> createValueFactory(Parameter parameter) {
    String parameterName = parameter.getSourceName();

    if (parameterName == null || parameterName.isEmpty()) {
      // Invalid query parameter name
      return null;
    }

    MultivaluedParameterExtractor e = get(parameter);
    if (e == null) {
      return null;
    }
    return new FormParamValueFactory(e, !parameter.isEncoded());
  }
 @Override
 protected AbstractContainerRequestValueFactory<?> createValueFactory(Parameter parameter) {
   Class<?> classType = parameter.getRawType();
   if (classType == null || !classType.equals(AuthToken.class)) {
     return null;
   }
   return new AuthTokenValueFactory();
 }
  /** {@inheritDoc} */
  @Override
  protected AbstractContainerRequestValueFactory<?> createValueFactory(Parameter parameter) {
    Class<?> classType = parameter.getRawType();

    if (classType == null || (!classType.equals(ProductSearchCriteria.class))) {
      return null;
    }
    return new ProductSearchCriteriaValueFactory();
  }
예제 #5
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;
  }
  /**
   * @param ar abstract resource
   * @param am abstract method
   * @param p parameter
   * @return parameter
   * @see
   *     org.glassfish.jersey.server.wadl.WadlGenerator#createParam(org.glassfish.jersey.server.model.Resource,
   *     org.glassfish.jersey.server.model.ResourceMethod,
   *     org.glassfish.jersey.server.model.Parameter)
   */
  public Param createParam(
      org.glassfish.jersey.server.model.Resource ar,
      org.glassfish.jersey.server.model.ResourceMethod am,
      Parameter p) {
    final Param param = wadlGeneratorDelegate.createParam(ar, am, p);

    // If the paramter is an entity we probably want to convert this to XML
    //
    if (p.getSource() == Parameter.Source.ENTITY) {
      nameCallbacks.add(
          new TypeCallbackPair(
              new GenericType(p.getType()),
              new NameCallbackSetter() {
                public void setName(QName name) {
                  param.setType(name);
                }
              }));
    }

    return param;
  }
    @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;
    }
  /**
   * @param ar abstract resource
   * @param arm abstract resource method
   * @param mt media type
   * @return respresentation type
   * @see org.glassfish.jersey.server.wadl.WadlGenerator# createRequestRepresentation
   *     (org.glassfish.jersey.server.model.Resource,
   *     org.glassfish.jersey.server.model.ResourceMethod, javax.ws.rs.core.MediaType)
   */
  public Representation createRequestRepresentation(
      org.glassfish.jersey.server.model.Resource ar,
      org.glassfish.jersey.server.model.ResourceMethod arm,
      MediaType mt) {

    final Representation rt = wadlGeneratorDelegate.createRequestRepresentation(ar, arm, mt);

    for (Parameter p : arm.getInvocable().getParameters()) {
      if (p.getSource() == Parameter.Source.ENTITY) {
        nameCallbacks.add(
            new TypeCallbackPair(
                new GenericType(p.getType()),
                new NameCallbackSetter() {
                  @Override
                  public void setName(QName name) {
                    rt.setElement(name);
                  }
                }));
      }
    }

    return rt;
  }