Example #1
0
  protected boolean hasReturnRepresentation(List<Header> preferenceAppliedHeaders) {
    for (Header h : preferenceAppliedHeaders) {
      // Handle optional whitespace, quoted preference token values, and
      // other tokens in the Preference-Applied response header.
      if (h.getValue().matches("(^|[ ;])return *= *\"?representation\"?($|[ ;])")) {
        return true;
      }
    }

    return false;
  }
 @BeforeClass(alwaysRun = true)
 public void determineOptions() {
   String uri = getResourceUri();
   if (StringUtils.isNotBlank(uri)) {
     // Use HTTP OPTIONS, which MUST be supported by LDP servers, to determine what methods are
     // supported on this container.
     Response optionsResponse = buildBaseRequestSpecification().options(uri);
     Headers headers = optionsResponse.getHeaders();
     List<Header> allowHeaders = headers.getList(ALLOW);
     for (Header allowHeader : allowHeaders) {
       String allow = allowHeader.getValue();
       if (allow != null) {
         String[] methods = allow.split("\\s*,\\s*");
         for (String method : methods) {
           options.add(method);
         }
       }
     }
   }
 }
Example #3
0
  // LinkDelegate doesn't handle this for us
  protected List<String> splitLinks(Header linkHeader) {
    final ArrayList<String> links = new ArrayList<>();
    final String value = linkHeader.getValue();

    // Track the beginning index for the current link-value.
    int beginIndex = 0;

    // Is the current char inside a URI-Reference?
    boolean inUriRef = false;

    // Split the string on commas, but only if not in a URI-Reference
    // delimited by angle brackets.
    for (int i = 0; i < value.length(); ++i) {
      final char c = value.charAt(i);

      if (c == ',' && !inUriRef) {
        // Found a comma not in a URI-Reference. Split the string.
        final String link = value.substring(beginIndex, i).trim();
        links.add(link);

        // Assign the next begin index for the next link.
        beginIndex = i + 1;
      } else if (c == '<') {
        // Angle brackets are not legal characters in a URI, so they can
        // only be used to mark the start and end of a URI-Reference.
        // See http://tools.ietf.org/html/rfc3986#section-2
        inUriRef = true;
      } else if (c == '>') {
        inUriRef = false;
      }
    }

    // There should be one more link in the string.
    final String link = value.substring(beginIndex, value.length()).trim();
    links.add(link);

    return links;
  }