Esempio n. 1
0
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    logger.info("get: " + req.getQueryString());

    String sessionId = req.getParameter("sessionId");
    if (!Utils.isNullOrEmpty(sessionId)) {
      Session session = getSessionCache().getSessionForSessionId(sessionId);
      if (session.getUserProfile() != null) {
        String picture = req.getParameter("picture");
        if ("tmp".equals(picture)) {
          String fileName = req.getParameter("filename");
          if (fileName.contains("..")) return;
          System.out.println("fnis:" + fileName);
          File picFile = new File(Backend.getWorkDir() + "tmpfiles" + File.separator + fileName);

          OutputStream out = resp.getOutputStream();
          FileInputStream fi = new FileInputStream(picFile);
          resp.setContentType("image");
          IOUtils.copy(fi, out);
          fi.close();
          out.close();

        } else if ("user".equals(picture)) {
          try {
            byte[] rawPicture = null;
            String fromUniqueUserId = req.getParameter("uniqueUserId");

            if (session.getUserProfile().getUniqueUserID().equals(fromUniqueUserId)) {
              if (Boolean.parseBoolean(req.getParameter("bigPicture"))) {
                logger.info("sending big user picture");
                rawPicture = session.getUserProfile().getUserCredentials().getPicture();
              } else {
                logger.info("sending small user picture");
                rawPicture = session.getUserProfile().getUserCredentials().getSmallPicture();
              }
            }
            OutputStream out = resp.getOutputStream();
            if (rawPicture == null) {
              FileInputStream fi =
                  new FileInputStream(
                      Backend.getWebContentFolder().getAbsolutePath()
                          + File.separator
                          + "images"
                          + File.separator
                          + "replacement_user_image.png");
              resp.setContentType("image");
              IOUtils.copy(fi, out);
              fi.close();
            } else {
              out.write(rawPicture);
            }
            out.close();
          } catch (Exception e) {
            logger.error("error sending user picture", e);
          }
        }
      }
    } else super.doGet(req, resp);
  }
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   super.doGet(req, resp);
   service(req, resp);
   log("method GET");
 }
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   LOG.info("enter--doGet");
   super.doGet(req, resp);
   LOG.info("exit--doGet");
 }
Esempio n. 4
0
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   // TODO Auto-generated method stub
   super.doGet(req, resp);
   doPost(req, resp);
 }
Esempio n. 5
0
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   // TODO Auto-generated method stub
   super.doGet(req, resp);
   PrintWriter pw = resp.getWriter();
   pw.println("hello...");
 }
  /**
   * Receives an HTTP HEAD request from the protected <code>service</code> method and handles the
   * request. The client sends a HEAD request when it wants to see only the headers of a response,
   * such as Content-Type or Content-Length. The HTTP HEAD method counts the output bytes in the
   * response to set the Content-Length header accurately.
   *
   * <p>If you override this method, you can avoid computing the response body and just set the
   * response headers directly to improve performance. Make sure that the <code>doHead</code> method
   * you write is both safe and idempotent (that is, protects itself from being called multiple
   * times for one HTTP HEAD request).
   *
   * <p>If the HTTP HEAD request is incorrectly formatted, <code>doHead</code> returns an HTTP "Bad
   * Request" message.
   *
   * @param req the request object that is passed to the servlet
   * @param resp the response object that the servlet uses to return the headers to the client
   * @exception IOException if an input or output error occurs
   * @exception ServletException if the request for the HEAD could not be handled
   */
  protected void doHead(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    NoBodyResponse response = new NoBodyResponse(resp);

    doGet(req, response);
    response.setContentLength();
  }
Esempio n. 7
0
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws IOException, ServletException {
   if (DEBUG) {
     doPost(req, resp);
   } else {
     super.doGet(req, resp);
   }
 }
Esempio n. 8
0
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    super.doGet(req, resp);

    // req.setAttribute("name", "Devcolibri");

    // req.getRequestDispatcher("mypage.jsp").forward(req, resp);

    PrintWriter out = resp.getWriter();
    out.print("<h1>Hello Servlet</1h1>");
  }
