Exemplo n.º 1
0
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {

    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    Enumeration values = req.getParameterNames();
    String name = "";
    String value = "";
    String id = "";
    while (values.hasMoreElements()) {
      name = ((String) values.nextElement()).trim();
      value = req.getParameter(name).trim();
      if (name.equals("id")) id = value;
    }
    if (url.equals("")) {
      url = getServletContext().getInitParameter("url");
      cas_url = getServletContext().getInitParameter("cas_url");
    }
    HttpSession session = null;
    session = req.getSession(false);
    if (session != null) {
      session.invalidate();
    }
    res.sendRedirect(cas_url);
    return;
  }
Exemplo n.º 2
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Reading All Request Parameters";
    out.println(
        ServletUtilities.headWithTitle(title)
            + "<BODY BGCOLOR=\"#FDF5E6\">\n"
            + "<H1 ALIGN=CENTER>"
            + title
            + "</H1>\n"
            + "<TABLE BORDER=1 ALIGN=CENTER>\n"
            + "<TR BGCOLOR=\"#FFAD00\">\n"
            + "<TH>Parameter Name<TH>Parameter Value(s)");
    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
      String paramName = (String) paramNames.nextElement();
      out.println("<TR><TD>" + paramName + "\n<TD>");
      String[] paramValues = request.getParameterValues(paramName);
      if (paramValues.length == 1) {
        String paramValue = paramValues[0];
        if (paramValue.length() == 0) out.print("<I>No Value</I>");
        else out.print(paramValue);
      } else {
        out.println("<UL>");
        for (int i = 0; i < paramValues.length; i++) {
          out.println("<LI>" + paramValues[i]);
        }
        out.println("</UL>");
      }
    }
    out.println("</TABLE>\n</BODY></HTML>");
  }
Exemplo n.º 3
0
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String pathInfo = req.getPathInfo();

    if (pathInfo.equals("/")) {
      HttpSession session = req.getSession();
      if (session == null) {
        resp.setStatus(401);
        return;
      }
      String username = (String) session.getAttribute("username");
      if (username == null) {
        resp.setStatus(401);
        return;
      }

      Map userMap = loadUserSettingsMap(username);
      if (userMap == null) {
        resp.setStatus(401);
        return;
      }
      Enumeration parameterNames = req.getParameterNames();
      while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        userMap.put(parameterName, req.getParameter(parameterName));
      }
      saveUserSettingsMap(username, userMap);
      return;
    }

    super.doPost(req, resp);
  }
Exemplo n.º 4
0
 @Override
 public void parseRequestParameters(
     final Map<String, String> params, final Map<String, com.bradmcevoy.http.FileItem> files)
     throws RequestParseException {
   try {
     if (isMultiPart()) {
       parseQueryString(params, req.getQueryString());
       @SuppressWarnings("unchecked")
       final List<FileItem> items = new ServletFileUpload().parseRequest(req);
       for (final FileItem item : items) {
         if (item.isFormField()) params.put(item.getFieldName(), item.getString());
         else files.put(item.getFieldName(), new FileItemWrapper(item));
       }
     } else {
       final Enumeration<String> en = req.getParameterNames();
       while (en.hasMoreElements()) {
         final String nm = en.nextElement();
         final String val = req.getParameter(nm);
         params.put(nm, val);
       }
     }
   } catch (final FileUploadException ex) {
     throw new RequestParseException("FileUploadException", ex);
   } catch (final Throwable ex) {
     throw new RequestParseException(ex.getMessage(), ex);
   }
 }
Exemplo n.º 5
0
 /**
  * Return the request parameters as a Properties. Only the first value of multivalued parameters
  * is included.
  */
 Properties getParamsAsProps() {
   Properties props = new Properties();
   for (Enumeration en = req.getParameterNames(); en.hasMoreElements(); ) {
     String name = (String) en.nextElement();
     props.setProperty(name, req.getParameter(name));
   }
   return props;
 }
Exemplo n.º 6
0
 /**
  * Return the values of the given parameter (ignoring case) for the given request.
  *
  * @param req the HttpServletRequest
  * @param paramName the name of the parameter to find.
  * @return the values of the given parameter for the given request.
  */
 public static String[] getParameterValuesIgnoreCase(HttpServletRequest req, String paramName) {
   Enumeration e = req.getParameterNames();
   while (e.hasMoreElements()) {
     String s = (String) e.nextElement();
     if (s.equalsIgnoreCase(paramName)) return req.getParameterValues(s);
   }
   return null;
 }
Exemplo n.º 7
0
 /**
  * Return the request parameters as a Map<String,String>. Only the first value of multivalued
  * parameters is included.
  */
 Map<String, String> getParamsAsMap() {
   Map<String, String> map = new HashMap<String, String>();
   for (Enumeration en = req.getParameterNames(); en.hasMoreElements(); ) {
     String name = (String) en.nextElement();
     map.put(name, req.getParameter(name));
   }
   return map;
 }
