/**
   * Get the mover channel for a certain HTTP request. The mover channel is identified by UUID
   * generated upon mover start and sent back to the door as a part of the address info.
   *
   * @param request HttpRequest that was sent by the client
   * @param exclusive True if the mover channel exclusively is to be opened in exclusive mode. False
   *     if the mover channel can be shared with other requests.
   * @return Mover channel for specified UUID
   * @throws IllegalArgumentException Request did not include UUID or no mover channel found for
   *     UUID in the request
   */
  private NettyTransferService<HttpProtocolInfo>.NettyMoverChannel open(
      HttpRequest request, boolean exclusive) throws IllegalArgumentException, URISyntaxException {
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());

    Map<String, List<String>> params = queryStringDecoder.parameters();
    if (!params.containsKey(HttpTransferService.UUID_QUERY_PARAM)) {
      if (!request.getUri().equals("/favicon.ico")) {
        _logger.error(
            "Received request without UUID in the query " + "string. Request-URI was {}",
            request.getUri());
      }

      throw new IllegalArgumentException("Query string does not include any UUID.");
    }

    List<String> uuidList = params.get(HttpTransferService.UUID_QUERY_PARAM);
    if (uuidList.isEmpty()) {
      throw new IllegalArgumentException("UUID parameter does not include any value.");
    }

    UUID uuid = UUID.fromString(uuidList.get(0));
    NettyTransferService<HttpProtocolInfo>.NettyMoverChannel file =
        _server.openFile(uuid, exclusive);
    if (file == null) {
      throw new IllegalArgumentException(
          "Request is no longer valid. " + "Please resubmit to door.");
    }

    URI uri = new URI(request.getUri());
    FsPath requestedFile = FsPath.create(uri.getPath());
    FsPath transferFile = FsPath.create(file.getProtocolInfo().getPath());

    if (!requestedFile.equals(transferFile)) {
      _logger.warn(
          "Received an illegal request for file {}, while serving {}", requestedFile, transferFile);
      throw new IllegalArgumentException(
          "The file you specified does " + "not match the UUID you specified!");
    }

    _files.add(file);

    return file;
  }
Esempio n. 2
0
  public FileAttributes getFileAttributes(String requestPath) throws CacheException {

    PnfsHandler handler = ServletContextHandlerAttributes.getPnfsHandler(ctx);
    FsPath path;
    if (requestPath == null || requestPath.isEmpty()) {
      path = FsPath.ROOT;
    } else {
      path = FsPath.create(FsPath.ROOT + requestPath);
    }
    Set<FileAttribute> attributes = EnumSet.allOf(FileAttribute.class);

    FileAttributes namespaceAttrributes = handler.getFileAttributes(path, attributes);
    return namespaceAttrributes;
  }
 @Override
 public void list(
     Subject subject,
     String path,
     Glob glob,
     Range<Integer> range,
     Set<FileAttribute> attrs,
     ListHandler handler)
     throws CacheException {
   try (DirectoryStream stream =
       _handler.list(subject, Restrictions.none(), FsPath.create(path), glob, range, attrs)) {
     for (DirectoryEntry entry : stream) {
       handler.addEntry(entry.getName(), entry.getFileAttributes());
     }
   } catch (InterruptedException e) {
     throw new TimeoutCacheException(e.getMessage());
   }
 }
 public HttpGetResponse(
     long fileSize, NettyTransferService<HttpProtocolInfo>.NettyMoverChannel file) {
   super(HTTP_1_1, OK);
   HttpProtocolInfo protocolInfo = file.getProtocolInfo();
   headers().add(ACCEPT_RANGES, BYTES);
   headers().add(CONTENT_LENGTH, fileSize);
   String digest = buildDigest(file);
   if (!digest.isEmpty()) {
     headers().add(DIGEST, digest);
   }
   headers()
       .add(
           "Content-Disposition",
           contentDisposition(
               protocolInfo.getDisposition(), FsPath.create(protocolInfo.getPath()).name()));
   if (protocolInfo.getLocation() != null) {
     headers().add(CONTENT_LOCATION, protocolInfo.getLocation());
   }
 }