Esempio n. 9
0
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   if (req.getPathInfo() == null) {
     super.doGet(req, resp);
     return;
   }
   String data = req.getPathInfo().replace("/", "");
   req.setAttribute("qrCode", data);
   RequestDispatcher rd = req.getRequestDispatcher("/public/itemView.jsp");
   rd.forward(req, resp);
 }
Esempio n. 10
0
  @Override
  protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
      throws ServletException, IOException {
    ResponderAndRelativeUri r = server.getResponderAndRelativeUri(request);
    if (r == null) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    Responder responder = r.getResponder();
    if (responder.getRequestOption().supportsHttpGet()) {
      processRequest(request, response, r, true);
    } else {
      super.doGet(request, response);
    }
  }
Esempio n. 11
0
 /**
  * Simply calls {@link #doGet(HttpServletRequest, HttpServletResponse)}
  *
  * @see #doGet(HttpServletRequest, HttpServletResponse)
  */
 protected void doPut(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   super.doGet(req, resp);
 }
Esempio n. 12
0
 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   super.doGet(request, response);
 }
Esempio n. 13
0
 protected void doGet(Map<String, Object> model, HttpServletRequest req, HttpServletResponse resp)
     throws IOException, ServletException {
   // Sends "method not implemented" by default
   super.doGet(req, resp);
 }
Esempio n. 14
0
 /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   // TODO Auto-generated method stub
   super.doGet(request, response);
 }
  /**
   * Receives standard HTTP requests from the public <code>service</code> method and dispatches them
   * to the <code>do</code><i>Method</i> methods defined in this class. This method is an
   * HTTP-specific version of the {@link javax.servlet.Servlet#service} method. There's no need to
   * override this method.
   *
   * @param req the {@link HttpServletRequest} object that contains the request the client made of
   *     the servlet
   * @param resp the {@link HttpServletResponse} object that contains the response the servlet
   *     returns to the client
   * @exception IOException if an input or output error occurs while the servlet is handling the
   *     HTTP request
   * @exception ServletException if the HTTP request cannot be handled
   * @see javax.servlet.Servlet#service
   */
  protected void service(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    String method = req.getMethod();

    if (method.equals(METHOD_GET)) {
      long lastModified = getLastModified(req);
      if (lastModified == -1) {
        // servlet doesn't support if-modified-since, no reason
        // to go through further expensive logic
        doGet(req, resp);
      } else {
        long ifModifiedSince;
        try {
          ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE);
        } catch (IllegalArgumentException iae) {
          // Invalid date header - proceed as if none was set
          ifModifiedSince = -1;
        }
        if (ifModifiedSince < (lastModified / 1000 * 1000)) {
          // If the servlet mod time is later, call doGet()
          // Round down to the nearest second for a proper compare
          // A ifModifiedSince of -1 will always be less
          maybeSetLastModified(resp, lastModified);
          doGet(req, resp);
        } else {
          resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        }
      }

    } else if (method.equals(METHOD_HEAD)) {
      long lastModified = getLastModified(req);
      maybeSetLastModified(resp, lastModified);
      doHead(req, resp);

    } else if (method.equals(METHOD_POST)) {
      doPost(req, resp);

    } else if (method.equals(METHOD_PUT)) {
      doPut(req, resp);

    } else if (method.equals(METHOD_DELETE)) {
      doDelete(req, resp);

    } else if (method.equals(METHOD_OPTIONS)) {
      doOptions(req, resp);

    } else if (method.equals(METHOD_TRACE)) {
      doTrace(req, resp);

    } else {
      //
      // Note that this means NO servlet supports whatever
      // method was requested, anywhere on this server.
      //

      String errMsg = lStrings.getString("http.method_not_implemented");
      Object[] errArgs = new Object[1];
      errArgs[0] = method;
      errMsg = MessageFormat.format(errMsg, errArgs);

      resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, errMsg);
    }
  }