Exemplo n.º 8
0
  /**
   * Gathers the parameters in the request as a HTTP URL string. to form request parameters and
   * policy advice String array. It collects all the parameters from the original request except the
   * original goto url and any advice parameters. Note: All the paramters will be url decoded by
   * default., we should make sure that these values are encoded again
   *
   * @param request an HttpServletRequest object that contains the request the client has made of
   *     the servlet.
   * @return An String array, index 0 is policy advice, index 1 is rest of the request parameters
   */
  private String[] parseRequestParams(HttpServletRequest request) {
    StringBuilder adviceList = null;
    StringBuilder parameterString = new StringBuilder(100);
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements(); ) {
      String paramName = (String) e.nextElement();
      if (adviceParams.contains(paramName.toLowerCase())) {
        if (adviceList == null) {
          adviceList = new StringBuilder();
        } else {
          adviceList.append(AMPERSAND);
        }
        String[] values = request.getParameterValues(paramName);
        for (int i = 0; values != null && i < values.length; i++) {
          adviceList.append(paramName).append(EQUAL_TO).append(values[i]);
        }
      } else {
        if (!paramName.equals(GOTO_PARAMETER)) {
          String[] values = request.getParameterValues(paramName);
          for (int i = 0; values != null && i < values.length; i++) {
            parameterString
                .append(AMPERSAND)
                .append(paramName)
                .append(EQUAL_TO)
                .append(URLEncDec.encode(values[i]));
          }
        }
      }
    }
    if (debug.messageEnabled()) {
      debug.message("CDCClientServlet.parseRequestParams:" + "Advice List is = " + adviceList);
      debug.message(
          "CDCClientServlet.parseRequestParams:"
              + "Parameter String is = "
              + parameterString.toString());
    }

    String policyAdviceList;
    String requestParams;

    if (adviceList == null) {
      policyAdviceList = null;
    } else {
      policyAdviceList = adviceList.toString();
    }

    if (parameterString.length() > 0) {
      requestParams = (parameterString.deleteCharAt(0).toString());
    } else {
      requestParams = parameterString.toString();
    }

    return new String[] {policyAdviceList, requestParams};
  }
Exemplo n.º 9
0
  private String paramToString(HttpServletRequest req) {

    String rc = "";

    @SuppressWarnings("rawtypes")
    Enumeration e = req.getParameterNames();
    while (e.hasMoreElements()) {
      String sParameter = (String) e.nextElement();
      rc = rc + sParameter + "=" + URLEncoder.encode(req.getParameter(sParameter)) + "&";
    }

    return rc.substring(0, rc.length() - 1);
  }
Exemplo n.º 10
0
  /** @service the servlet service request. called once for each servlet request. */
  public void service(HttpServletRequest servReq, HttpServletResponse servRes) throws IOException {
    String name;
    String value[];
    String val;

    servRes.setHeader("AUTHORIZATION", "user fred:mypassword");
    ServletOutputStream out = servRes.getOutputStream();

    HttpSession session = servReq.getSession(true);
    session.setAttribute("timemilis", new Long(System.currentTimeMillis()));
    if (session.isNew()) {
      out.println("<p> Session is new ");
    } else {
      out.println("<p> Session is not new ");
    }
    Long l = (Long) session.getAttribute("timemilis");
    out.println("<p> Session id = " + session.getId());
    out.println("<p> TimeMillis = " + l);

    out.println("<H2>Servlet Params</H2>");
    Enumeration e = servReq.getParameterNames();
    while (e.hasMoreElements()) {
      name = (String) e.nextElement();
      value = servReq.getParameterValues(name);
      out.println(name + " : ");
      for (int i = 0; i < value.length; ++i) {
        out.println(value[i]);
      }
      out.println("<p>");
    }

    out.println("<H2> Request Headers : </H2>");
    e = servReq.getHeaderNames();
    while (e.hasMoreElements()) {
      name = (String) e.nextElement();
      val = (String) servReq.getHeader(name);
      out.println("<p>" + name + " : " + val);
    }
    try {
      BufferedReader br = servReq.getReader();
      String line = null;
      while (null != (line = br.readLine())) {
        out.println(line);
      }
    } catch (IOException ie) {
      ie.printStackTrace();
    }

    session.invalidate();
  }
Exemplo n.º 11
0
 protected void logParams() {
   Enumeration en = req.getParameterNames();
   while (en.hasMoreElements()) {
     String name = (String) en.nextElement();
     String vals[];
     String dispval;
     if (StringUtil.indexOfIgnoreCase(name, "passw") >= 0) {
       dispval = req.getParameter(name).length() == 0 ? "" : "********";
     } else if (log.isDebug2() && (vals = req.getParameterValues(name)).length > 1) {
       dispval = StringUtil.separatedString(vals, ", ");
     } else {
       dispval = req.getParameter(name);
     }
     log.debug(name + " = " + dispval);
   }
 }
Exemplo n.º 12
0
 // Get parameter map either directly from an Servlet 2.4 compliant implementation
 // or by looking it up explictely (thanks to codewax for the patch)
 private Map<String, String[]> getParameterMap(HttpServletRequest pReq) {
   try {
     // Servlet 2.4 API
     return pReq.getParameterMap();
   } catch (UnsupportedOperationException exp) {
     // Thrown by 'pseudo' 2.4 Servlet API implementations which fake a 2.4 API
     // As a service for the parameter map is build up explicitely
     Map<String, String[]> ret = new HashMap<String, String[]>();
     Enumeration params = pReq.getParameterNames();
     while (params.hasMoreElements()) {
       String param = (String) params.nextElement();
       ret.put(param, pReq.getParameterValues(param));
     }
     return ret;
   }
 }
