Example usage for javax.servlet.http HttpServletRequest getContentLength

List of usage examples for javax.servlet.http HttpServletRequest getContentLength

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getContentLength.

Prototype

public int getContentLength();

Source Link

Document

Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known ir is greater than Integer.MAX_VALUE.

Usage

From source file:gwtupload.server.gae.AppEngineUploadAction.java

@Override
public void checkRequest(HttpServletRequest request) {
    super.checkRequest(request);
    if (request.getContentLength() > MemCacheFileItemFactory.DEFAULT_REQUEST_SIZE + 1024) {
        throw new RuntimeException("Google appengine doesn't allow requests with a size greater than "
                + MemCacheFileItemFactory.DEFAULT_REQUEST_SIZE + " Bytes");
    }// w  w  w . j  a v  a  2  s  .c  o  m
}

From source file:gwtupload.server.gae.AppEngineUploadAction.java

@Override
protected final AbstractUploadListener createNewListener(HttpServletRequest request) {
    return new MemCacheUploadListener(uploadDelay, request.getContentLength());
}

From source file:ubic.gemma.web.util.upload.UploadListener.java

public UploadListener(HttpServletRequest request) {
    this.request = request;
    this.totalToRead = request.getContentLength();
}

From source file:org.nightcode.gwt.selectio.server.SelectioServlet.java

private String getContent(HttpServletRequest request) throws IOException {
    int contentLength = request.getContentLength();
    byte[] content = new byte[contentLength];
    BufferedInputStream bis = new BufferedInputStream(request.getInputStream());
    try {//w  w w  .j  a  v  a2s  .c om
        int readBytes = 0;
        while (bis.read(content, readBytes, contentLength - readBytes) > 0) {
            // read the contents
        }
        return new String(content);
    } finally {
        bis.close();
    }
}

From source file:de.betterform.agent.web.upload.UploadListener.java

public UploadListener(HttpServletRequest request, String sessionKey) {
    this.request = request;
    this.delay = 0; //not used
    totalToRead = request.getContentLength();
    this.startTime = System.currentTimeMillis();
    this.sessionKey = sessionKey;
}

From source file:com.liferay.util.servlet.fileupload.LiferayInputStream.java

public LiferayInputStream(HttpServletRequest req) throws IOException {
    super(req.getInputStream());

    _req = req;/*  w  w  w. j  a  v  a 2 s  .  com*/
    _ses = req.getSession();
    _totalSize = req.getContentLength();
}

From source file:be.solidx.hot.test.nio.http.EchoPOSTServlet.java

protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setContentType(req.getContentType());
    resp.setContentLength(req.getContentLength());
    String body = IOUtils.toString(req.getInputStream());
    System.out.println(body);/*from  w  w w.  ja v a2s.  c o m*/
    resp.getWriter().write(body);
}

From source file:de.elomagic.mag.ServletMock.java

@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    received = false;/*from   ww  w.j a  v a2  s . c  o m*/

    lastContentLength = request.getContentLength();
    requestedUri = request.getRequestURI();

    if (lastContentLength > 0) {
        lastContent = IOUtils.readFully(request.getInputStream(), lastContentLength);
    }

    LOGGER.info("contentLength=" + FileUtils.byteCountToDisplaySize(lastContentLength));
    LOGGER.info("content" + lastContent);

    response.setStatus(HttpServletResponse.SC_CREATED);

    received = true;
}

From source file:foam.nanos.blob.HttpBlobService.java

protected void upload(X x) {
    InputStreamBlob blob = null;//from   ww w.ja v  a  2  s.  co  m
    HttpServletRequest req = x.get(HttpServletRequest.class);
    HttpServletResponse resp = x.get(HttpServletResponse.class);

    try {
        int size = req.getContentLength();
        blob = new InputStreamBlob(req.getInputStream(), size);
        new Outputter(resp.getWriter(), OutputterMode.NETWORK).output(getDelegate().put(blob));
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException(t);
    } finally {
        IOUtils.closeQuietly(blob);
    }
}

From source file:de.ingrid.interfaces.csw.server.CSWServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//*from ww w .  j  a v a 2  s . com*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    try {
        if (request.getHeader("Keep-Alive") != null && request.getContentLength() == -1) {
            Log.debug("Ignore keep-alive request.");
        } else if (request.getContentType().toLowerCase().indexOf("application/soap+xml") != -1) {
            this.serverFacade.handleSoapRequest(request, response);
        } else {
            this.serverFacade.handlePostRequest(request, response);
        }
    } catch (Exception ex) {
        throw new ServletException("POST failed: " + ex.getMessage(), ex);
    }
}