Java Code Examples for javax.servlet.http.HttpServletRequest#getContentLengthLong()

The following examples show how to use javax.servlet.http.HttpServletRequest#getContentLengthLong() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: rdf-delta   File: LogOp.java    License: Apache License 2.0 5 votes vote down vote up
private static RDFPatch readPatch(DeltaAction action) throws IOException {
    HttpServletRequest request = action.request;
    long byteLength = request.getContentLengthLong();
    try ( CountingInputStream in = new CountingInputStream(request.getInputStream()); ) {
        RDFPatch patch = RDFPatchOps.read(in);
        if ( byteLength != -1L ) {
            if ( in.getByteCount() != byteLength )
                FmtLog.warn(LOG, "[%d] Length mismatch: Read: %d : Content-Length: %d", action.id, in.getByteCount(),  byteLength);
        }
        return patch;
    }
}
 
Example 2
Source Project: nakadi   File: TracingFilter.java    License: MIT License 5 votes vote down vote up
private AsyncRequestListener(final HttpServletRequest request, final HttpServletResponse response,
                             final String flowId, final Span span) {
    this.response = response;
    this.flowId = flowId;
    this.currentSpan = span;
    this.contentLength = request.getContentLengthLong() == -1 ? 0 : request.getContentLengthLong();
}
 
Example 3
Source Project: nakadi   File: LoggingFilter.java    License: MIT License 5 votes vote down vote up
private RequestLogInfo(final HttpServletRequest request, final long requestTime) {
    this.userAgent = Optional.ofNullable(request.getHeader("User-Agent")).orElse("-");
    this.user = authorizationService.getSubject().map(Subject::getName).orElse("-");
    this.method = request.getMethod();
    this.path = request.getRequestURI();
    this.query = Optional.ofNullable(request.getQueryString()).map(q -> "?" + q).orElse("");
    this.contentEncoding = Optional.ofNullable(request.getHeader(HttpHeaders.CONTENT_ENCODING)).orElse("-");
    this.acceptEncoding = Optional.ofNullable(request.getHeader(HttpHeaders.ACCEPT_ENCODING)).orElse("-");
    this.contentLength = request.getContentLengthLong() == -1 ? 0 : request.getContentLengthLong();
    this.requestTime = requestTime;
}
 
Example 4
Source Project: Tomcat8-Source-Read   File: WebdavServlet.java    License: MIT License 4 votes vote down vote up
/**
 * MKCOL Method.
 * @param req The Servlet request
 * @param resp The Servlet response
 * @throws ServletException If an error occurs
 * @throws IOException If an IO error occurs
 */
protected void doMkcol(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

    String path = getRelativePath(req);

    WebResource resource = resources.getResource(path);

    // Can't create a collection if a resource already exists at the given
    // path
    if (resource.exists()) {
        sendNotAllowed(req, resp);
        return;
    }

    if (readOnly) {
        resp.sendError(WebdavStatus.SC_FORBIDDEN);
        return;
    }

    if (isLocked(req)) {
        resp.sendError(WebdavStatus.SC_LOCKED);
        return;
    }

    if (req.getContentLengthLong() > 0) {
        DocumentBuilder documentBuilder = getDocumentBuilder();
        try {
            // Document document =
            documentBuilder.parse(new InputSource(req.getInputStream()));
            // TODO : Process this request body
            resp.sendError(WebdavStatus.SC_NOT_IMPLEMENTED);
            return;

        } catch(SAXException saxe) {
            // Parse error - assume invalid content
            resp.sendError(WebdavStatus.SC_UNSUPPORTED_MEDIA_TYPE);
            return;
        }
    }

    if (resources.mkdir(path)) {
        resp.setStatus(WebdavStatus.SC_CREATED);
        // Removing any lock-null resource which would be present
        lockNullResources.remove(path);
    } else {
        resp.sendError(WebdavStatus.SC_CONFLICT,
                       WebdavStatus.getStatusText
                       (WebdavStatus.SC_CONFLICT));
    }
}
 
Example 5
Source Project: enkan   File: ServletUtils.java    License: Eclipse Public License 1.0 4 votes vote down vote up
private static Long getContentLength(HttpServletRequest servletRequest) {
    long length = servletRequest.getContentLengthLong();
    return length >= 0 ? length : null;
}