Exemplo n.º 13
0
  protected Request setupRequest(String serviceURI, HttpServletRequest httpRequest, String opType)
      throws IOException {
    // No reader.  Done by standard servlet form processing.
    Request request = new Request(serviceURI, null);
    // params => request items
    @SuppressWarnings("unchecked")
    Enumeration<String> en = httpRequest.getParameterNames();

    for (; en.hasMoreElements(); ) {
      String k = en.nextElement();
      String[] x = httpRequest.getParameterValues(k);

      for (int i = 0; i < x.length; i++) {
        String s = x[i];
        request.setParam(k, s);
      }
    }
    request.setParam(Joseki.OPERATION, opType);
    return request;
  }
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/plain");

    resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
    resp.setHeader("Pragma", "no-cache"); // HTTP 1.0
    resp.setDateHeader("Expires", 0); // Proxies.

    Enumeration paramNames = req.getParameterNames();
    String action = req.getParameterValues("action")[0];
    String values = req.getParameterValues("values")[0];

    Gson gson = new Gson();
    JsonValues jsonValues = gson.fromJson(values, JsonValues.class);

    if (action.equals("RECORD")) {
      doRecordAction(jsonValues, resp.getWriter());
    } else if (action.equals("GET")) {
      doGetAction(jsonValues, resp.getWriter());
    }
  }
  static void returnOembed(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    String url = request.getParameter("url");
    if (url == null) throw new Exception("No subject URL found.");

    String retUrl = request.getParameter(S3Servlet.URL_PARAM);
    if (retUrl == null && !S3Servlet.testing)
      throw new Exception("Recieved no launch presentation return url");

    Enumeration<String> en = request.getParameterNames();
    ArrayList<String> keys = new ArrayList<String>(), vals = new ArrayList<String>();

    String key, value;
    while (en.hasMoreElements()) {
      key = en.nextElement();
      if ("action".equals(key)) continue;
      if ("launch_presentation_return_url".equals(key)) continue;
      if ("url".equals(key)) continue;

      if ((value = request.getParameter(key)) != null) {
        keys.add(key);
        vals.add(value);
      } // if//
    } // while//

    String endpoint =
        S3Servlet.makeUrl(
            S3Servlet.server + S3Servlet.prefix + "/" + S3Action.oembed,
            keys.toArray(new String[keys.size()]),
            vals.toArray(new String[vals.size()]));

    String oembedUrl =
        S3Servlet.makeUrl(
            retUrl,
            new String[] {"embed_type", "endpoint", "url"},
            new String[] {"oembed", endpoint, url});

    response.reset();
    response.sendRedirect(oembedUrl);
  } // returnOembed//
Exemplo n.º 16
0
    public Writer getErrorReport(
        Writer to, final HttpServletRequest request, CharTransformer escape) throws IOException {
      final Writer logMsg = new StringWriter();
      final Writer tee = new org.mmbase.util.ChainedWriter(to, logMsg);
      Writer msg = tee;

      LinkedList<Throwable> stack = getStack();
      String ticket = new Date().toString();

      Map<String, String> props;
      try {
        props = org.mmbase.util.ApplicationContextReader.getProperties("mmbase_errorpage");
      } catch (javax.naming.NamingException ne) {
        props = Collections.emptyMap();
        log.info(ne);
      }

      if (request != null) {
        {
          msg.append("Headers\n----------\n");
          // request properties
          for (Object name : Collections.list(request.getHeaderNames())) {
            msg.append(
                escape.transform(
                    name + ": " + escape.transform(request.getHeader((String) name)) + "\n"));
          }
        }
        {
          msg.append("\nAttributes\n----------\n");
          Pattern p = requestIgnore;
          if (p == null && props.get("request_ignore") != null) {
            p = Pattern.compile(props.get("request_ignore"));
          }
          for (Object name : Collections.list(request.getAttributeNames())) {
            if (p == null || !p.matcher((String) name).matches()) {
              msg.append(
                  escape.transform(name + ": " + request.getAttribute((String) name) + "\n"));
            }
          }
        }
        if (Boolean.TRUE.equals(showSession)
            || (showSession == null && !"false".equals(props.get("show_session")))) {
          HttpSession ses = request.getSession(false);
          if (ses != null) {
            msg.append("\nSession\n----------\n");
            Pattern p = sessionIgnore;
            if (p == null && props.get("session_ignore") != null) {
              p = Pattern.compile(props.get("session_ignore"));
            }
            for (Object name : Collections.list(ses.getAttributeNames())) {
              if (p == null || !p.matcher((String) name).matches()) {
                msg.append(escape.transform(name + ": " + ses.getAttribute((String) name) + "\n"));
              }
            }
          }
        }
      }
      msg.append("\n");
      msg.append("Misc. properties\n----------\n");

      if (request != null) {
        msg.append("method: ").append(escape.transform(request.getMethod())).append("\n");
        msg.append("querystring: ").append(escape.transform(request.getQueryString())).append("\n");
        msg.append("requesturl: ")
            .append(escape.transform(request.getRequestURL().toString()))
            .append("\n");
      }
      if (Boolean.TRUE.equals(showMMBaseVersion)
          || (showMMBaseVersion == null && !"false".equals(props.get("show_mmbase_version")))) {
        msg.append("mmbase version: ").append(org.mmbase.Version.get()).append("\n");
      }
      msg.append("status: ").append("").append(String.valueOf(status)).append("\n\n");

      if (request != null) {
        msg.append("Parameters\n----------\n");
        // request parameters
        Enumeration en = request.getParameterNames();
        while (en.hasMoreElements()) {
          String name = (String) en.nextElement();
          msg.append(name)
              .append(": ")
              .append(escape.transform(request.getParameter(name)))
              .append("\n");
        }
      }
      msg.append("\nException ")
          .append(ticket)
          .append("\n----------\n\n")
          .append(
              exception != null
                  ? (escape.transform(exception.getClass().getName()))
                  : "NO EXCEPTION")
          .append(": ");

      int wroteCauses = 0;
      while (!stack.isEmpty()) {

        Throwable t = stack.removeFirst();
        // add stack stacktraces
        if (t != null) {
          if (stack.isEmpty()) { // write last message always
            msg = tee;
          }
          String message = t.getMessage();
          if (msg != tee) {
            to.append("\n=== skipped(see log)  : ")
                .append(escape.transform(t.getClass().getName()))
                .append(": ")
                .append(message)
                .append("\n");
          }

          msg.append("\n\n").append(escape.transform(t.getClass().getName() + ": " + message));
          StackTraceElement[] stackTrace = t.getStackTrace();
          for (StackTraceElement e : stackTrace) {
            msg.append("\n        at ").append(escape.transform(e.toString()));
          }
          if (!stack.isEmpty()) {
            msg.append("\n-------caused:\n");
          }
          wroteCauses++;
          if (wroteCauses >= MAX_CAUSES) {
            msg = logMsg;
          }
        }
      }
      // write errors to  log
      if (status == 500) {
        try {
          if (props.get("to") != null && props.get("to").length() > 0) {
            javax.naming.Context initCtx = new javax.naming.InitialContext();
            javax.naming.Context envCtx = (javax.naming.Context) initCtx.lookup("java:comp/env");
            Object mailSession = envCtx.lookup("mail/Session");
            Class sessionClass = Class.forName("javax.mail.Session");
            Class recipientTypeClass = Class.forName("javax.mail.Message$RecipientType");
            Class messageClass = Class.forName("javax.mail.internet.MimeMessage");
            Object mail = messageClass.getConstructor(sessionClass).newInstance(mailSession);
            messageClass
                .getMethod("addRecipients", recipientTypeClass, String.class)
                .invoke(mail, recipientTypeClass.getDeclaredField("TO").get(null), props.get("to"));
            messageClass.getMethod("setSubject", String.class).invoke(mail, ticket);
            mail.getClass().getMethod("setText", String.class).invoke(mail, logMsg.toString());
            Class.forName("javax.mail.Transport")
                .getMethod("send", Class.forName("javax.mail.Message"))
                .invoke(null, mail);
            tee.append("\nmailed to (").append(String.valueOf(props)).append(")");
          }

        } catch (Exception nnfe) {
          tee.append("\nnot mailed (").append(String.valueOf(nnfe)).append(")");
          if (log.isDebugEnabled()) {
            log.debug(nnfe.getMessage(), nnfe);
          }
        }
        log.error("TICKET " + ticket + ":\n" + logMsg);
      }
      return to;
    }
