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

The following examples show how to use javax.servlet.http.HttpServletRequest#getIntHeader() . 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: iotplatform   File: BaseController.java    License: Apache License 2.0 6 votes vote down vote up
protected String constructBaseUrl(HttpServletRequest request) {
  String scheme = request.getScheme();
  if (request.getHeader("x-forwarded-proto") != null) {
    scheme = request.getHeader("x-forwarded-proto");
  }
  int serverPort = request.getServerPort();
  if (request.getHeader("x-forwarded-port") != null) {
    try {
      serverPort = request.getIntHeader("x-forwarded-port");
    } catch (NumberFormatException e) {
    }
  }

  String baseUrl = String.format("%s://%s:%d", scheme, request.getServerName(), serverPort);
  return baseUrl;
}
 
Example 2
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
  doResponse(res);

  int length = req.getIntHeader("Content-Length");
  char[] postData = new char[length];

  int pos = 0;
  while (pos < length) {
    int read = req.getReader().read(postData, pos, length - pos);
    if (read == -1) {
      throw new EOFException("expected " + (length - pos) + " more bytes");
    }
    pos += read;
  }

  res.getWriter().println("Post data is:" + new String(postData));
}
 
Example 3
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);

  // Verify all of the header accessors contain the upload header.
  if (!req.getHeader(UPLOAD_HEADER).equals("true")
      || !Collections.list(req.getHeaderNames()).contains(UPLOAD_HEADER)
      || !Collections.list(req.getHeaders(UPLOAD_HEADER)).contains("true")) {
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "Expected header to be present: " + UPLOAD_HEADER);
    return;
  }
  try {
    req.getIntHeader(UPLOAD_HEADER);
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "Expected header to be present: " + UPLOAD_HEADER);
    return;
  } catch (NumberFormatException e) {
  }

  Map<String, String[]> parameterMap = req.getParameterMap();
  if (!parameterMap.containsKey("text1")) {
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "Expected text1 to be found in the parameterMap.");
  }
  if (req.getParameter("text1") == null || req.getParameter("text1").length() == 0) {
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Expected non-empty text1 field.");
    return;
  }

  // Verify blob keys are present.
  if (blobs.size() == 1) {
    BlobKey blobKey =
        blobs
            .entrySet()
            .iterator()
            .next()
            .getValue();
    resp.sendRedirect("/serve-blob?key=" + blobKey.getKeyString());
  } else {
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "Expect one uploaded blob, got " + blobs.size());
  }
}