Package com.kurento.kmf.repository.internal

Examples of com.kurento.kmf.repository.internal.RepositoryHttpEndpointImpl


    }

    try (RandomAccessFile randAccessContentFile = new RandomAccessFile(
        contentFile, "rw")) {

      RepositoryHttpEndpointImpl repoItemHttpElem = repoHttpManager
          .getHttpRepoItemElem(sessionId);

      // Copy data in oldRevisionContent to contentFile
      if (repoItemHttpElem != null) {

        try (BufferedInputStream bufOldRevStream = new BufferedInputStream(
            repoItemHttpElem.createRepoItemInputStream(),
            FILE_BUFFER_SIZE)) {

          int numBytesRead;
          byte[] copyBuffer = new byte[FILE_BUFFER_SIZE];
          while ((numBytesRead = bufOldRevStream.read(copyBuffer)) != -1) {
View Full Code Here


    boolean serveContent = content;

    // Identify the requested resource path
    String sessionId = extractSessionId(request);

    RepositoryHttpEndpointImpl elem = repoHttpManager
        .getHttpRepoItemElem(sessionId);

    if (elem == null) {

      if (debug > 0) {
        log("Resource with sessionId '" + sessionId + "' not found");
      }

      response.sendError(SC_NOT_FOUND, request.getRequestURI());
      return;
    }

    elem.fireStartedEventIfFirstTime();

    RepositoryItem repositoryItem = elem.getRepositoryItem();
    RepositoryItemAttributes attributes = repositoryItem.getAttributes();

    if (debug > 0) {
      if (serveContent) {
        log("Serving resource with sessionId '"
            + sessionId
            + "' headers and data. This resource corresponds to repository item '"
            + repositoryItem.getId() + "'");
      } else {
        log("Serving resource with sessionId '"
            + sessionId
            + "' headers only. This resource corresponds to repository item '"
            + repositoryItem.getId() + "'");
      }
    }

    boolean malformedRequest = response.getStatus() >= SC_BAD_REQUEST;

    if (!malformedRequest && !checkIfHeaders(request, response, attributes)) {
      return;
    }

    String contentType = getContentType(elem, attributes);

    List<Range> ranges = null;

    if (!malformedRequest) {

      response.setHeader("Accept-Ranges", "bytes");
      response.setHeader("ETag", attributes.getETag());
      response.setHeader("Last-Modified",
          attributes.getLastModifiedHttp());

      ranges = parseRange(request, response, attributes);
    }

    long contentLength = attributes.getContentLength();

    // Special case for zero length files, which would cause a
    // (silent) ISE when setting the output buffer size
    if (contentLength == 0L) {
      serveContent = false;
    }

    // Check to see if a Filter, Valve of wrapper has written some content.
    // If it has, disable range requests and setting of a content length
    // since neither can be done reliably.
    boolean contentWritten = response.isCommitted();

    if (contentWritten) {
      ranges = FULL;
    }

    boolean noRanges = (ranges == null || ranges.isEmpty());

    if (malformedRequest
        || (noRanges && request.getHeader("Range") == null)
        || ranges == FULL) {

      setContentType(response, contentType);

      if (contentLength >= 0) {
        // Don't set a content length if something else has already
        // written to the response.
        if (!contentWritten) {
          setContentLength(response, contentLength);
        }
      }

      // Copy the input stream to our output stream (if requested)
      if (serveContent) {
        copy(elem, response);
      }

    } else {

      if (noRanges) {
        return;
      }

      // Partial content response.
      response.setStatus(SC_PARTIAL_CONTENT);

      if (ranges.size() == 1) {

        Range range = ranges.get(0);

        response.addHeader("Content-Range", "bytes " + range.start
            + "-" + range.end + "/" + range.length);

        long length = range.end - range.start + 1;

        setContentLength(response, length);
        setContentType(response, contentType);

        if (serveContent) {
          copy(elem, response, range);
        }

      } else {

        response.setContentType("multipart/byteranges; boundary="
            + MIME_SEPARATION);

        if (serveContent) {
          copy(elem, response, ranges, contentType);
        }
      }
    }

    elem.stopInTimeout();

  }
View Full Code Here

  protected void uploadContent(HttpServletRequest req,
      HttpServletResponse resp) throws IOException {

    String sessionId = extractSessionId(req);

    RepositoryHttpEndpointImpl elem = repoHttpManager
        .getHttpRepoItemElem(sessionId);

    if (elem == null) {
      resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    elem.stopCurrentTimer();
    elem.fireStartedEventIfFirstTime();

    try (InputStream requestInputStream = req.getInputStream()) {

      try (OutputStream repoItemOutputStream = elem
          .getRepoItemOutputStream()) {

        Range range = parseContentRange(req, resp);

        if (range != null) {

          if (range.start > elem.getWrittenBytes()) {
            resp.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
            resp.getOutputStream().println(
                "The server doesn't support writing ranges "
                    + "ahead of previously written bytes");
          } else if (range.end == elem.getWrittenBytes()) {

            // TODO We assume that the put range is the same than
            // the
            // previous one. Do we need to check this?

            resp.setStatus(SC_OK);
            resp.getOutputStream()
                .println(
                    "The server has detected that the submited range "
                        + "has already submited in a previous request");
          } else if (range.start < elem.getWrittenBytes()
              && range.end > elem.getWrittenBytes()) {

            Range copyRange = new Range();
            copyRange.start = elem.getWrittenBytes() - range.start;
            copyRange.end = range.end - range.start;

            copyStreamsRange(requestInputStream,
                repoItemOutputStream, copyRange);

            resp.setStatus(SC_OK);

          } else if (range.start == elem.getWrittenBytes()) {

            IOUtils.copy(requestInputStream, repoItemOutputStream);

            resp.setStatus(SC_OK);

          }

        } else {

          boolean isMultipart = ServletFileUpload
              .isMultipartContent(req);

          if (isMultipart) {

            uploadMultipart(req, resp, repoItemOutputStream);

          } else {

            try {

              log.info("Start to receive bytes (estimated "
                  + req.getContentLength() + " bytes)");
              int bytes = IOUtils.copy(requestInputStream,
                  repoItemOutputStream);
              resp.setStatus(SC_OK);
              log.info("Bytes received: " + bytes);

            } catch (Exception e) {

              log.warn("Exception when uploading content", e);

              elem.fireSessionErrorEvent(e);
              resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            }
          }
        }
      }

    } finally {
      elem.stopInTimeout();
    }
  }
View Full Code Here

      sessionIdInURL = createUniqueId();
    }

    String url = createUlr(sessionIdInURL);

    RepositoryHttpEndpointImpl elem = null;

    if (repoItemHttpElemClass == RepositoryHttpPlayer.class) {
      elem = new RepositoryHttpPlayerImpl(repositoryItem, sessionIdInURL,
          url, this);
    } else {
View Full Code Here

    Iterator<Entry<String, RepositoryHttpEndpointImpl>> it = sessions
        .entrySet().iterator();

    while (it.hasNext()) {
      Entry<String, RepositoryHttpEndpointImpl> entry = it.next();
      RepositoryHttpEndpointImpl elem = entry.getValue();
      if (elem.getRepositoryItem().getId().equals(item.getId())) {
        elem.forceStopHttpManager(message);
        it.remove();
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.kurento.kmf.repository.internal.RepositoryHttpEndpointImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.