Exemplo n.º 17
0
  public void getEnv(VariableTable vt) {
    Enumeration e = null;
    HttpServletRequest request = (HttpServletRequest) (pageContext.getRequest());
    HttpSession session = request.getSession(false);

    String db_charset = "gb2312";
    String url_charset = null;

    vt.remove("SESSION.LOGINID");
    vt.remove("SESSION.LOGINNAME");
    vt.remove("SESSION.LOGINROLE");

    if (vt.exists("WEBCHART.DB_CHARSET")) {
      db_charset = vt.getString("WEBCHART.DB_CHARSET");
    }

    if (vt.exists("WEBCHART.URL_CHARSET")) {
      url_charset = vt.getString("WEBCHART.URL_CHARSET");
    }

    if (session != null) {
      e = session.getAttributeNames();
      while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        Object value = session.getAttribute(name);
        vt.add(name, java.sql.Types.VARCHAR);
        if (value != null) vt.setValue(name, value.toString());
      }
      vt.add("SESSION.ID", java.sql.Types.VARCHAR);
      vt.setValue("SESSION.ID", session.getId());
      vt.add("SESSION.CREATE", java.sql.Types.VARCHAR);
      vt.setValue(
          "SESSION.CREATE",
          DBOperation.toString(
              new java.util.Date(session.getCreationTime()), "yyyy-MM-dd HH:mm:ss"));
      vt.add("SESSION.ACCESS", java.sql.Types.VARCHAR);
      vt.setValue(
          "SESSION.ACCESS",
          DBOperation.toString(
              new java.util.Date(session.getLastAccessedTime()), "yyyy-MM-dd HH:mm:ss"));
    }
    e = request.getParameterNames();
    while (e.hasMoreElements()) {
      String name = (String) e.nextElement();
      String value = request.getParameter(name);
      ;
      String par_values[] = request.getParameterValues(name);
      name = name.toUpperCase();
      if (name.equalsIgnoreCase("WEBCHART.SECURITY")
          || name.equalsIgnoreCase("WEBCHART.DEFAULTACCESS")
          || name.equalsIgnoreCase("WEBCHART.ALLOW")
          || name.equalsIgnoreCase("WEBCHART.DENY")
          || name.equalsIgnoreCase("WEBCHART.IPSECURITY")
          || name.equalsIgnoreCase("WEBCHART.IPACCESS")
          || name.equalsIgnoreCase("WEBCHART.IPALLOW")
          || name.equalsIgnoreCase("WEBCHART.IPDENY")
          || name.equalsIgnoreCase("WEBCHART.XSLDOC")
          || name.equalsIgnoreCase("WEBCHART.IMAGEONLY")
          || name.equalsIgnoreCase("WEBCHART.XMLDATA")
          || name.equalsIgnoreCase("WEBCHART.LOGSQL")
          || name.equalsIgnoreCase("WEBCHART.DATATYPE")
          || name.equalsIgnoreCase("WEBCHART.URLS")
          || name.equalsIgnoreCase("WEBCHART.TOPURLS")
          || name.equalsIgnoreCase("WEBCHART.TOPCURR")
          || name.equalsIgnoreCase("WEBCHART.LEFTURLS")
          || name.equalsIgnoreCase("WEBCHART.LEFTCURR")
          || name.equalsIgnoreCase("WEBCHART.INPUTS")
          || name.equalsIgnoreCase("WEBCHART.CACHE")
          || name.equalsIgnoreCase("WEBCHART.DATA")
          || name.equalsIgnoreCase("WEBCHART.CSS")
          || name.equalsIgnoreCase("WEBCHART.RELOAD")
          || name.equalsIgnoreCase("WEBCHART.EXPIRE")
          || name.equalsIgnoreCase("WEBCHART.DMLKEY")
          || name.equalsIgnoreCase("WEBCHART.ENGINE")
          || name.equalsIgnoreCase("WEBCHART.EXCELURL")
          || name.equalsIgnoreCase("WEBCHART.DBID")
          || name.equalsIgnoreCase("WEBCHART.DBIDSEED")
          || name.equalsIgnoreCase("WEBCHART.SECUREFIELDS")
          || name.equalsIgnoreCase("WEBCHART.KEEP_CACHE_IMAGE")
          || name.equalsIgnoreCase("WEBCHART.KEEP_CACHE_TIME")
          || name.startsWith("WEBCHART.SECUREMEMO")
          || name.startsWith("WEBCHART.QUERY_")
          || name.startsWith("WEBCHART.HEADHTML_")
          || name.startsWith("WEBCHART.DATAHTML_")
          || name.startsWith("WEBCHART.VARLIST_")
          || name.startsWith("WEBCHART.FORALL_")
          || name.startsWith("WEBCHART.XMLDATA_")
          || name.startsWith("WEBCHART.TABLE_")
          || name.startsWith("WEBCHART.COLUMN_")
          || name.startsWith("SESSION.")) continue;
      if (name.startsWith("WEBCHART.") && !name.equals("WEBCHART.DOCTYPE")) continue;
      vt.add(name, java.sql.Types.VARCHAR);

      if (par_values != null && par_values.length > 1) {
        StringBuffer temp = new StringBuffer();
        for (int i = 0; i < par_values.length; i++) {
          if (par_values[i] != null && par_values[i].trim().length() > 0) {
            if (temp.length() > 0) {
              temp.append(",");
            }
            temp.append(par_values[i]);
          }
        }
        value = temp.toString();
      }
      if (url_charset != null) {
        try {
          value = new String(value.getBytes(url_charset), db_charset);
        } catch (java.io.UnsupportedEncodingException uee) {
        }
        ;
      }
      vt.setValue(name, value);
    }
    vt.add("REQUEST.REMOTEADDR", java.sql.Types.VARCHAR);
    vt.setValue("REQUEST.REMOTEADDR", getClientIPAddr());
    vt.add("REQUEST.REMOTEHOST", java.sql.Types.VARCHAR);
    vt.setValue("REQUEST.REMOTEHOST", request.getRemoteAddr());
    vt.add("REQUEST.REFERER", java.sql.Types.VARCHAR);
    vt.setValue("REQUEST.REFERER", request.getHeader("Referer"));
    vt.add("REQUEST.QUERYSTRING", java.sql.Types.VARCHAR);
    vt.setValue("REQUEST.QUERYSTRING", request.getQueryString());
  }
