private static WebResource.Builder getBuilder(
      String url, String authorization, Map<String, String> key, Boolean overwrite) {
    Client client = Client.create();
    WebResource wr = client.resource(url);

    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();

    if (key != null && !key.isEmpty()) {
      for (String k : key.keySet()) {
        queryParams.add(k, key.get(k));
      }
    }

    if (overwrite != null && overwrite) {
      queryParams.add(CLOUDHUB_OVERRITE_REST_PARAMETER, overwrite.toString());
    }

    if (queryParams.isEmpty()) {
      return wr.header(HTTP_AUTH_HEADER_NAME, authorization).type(MediaType.APPLICATION_JSON);
    } else {
      return wr.queryParams(queryParams)
          .header(HTTP_AUTH_HEADER_NAME, authorization)
          .type(MediaType.APPLICATION_JSON);
    }
  }
 @Override
 public String toString() {
   MultivaluedMap<String, String> matrixParameters = getMatrixParameters();
   String parameters = MultivaluedMapImpl.toString(matrixParameters, ";"); // $NON-NLS-1$
   String delim = (matrixParameters.isEmpty() ? "" : ";"); // $NON-NLS-1$ //$NON-NLS-2$
   String result = getPath() + delim + parameters;
   return result;
 }
  private void encodeMatrix() {
    if (matrixParams == null || matrixParams.isEmpty()) return;

    for (Map.Entry<String, List<String>> e : matrixParams.entrySet()) {
      String name = e.getKey();

      for (String value : e.getValue()) {
        path.append(';').append(name);
        if (value.length() > 0) path.append('=').append(value);
      }
    }
    matrixParams = null;
  }
  private void encodeQuery() {
    if (queryParams == null || queryParams.isEmpty()) return;

    for (Map.Entry<String, List<String>> e : queryParams.entrySet()) {
      String name = e.getKey();

      for (String value : e.getValue()) {
        if (query.length() > 0) query.append('&');
        query.append(name);

        if (value.length() > 0) query.append('=').append(value);
      }
    }
    queryParams = null;
  }
 @GET
 @Produces("text/plain")
 public String get(
     @MatrixParam("firstname") String firstname,
     @MatrixParam("lastname") String lastname,
     @Context UriInfo uriInfo) {
   final List<PathSegment> pathSegents = uriInfo.getPathSegments();
   final PathSegment lastPathSegm = pathSegents.get(0);
   final MultivaluedMap<String, String> mp = lastPathSegm.getMatrixParameters();
   if (mp.isEmpty()) {
     final ResponseBuilder rb = Response.status(Status.NOT_FOUND);
     rb.entity("matrix parameters are empty");
     throw new WebApplicationException(rb.build());
   }
   return firstname + " " + lastname;
 }
 @Override
 public boolean isEmpty() {
   return delegate.isEmpty();
 }
Beispiel #7
0
  /**
   * Create a new RequestScope.
   *
   * @param path the URL path
   * @param jsonApiDocument the document for this request
   * @param transaction the transaction for this request
   * @param user the user making this request
   * @param dictionary the entity dictionary
   * @param mapper converts JsonApiDocuments to raw JSON
   * @param auditLogger logger for this request
   * @param queryParams the query parameters
   * @param securityMode the current security mode
   * @param permissionExecutorGenerator the user-provided function that will generate a
   *     permissionExecutor
   */
  public RequestScope(
      String path,
      JsonApiDocument jsonApiDocument,
      DataStoreTransaction transaction,
      User user,
      EntityDictionary dictionary,
      JsonApiMapper mapper,
      AuditLogger auditLogger,
      MultivaluedMap<String, String> queryParams,
      SecurityMode securityMode,
      Function<RequestScope, PermissionExecutor> permissionExecutorGenerator,
      MultipleFilterDialect filterDialect,
      boolean useFilterExpressions) {
    this.path = path;
    this.jsonApiDocument = jsonApiDocument;
    this.transaction = transaction;
    this.user = user;
    this.dictionary = dictionary;
    this.mapper = mapper;
    this.auditLogger = auditLogger;
    this.securityMode = securityMode;
    this.filterDialect = filterDialect;

    this.expressionsByType = new HashMap<>();
    this.globalFilterExpression = null;
    this.objectEntityCache = new ObjectEntityCache();
    this.newPersistentResources = new LinkedHashSet<>();
    this.dirtyResources = new LinkedHashSet<>();
    this.commitTriggers = new LinkedHashSet<>();
    this.useFilterExpressions = useFilterExpressions;

    this.permissionExecutor =
        (permissionExecutorGenerator == null)
            ? new ActivePermissionExecutor(this)
            : permissionExecutorGenerator.apply(this);

    this.queryParams =
        (queryParams == null || queryParams.size() == 0)
            ? Optional.empty()
            : Optional.of(queryParams);

    if (this.queryParams.isPresent()) {

      /* Extract any query param that starts with 'filter' */
      MultivaluedMap filterParams = getFilterParams(queryParams);

      String errorMessage = "";
      if (!filterParams.isEmpty()) {

        /* First check to see if there is a global, cross-type filter */
        try {
          globalFilterExpression = filterDialect.parseGlobalExpression(path, filterParams);
        } catch (ParseException e) {
          errorMessage = e.getMessage();
        }

        /* Next check to see if there is are type specific filters */
        try {
          expressionsByType.putAll(filterDialect.parseTypedExpression(path, filterParams));
        } catch (ParseException e) {

          /* If neither dialect parsed, report the last error found */
          if (globalFilterExpression == null) {

            if (errorMessage.isEmpty()) {
              errorMessage = e.getMessage();
            } else if (!errorMessage.equals(e.getMessage())) {

              /* Combine the two different messages together */
              errorMessage = errorMessage + "\n" + e.getMessage();
            }

            throw new InvalidPredicateException(errorMessage);
          }
        }
      }

      this.sparseFields = parseSparseFields(queryParams);
      this.sorting = Sorting.parseQueryParams(queryParams);
      this.pagination = Pagination.parseQueryParams(queryParams);
    } else {
      this.sparseFields = Collections.emptyMap();
      this.sorting = Sorting.getDefaultEmptyInstance();
      this.pagination = Pagination.getDefaultPagination();
    }

    if (transaction instanceof RequestScopedTransaction) {
      ((RequestScopedTransaction) transaction).setRequestScope(this);
    }
  }