Exemplo n.º 18
0
 public Enumeration getParameterNames() {
   return request.getParameterNames();
 }
Exemplo n.º 19
0
  /**
   * Show details about the request
   *
   * @param servlet used to get teh servlet context, may be null
   * @param req the request
   * @return string showing the details of the request.
   */
  public static String showRequestDetail(HttpServlet servlet, HttpServletRequest req) {
    StringBuilder sbuff = new StringBuilder();

    sbuff.append("Request Info\n");
    sbuff.append(" req.getServerName(): ").append(req.getServerName()).append("\n");
    sbuff.append(" req.getServerPort(): ").append(req.getServerPort()).append("\n");
    sbuff.append(" req.getContextPath:").append(req.getContextPath()).append("\n");
    sbuff.append(" req.getServletPath:").append(req.getServletPath()).append("\n");
    sbuff.append(" req.getPathInfo:").append(req.getPathInfo()).append("\n");
    sbuff.append(" req.getQueryString:").append(req.getQueryString()).append("\n");
    sbuff
        .append(" getQueryStringDecoded:")
        .append(EscapeStrings.urlDecode(req.getQueryString()))
        .append("\n");
    /*try {
      sbuff.append(" getQueryStringDecoded:").append(URLDecoder.decode(req.getQueryString(), "UTF-8")).append("\n");
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }*/
    sbuff.append(" req.getRequestURI:").append(req.getRequestURI()).append("\n");
    sbuff.append(" getRequestBase:").append(getRequestBase(req)).append("\n");
    sbuff.append(" getRequestServer:").append(getRequestServer(req)).append("\n");
    sbuff.append(" getRequest:").append(getRequest(req)).append("\n");
    sbuff.append("\n");

    sbuff.append(" req.getPathTranslated:").append(req.getPathTranslated()).append("\n");
    String path = req.getPathTranslated();
    if ((path != null) && (servlet != null)) {
      ServletContext context = servlet.getServletContext();
      sbuff.append(" getMimeType:").append(context.getMimeType(path)).append("\n");
    }
    sbuff.append("\n");
    sbuff.append(" req.getScheme:").append(req.getScheme()).append("\n");
    sbuff.append(" req.getProtocol:").append(req.getProtocol()).append("\n");
    sbuff.append(" req.getMethod:").append(req.getMethod()).append("\n");
    sbuff.append("\n");
    sbuff.append(" req.getContentType:").append(req.getContentType()).append("\n");
    sbuff.append(" req.getContentLength:").append(req.getContentLength()).append("\n");

    sbuff.append(" req.getRemoteAddr():").append(req.getRemoteAddr());
    try {
      sbuff
          .append(" getRemoteHost():")
          .append(java.net.InetAddress.getByName(req.getRemoteHost()).getHostName())
          .append("\n");
    } catch (java.net.UnknownHostException e) {
      sbuff.append(" getRemoteHost():").append(e.getMessage()).append("\n");
    }
    sbuff.append(" getRemoteUser():").append(req.getRemoteUser()).append("\n");

    sbuff.append("\n");
    sbuff.append("Request Parameters:\n");
    Enumeration params = req.getParameterNames();
    while (params.hasMoreElements()) {
      String name = (String) params.nextElement();
      String values[] = req.getParameterValues(name);
      if (values != null) {
        for (int i = 0; i < values.length; i++) {
          sbuff
              .append("  ")
              .append(name)
              .append("  (")
              .append(i)
              .append("): ")
              .append(values[i])
              .append("\n");
        }
      }
    }
    sbuff.append("\n");

    sbuff.append("Request Headers:\n");
    Enumeration names = req.getHeaderNames();
    while (names.hasMoreElements()) {
      String name = (String) names.nextElement();
      Enumeration values = req.getHeaders(name); // support multiple values
      if (values != null) {
        while (values.hasMoreElements()) {
          String value = (String) values.nextElement();
          sbuff.append("  ").append(name).append(": ").append(value).append("\n");
        }
      }
    }
    sbuff.append(" ------------------\n");

    return sbuff.toString();
  }
Exemplo n.º 20
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    request.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();

    try {
      String lien = "";
      HttpSession sessionHttp = request.getSession();

      // Pour le log du personnel
      if (request.getParameter("login") != null && request.getParameter("pwd") != null) {
        String login = request.getParameter("login");
        String pwd = request.getParameter("pwd");
        // On crypte le mot de passe
        String pwdCrypt = cryptPassword(pwd);
        Personnel lePersonnel = new Personnel();

        // On récupère un objet de type Personnel grâce à la fonction de connexion de cette classe
        lePersonnel = this.getUnPersonnel().connexionPersonnel(login, pwdCrypt);

        if (!lePersonnel.getLogin().equals("loginPwdErrone")) {
          if (lePersonnel.getLogin().equals("superAdmin")) {
            ArrayList<Service> lesServices = this.getUnService().rechercherServices();
            request.setAttribute("lesServices", lesServices);
            lien = "/Vue/adminProfils.jsp";
          } else {
            lien = "/Vue/apercuDossiers.jsp";
          }
        } else {
          lien = "/index.jsp?e=loginMdpErrone&login="******"/Vue/creationDossier.jsp?login="******"&pwd=" + pwdCrypt;

        sessionHttp.setAttribute("personnel", lePersonnel);

        // Pour la déconnexion du personnel
        /*} else if (request.getParameter("co").equals("logout")) {
        sessionHttp.removeAttribute("personnel");
        lien = "/index.jsp";*/

        // Déconnexion du personnel
      } else if (request.getParameter("co") != null) {
        if (request.getParameter("co").equals("logout")) {
          sessionHttp.removeAttribute("personnel");

          lien = "/index.jsp";
        }

        // Gestion du menu
      } else if (request.getParameter("page") != null) {
        if (request.getParameter("page").equals("apercuDossiers")) {
          lien = "/Vue/apercuDossiers.jsp";
        }

        // Recherche d'un dossier
      } else if (request.getParameter("recherche_dossier") != null) {
        String recherche = request.getParameter("recherche_dossier");
        ArrayList<Patient> lesPatients = new ArrayList<Patient>();
        lesPatients = this.getUnPatient().rechercherPatients(recherche, 2);
        request.setAttribute("lesPatients", lesPatients);
        request.setAttribute("recherche", recherche);

        lien = "/Vue/apercuDossiers.jsp";

        // Ajout d'un profil de personnel
      } else if (request.getParameter("login_ajout_profil") != null) {
        String nom = StringToMySQL(request.getParameter("nom_ajout_profil").toUpperCase());
        String prenom = StringToMySQL(request.getParameter("prenom_ajout_profil"));
        String login = StringToMySQL(request.getParameter("login_ajout_profil"));
        String pwd = request.getParameter("pwd_ajout_profil");
        String pwdCrypt = cryptPassword(pwd);
        String telDom = request.getParameter("telDom_ajout_profil");
        String telPort = request.getParameter("telPort_ajout_profil");
        String dateNaiss = dateToMySQL(request.getParameter("dateNaiss_ajout_profil"));
        String lieuNaiss = StringToMySQL(request.getParameter("lieuNaiss_ajout_profil"));
        String dateEmbauch = dateToMySQL(request.getParameter("dateEmbauch_ajout_profil"));
        String specMed = request.getParameter("speMed_ajout_profil");
        Boolean adminBool = false;
        if (request.getParameter("affect_ajout_profil").equals("1")) {
          adminBool = true;
        }
        String adresse = StringToMySQL(request.getParameter("adr_ajout_profil"));
        String cp = request.getParameter("cp_ajout_profil");
        String ville = StringToMySQL(request.getParameter("ville_ajout_profil"));
        int idService = Integer.parseInt(request.getParameter("service_ajout_profil"));
        Adresse sonAdresse = new Adresse(0, adresse, cp, ville);
        Service sonService = new Service(idService, "");
        Personnel lePersonnel =
            new Personnel(
                0,
                nom,
                prenom,
                login,
                pwdCrypt,
                telDom,
                telPort,
                dateNaiss,
                lieuNaiss,
                dateEmbauch,
                specMed,
                adminBool,
                sonAdresse,
                sonService);
        this.getUnPersonnel().ajouterPersonnel(lePersonnel);

        lien = "/index.jsp";

        // Lien vers la page de création d'un nouveau dossier
      } else if (request.getParameter("btn_lien_creation_dossier") != null) {
        ArrayList<Service> lesServices = this.getUnService().rechercherServices();
        request.setAttribute("lesServices", lesServices);
        lien = "/Vue/creationDossier.jsp";

        // Lien vers la page de création d'une nouvelle prescription (traitement ou bien
        // intervention chirurgicale)
      } else if (request.getParameter("type_lien_creation_prescription") != null) {
        request.setAttribute("idDossier", request.getParameter("id_dossier"));
        if (request.getParameter("type_lien_creation_prescription").equals("intervention")) {
          lien = "/Vue/creationChirurgie.jsp";
        } else {
          lien = "/Vue/creationPrescription.jsp";
        }

        // Création d'un dossier et d'un patient
      } else if (request.getParameter("nom_ajout_patient") != null) {
        String nom_patient = StringToMySQL(request.getParameter("nom_ajout_patient").toUpperCase());
        String prenom_patient = request.getParameter("prenom_ajout_patient");
        String adr_patient = StringToMySQL(request.getParameter("rue_ajout_patient"));
        String cp_patient = request.getParameter("cp_ajout_patient");
        String ville_patient = StringToMySQL(request.getParameter("ville_ajout_patient"));
        String num_secu_patient =
            request.getParameter("num_secu_ajout_patient")
                + request.getParameter("num_secu2_ajout_patient");
        String complementaire_dossier =
            StringToMySQL(request.getParameter("complementaire_ajout_dossier"));
        String nom_personne_prevenir_dossier =
            StringToMySQL(
                request.getParameter("nom_personne_prevenir_ajout_dossier").toUpperCase());
        String prenom_personne_prevenir_dossier =
            request.getParameter("prenom_personne_prevenir_ajout_dossier");
        String tel_personne_prevenir_dossier =
            request.getParameter("tel_personne_prevenir_ajout_dossier");
        String nom_personne_confiance_dossier =
            StringToMySQL(
                request.getParameter("nom_personne_confiance_ajout_dossier").toUpperCase());
        String prenom_personne_confiance_dossier =
            request.getParameter("prenom_personne_confiance_ajout_dossier");
        String tel_personne_confiance_dossier =
            request.getParameter("tel_personne_confiance_ajout_dossier");
        String medecin_traitant_dossier =
            StringToMySQL(request.getParameter("medecin_traitant_ajout_dossier"));
        String tel_medecin_traitant_dossier =
            request.getParameter("tel_medecin_traitant_ajout_dossier");
        int chambre_patient = Integer.parseInt(request.getParameter("chambre_ajout_patient"));

        Service sonService = new Service(0, "");
        Chambre saChambre = new Chambre(chambre_patient, 0, true, sonService);
        Dossier sonDossier =
            new Dossier(
                0,
                complementaire_dossier,
                nom_personne_prevenir_dossier,
                nom_personne_confiance_dossier,
                medecin_traitant_dossier,
                prenom_personne_prevenir_dossier,
                prenom_personne_confiance_dossier,
                tel_personne_prevenir_dossier,
                tel_personne_confiance_dossier,
                tel_medecin_traitant_dossier,
                false,
                false);
        Adresse sonAdresse = new Adresse(0, adr_patient, cp_patient, ville_patient);
        Patient lePatient =
            new Patient(
                0,
                nom_patient,
                prenom_patient,
                num_secu_patient,
                sonAdresse,
                sonDossier,
                saChambre);
        this.getUnPatient().ajouterPatient(lePatient);

        lien = "/Vue/apercuDossiers.jsp";

        // Lien pour afficher les informations sur un dossier
      } else if (request.getParameter("champ_visualisation_dossier") != null) {
        Personnel lePersonnel = (Personnel) sessionHttp.getAttribute("personnel");
        String idPatient = request.getParameter("champ_visualisation_dossier");
        ArrayList<Patient> lesPatients = new ArrayList<Patient>();
        lesPatients = this.getUnPatient().rechercherPatients(idPatient, 1);
        Patient lePatient = new Patient();
        lePatient = lesPatients.get(0);

        // Si le personnel est administratif
        if (lePersonnel.getAdminBool()) {
          ArrayList<Service> lesServices = this.getUnService().rechercherServices();
          request.setAttribute("lesServices", lesServices);

          ArrayList<Chambre> lesChambres =
              this.getUneChambre()
                  .rechercherChambresLibres(
                      lePatient.getUneChambre().getUnService().getIdService().toString());
          request.setAttribute("lesChambres", lesChambres);

          request.setAttribute("lePatient", lePatient);

          lien = "/Vue/modifDossier.jsp";
          // Si le personnel est un médecin
        } else {
          int idDossier = lePatient.getUnDossier().getId();
          ArrayList<Prescription> lesPrescriptions =
              this.getUnePrescription().rechercherPrescriptions("" + idDossier);
          request.setAttribute("lesPrescriptions", lesPrescriptions);
          String stringIdDossier = "" + idDossier;
          request.setAttribute("idDossier", stringIdDossier);

          lien = "/Vue/apercuPrescriptions.jsp";
        }

        // Modification d'un dossier et d'un patient
      } else if (request.getParameter("nom_modif_patient") != null) {
        String nom_patient = StringToMySQL(request.getParameter("nom_modif_patient").toUpperCase());
        String prenom_patient = request.getParameter("prenom_modif_patient");
        String adr_patient = StringToMySQL(request.getParameter("rue_modif_patient"));
        String cp_patient = request.getParameter("cp_modif_patient");
        String ville_patient = StringToMySQL(request.getParameter("ville_modif_patient"));
        String num_secu_patient =
            request.getParameter("num_secu_modif_patient")
                + request.getParameter("num_secu2_modif_patient");
        String complementaire_dossier =
            StringToMySQL(request.getParameter("complementaire_modif_dossier"));
        String nom_personne_prevenir_dossier =
            StringToMySQL(
                request.getParameter("nom_personne_prevenir_modif_dossier").toUpperCase());
        String prenom_personne_prevenir_dossier =
            request.getParameter("prenom_personne_prevenir_modif_dossier");
        String tel_personne_prevenir_dossier =
            request.getParameter("tel_personne_prevenir_modif_dossier");
        String nom_personne_confiance_dossier =
            StringToMySQL(
                request.getParameter("nom_personne_confiance_modif_dossier").toUpperCase());
        String prenom_personne_confiance_dossier =
            request.getParameter("prenom_personne_confiance_modif_dossier");
        String tel_personne_confiance_dossier =
            request.getParameter("tel_personne_confiance_modif_dossier");
        String medecin_traitant_dossier =
            StringToMySQL(request.getParameter("medecin_traitant_modif_dossier"));
        String tel_medecin_traitant_dossier =
            request.getParameter("tel_medecin_traitant_modif_dossier");
        int chambre_patient = Integer.parseInt(request.getParameter("chambre_modif_patient"));
        int idService = Integer.parseInt(request.getParameter("service"));

        int idPatient = Integer.parseInt(request.getParameter("id_modif_patient"));
        int idDossier = Integer.parseInt(request.getParameter("idDossier_modif_patient"));
        int idAdresse = Integer.parseInt(request.getParameter("idAdresse_modif_patient"));
        String ancienneChambre = request.getParameter("idChambre_modif_patient");

        Service sonService = new Service(idService, "");
        Chambre saChambre = new Chambre(chambre_patient, 0, true, sonService);
        Dossier sonDossier =
            new Dossier(
                idDossier,
                complementaire_dossier,
                nom_personne_prevenir_dossier,
                nom_personne_confiance_dossier,
                medecin_traitant_dossier,
                prenom_personne_prevenir_dossier,
                prenom_personne_confiance_dossier,
                tel_personne_prevenir_dossier,
                tel_personne_confiance_dossier,
                tel_medecin_traitant_dossier,
                false,
                false);
        Adresse sonAdresse = new Adresse(idAdresse, adr_patient, cp_patient, ville_patient);
        Patient lePatient =
            new Patient(
                idPatient,
                nom_patient,
                prenom_patient,
                num_secu_patient,
                sonAdresse,
                sonDossier,
                saChambre);
        this.getUnPatient().modifierPatient(lePatient, ancienneChambre);

        lien = "/Vue/apercuDossiers.jsp";

        // Affichage des informations d'une prescription
      } else if (request.getParameter("champ_visualisation_prescription") != null) {
        String idPrescription = request.getParameter("champ_visualisation_prescription");
        Prescription laPrescription =
            this.getUnePrescription().rechercherUnePrescription(idPrescription);
        request.setAttribute("laPrescription", laPrescription);

        lien = "/Vue/apercuUnePrescription.jsp";

        // Ajout d'une prescription d'un traitement
      } else if (request.getParameter("nom_medecin_ajout_prescription") != null) {
        String idDossier = request.getParameter("id_dossier");

        ArrayList<Medicament> lesMedicaments = new ArrayList<Medicament>();
        Personnel lePersonnel = (Personnel) sessionHttp.getAttribute("personnel");
        String idPersonnel = "" + lePersonnel.getId();

        Enumeration flds = request.getParameterNames();

        while (flds.hasMoreElements()) {
          String element = (String) flds.nextElement();
          String[] tab_med = element.split("medic");
          int length = tab_med.length;
          if (length > 1) {
            int num = Integer.parseInt(tab_med[1]);
            String nom_medic = StringToMySQL(request.getParameter(element));
            String nom_poso = StringToMySQL(request.getParameter("poso" + num));
            Medicament leMedicament = new Medicament(0, nom_medic, nom_poso);
            lesMedicaments.add(leMedicament);
          }
          // String value = request.getParameter(test);*/
        }
        this.getUnePrescription().creerPrescription(lesMedicaments, idPersonnel, idDossier);

        ArrayList<Prescription> lesPrescriptions =
            this.getUnePrescription().rechercherPrescriptions("" + idDossier);
        request.setAttribute("lesPrescriptions", lesPrescriptions);
        String stringIdDossier = "" + idDossier;
        request.setAttribute("idDossier", stringIdDossier);

        lien = "/Vue/apercuPrescriptions.jsp";

        // Ajout d'une intervention chirurgicale
      } else if (request.getParameter("nom_medecin_ajout_intervention") != null) {
        String idDossier = request.getParameter("id_dossier");

        Personnel lePersonnel = (Personnel) sessionHttp.getAttribute("personnel");
        String idPersonnel = "" + lePersonnel.getId();

        InterChirurgicale lInterChirurgicale =
            new InterChirurgicale(
                0,
                StringToMySQL(request.getParameter("type_creation_inter")),
                StringToMySQL(request.getParameter("remarque_creation_inter")));

        this.getUnePrescription()
            .creerInterChirurgicale(lInterChirurgicale, idPersonnel, idDossier);

        ArrayList<Prescription> lesPrescriptions =
            this.getUnePrescription().rechercherPrescriptions("" + idDossier);
        request.setAttribute("lesPrescriptions", lesPrescriptions);
        String stringIdDossier = "" + idDossier;
        request.setAttribute("idDossier", stringIdDossier);

        lien = "/Vue/apercuPrescriptions.jsp";

        // Gestion de la sortie des patients
      } else if (request.getParameter("champ_sortie_id_patient") != null) {
        // Si c'est pour la sortie du patient
        if (request.getParameter("champ_sortie_patient_type").equals("sortie")) {
          // Si c'est un médecin
          if (request.getParameter("champ_sortie_patient_type_personnel").equals("Medecin")) {
            // On autorise la sortie
            this.getUnDossier().autoriserSortie(request.getParameter("champ_sortie_id_patient"));
          } else {
            // On enregistre la sortie
            this.getUnDossier().enregistrerSortie(request.getParameter("champ_sortie_id_patient"));
          }

          lien = "/Vue/apercuDossiers.jsp";

          // Si c'est pour l'admission du patient
        } else {
          String idPatient = request.getParameter("champ_sortie_id_patient");
          ArrayList<Patient> lesPatients = new ArrayList<Patient>();
          lesPatients = this.getUnPatient().rechercherPatients(idPatient, 1);
          Patient lePatient = new Patient();
          lePatient = lesPatients.get(0);

          ArrayList<Service> lesServices = this.getUnService().rechercherServices();
          request.setAttribute("lesServices", lesServices);

          ArrayList<Chambre> lesChambres =
              this.getUneChambre()
                  .rechercherChambresLibres(
                      lePatient.getUneChambre().getUnService().getIdService().toString());
          request.setAttribute("lesChambres", lesChambres);

          request.setAttribute("lePatient", lePatient);

          lien = "/Vue/modifDossier.jsp";
        }

      } else {
        lien = "/index.jsp";
      }
      getServletContext().getRequestDispatcher(lien).forward(request, response);
    } finally {
      out.close();
    }
  }