Example usage for javax.servlet.http HttpServletRequest getParameter

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

Introduction

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

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:com.bluepandora.therap.donatelife.service.DonationService.java

public static void addDonationRecord(HttpServletRequest request, HttpServletResponse response)
        throws JSONException {
    DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD);
    dbService.databaseOpen();// w  ww. j  av  a2s.co m

    String requestName = request.getParameter("requestName");
    JSONObject jsonObject = null;

    if (request.getParameter("mobileNumber") != null && request.getParameter("donationDate") != null
            && request.getParameter("donationDetail") != null) {

        String mobileNumber = request.getParameter("mobileNumber");
        String donationDate = request.getParameter("donationDate");
        String donationDetail = request.getParameter("donationDetail");

        Debug.debugLog("MobileNumber: ", mobileNumber, "Date: ", donationDate, "Details: ", donationDetail);

        if (DataValidation.isValidMobileNumber(mobileNumber) && DataValidation.isValidString(donationDate)
                && DataValidation.isValidString(donationDetail)) {
            String query = GetQuery.addDonationRecordQuery(mobileNumber, donationDate, donationDetail);
            //    Debug.debugLog("Add Donation Record Query: ", query);
            boolean done = dbService.queryExcute(query);
            if (done) {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.CORRECT, Enum.MESSAGE_DONATION_ADDED,
                        requestName);
                Debug.debugLog("MOBILE NUMBER: ", mobileNumber, " ADD DONATION SUCCESS");
            } else {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_ERROR, requestName);
            }
        } else {
            jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_INVALID_VALUE, requestName);
        }
    } else {
        jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_LESS_PARAMETER, requestName);
    }
    SendJsonData.sendJsonData(request, response, jsonObject);
    dbService.databaseClose();
}

From source file:edu.stanford.muse.webapp.Accounts.java

/** adds alternateEmailAddrs if specified in the request to the session. alternateEmailAddrs are simply appended to. */
public static void updateUserInfo(HttpServletRequest request) {
    HttpSession session = request.getSession();

    String ownerName = request.getParameter("name");
    if (!Util.nullOrEmpty(ownerName))
        session.setAttribute("ownerName", ownerName);

    String archiveTitle = request.getParameter("archiveTitle");
    if (!Util.nullOrEmpty(archiveTitle))
        session.setAttribute("archiveTitle", archiveTitle);

    String alt = request.getParameter("alternateEmailAddrs");
    if (Util.nullOrEmpty(alt))
        return;// w  w w .j  av a  2  s . com

    String sessionAlt = (String) JSPHelper.getSessionAttribute(session, "alternateEmailAddrs");
    if (Util.nullOrEmpty(sessionAlt))
        session.setAttribute("alternateEmailAddrs", alt); // this will be removed when we fetch and index email
    else
        session.setAttribute("alternateEmailAddrs", sessionAlt + " " + alt);
    // could also uniquify the emailAddrs here
}

From source file:azkaban.server.HttpRequestUtils.java

/**
 * Retrieves the param from the http servlet request. Will throw an exception
 * if not found//  w ww .  j  a  v  a2s.  c o m
 *
 * @param request
 * @param name
 * @return
 * @throws ServletException
 */
public static String getParam(HttpServletRequest request, String name) throws ServletException {
    String p = request.getParameter(name);
    if (p == null) {
        throw new ServletException("Missing required parameter '" + name + "'.");
    } else {
        return p;
    }
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java

protected static void editarUsuario(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println(request.getParameter("5"));
    ArrayList r = CtrlAdmin.editarUsuario(Integer.parseInt(request.getParameter("0")), //IdUsuario
            request.getParameter("1"), //Nombre
            request.getParameter("2"), //Apellidos
            request.getParameter("3"), //Tipo de documento
            request.getParameter("4"), //documento
            request.getParameter("5"), //Correo= usuario
            request.getParameter("6"), //passworld
            request.getParameter("7").charAt(0)//rol
    );// w ww. ja  va  2s . c om

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    if (r.get(0) == "error") {
        obj.put("isError", true);
        boolean errorSerio = false;
        if (r.get(1) == "usuario") {
            obj.put("errorDescrip", "El usuario ya existe");
        } else if (r.get(1) == "contrasena") {
            obj.put("errorDescrip", "La contrasea es invalida");
        } else if (r.get(1) == "documento") {
            obj.put("errorDescrip", "El documento ya est registrado");
        } else if (r.get(1) == "tipoDocumento") {
            obj.put("errorDescrip", "El tipo de documento es invalido");
        } else if (r.get(1) == "correo") {
            obj.put("errorDescrip", "El correo ya est registrado");
        } else if (r.get(1) == "correo1") {
            obj.put("errorDescrip", "El correo no es valido");
        } else if (r.get(1) == "nombre") {
            obj.put("errorDescrip", "Los nombres o apellidos son incorrectos");
        } else if (r.get(1) == "rol") {
            obj.put("errorDescrip", "El rol es invalido, los posibles valores son: E, P y A");
        } else {
            Util.errordeRespuesta(r, out);
            errorSerio = true;
        }
        if (!errorSerio) {
            out.print(obj);
        }
    } else if (r.get(0) == "isExitoso") {
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:com.ibm.sbt.sample.web.util.SnippetFactory.java

private static String getJsLibId(HttpServletRequest request) {
    if (request.getParameter("jsLibId") != null)
        return request.getParameter("jsLibId");
    else//from   w  ww  . j ava  2 s.c om
        return null;
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void crearTaller(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ArrayList r = CtrlAdmin.crearTaller(request.getParameter("1"), // nombre
            request.getParameter("2"), // descripcin
            request.getParameter("4"), // fin registro (Fecha hasta donde est permitido registrarse)
            request.getParameter("3"), // inicio del taller
            request.getParameter("4"), // fin del taller
            Integer.parseInt(request.getParameter("5")), // costo
            Integer.parseInt(request.getParameter("6")) // cupos
    );/*from  w  ww.  j  ava  2s. c  o m*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java

protected static void crearUsuario(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println(request.getParameter("5"));
    ArrayList r = CtrlAdmin.crearUsuario(request.getParameter("1"), //Nombre
            request.getParameter("2"), //Apellidos
            request.getParameter("3"), //Tipo de documento
            request.getParameter("4"), //documento
            request.getParameter("5"), //Correo= usuario
            request.getParameter("6"), //passworld
            request.getParameter("7").charAt(0)//rol
    );/*from  w w  w. java 2  s .c  om*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        if (r.get(1) == "usuario") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El usuario ya existe");
        } else if (r.get(1) == "contrasena") {
            obj.put("isError", true);
            obj.put("errorDescrip", "La contrasea es invalida");
        } else if (r.get(1) == "documento") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El documento ya est registrado");
        } else if (r.get(1) == "tipoDocumento") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El tipo de documento es invalido");
        } else if (r.get(1) == "correo") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El correo ya est registrado");
        } else if (r.get(1) == "correo1") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El correo no es valido");
        } else if (r.get(1) == "nombre") {
            obj.put("isError", true);
            obj.put("errorDescrip", "Los nombres o apellidos son incorrectos");
        } else if (r.get(1) == "rol") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El rol es invalido, los posibles valores son: E, P y A");
        } else
            Util.errordeRespuesta(r, out);
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:com.nexmo.security.RequestSigning.java

/**
 * looks at the current http request and verifies that the request signature, if supplied is valid.
 *
 * @param request The servlet request object to be verified
 * @param secretKey the pre-shared secret key used by the sender of the request to create the signature
 *
 * @return boolean returns true only if the signature is correct for this request and secret key.
 *///from   w  ww  .  j av  a 2s.c o  m
public static boolean verifyRequestSignature(HttpServletRequest request, String secretKey) {
    // identify the signature supplied in the request ...
    String suppliedSignature = request.getParameter(PARAM_SIGNATURE);
    if (suppliedSignature == null)
        return false;

    // Firstly, extract the timestamp parameter and verify that it is within 5 minutes of 'current time'
    String timeString = request.getParameter(PARAM_TIMESTAMP);
    long time = -1;
    try {
        if (timeString != null)
            time = Long.parseLong(timeString) * 1000;
    } catch (NumberFormatException e) {
        log.debug("Error parsing 'time' parameter [ " + timeString + " ]", e);
        time = 0;
    }
    long diff = System.currentTimeMillis() - time;
    if (diff > MAX_ALLOWABLE_TIME_DELTA || diff < -MAX_ALLOWABLE_TIME_DELTA) {
        log.warn("SECURITY-KEY-VERIFICATION -- BAD-TIMESTAMP ... Timestamp [ " + time + " ] delta [ " + diff
                + " ] max allowed delta [ " + -MAX_ALLOWABLE_TIME_DELTA + " ] ");
        return false;
    }

    // Next, construct a sorted list of the name-value pair parameters supplied in the request, excluding the signature parameter
    Map<String, String> sortedParams = new TreeMap<>();
    for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue()[0];
        if (name.equals(PARAM_SIGNATURE))
            continue;
        if (value == null || value.trim().equals(""))
            continue;
        sortedParams.put(name, value);
    }

    // walk this sorted list of parameters and construct a string
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, String> param : sortedParams.entrySet()) {
        String name = param.getKey();
        String value = param.getValue();
        sb.append("&").append(clean(name)).append("=").append(clean(value));
    }

    // append the secret key and calculate an md5 signature of the resultant string
    sb.append(secretKey);

    String str = sb.toString();

    String md5 = "no signature";
    try {
        md5 = MD5Util.calculateMd5(str);
    } catch (Exception e) {
        log.error("error...", e);
        return false;
    }

    log.info("SECURITY-KEY-VERIFICATION -- String [ " + str + " ] Signature [ " + md5
            + " ] SUPPLIED SIGNATURE [ " + suppliedSignature + " ] ");

    // verify that the supplied signature matches generated one
    // use MessageDigest.isEqual as an alternative to String.equals() to defend against timing based attacks
    try {
        if (!MessageDigest.isEqual(md5.getBytes("UTF-8"), suppliedSignature.getBytes("UTF-8")))
            return false;
    } catch (UnsupportedEncodingException e) {
        log.error("This should not occur!!", e);
        return false;
    }

    return true;
}

From source file:net.cristcost.study.services.ServiceTestUtil.java

private static SecurityContext authenticate(PrintWriter writer, HttpServletRequest request,
        AuthenticationManager authenticationManager) {

    SecurityContext initialContext = SecurityContextHolder.getContext();

    if (request.getParameter("user") != null) {

        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
                request.getParameter("user"), request.getParameter("pass"));
        try {/* ww  w .  j  a  v a 2 s  .co m*/
            Authentication authentication = authenticationManager.authenticate(authRequest);
            SecurityContextHolder.setContext(SecurityContextHolder.createEmptyContext());
            SecurityContextHolder.getContext().setAuthentication(authentication);
            writer.println("Authenticating user: " + request.getParameter("user"));
        } catch (AuthenticationException e) {
            writer.println("! Error while Authenticating: " + e.getMessage());
        }
        writer.println();
    }

    return initialContext;
}

From source file:org.apache.atlas.web.util.Servlets.java

/**
 * Returns the user of the given request.
 *
 * @param httpRequest    an HTTP servlet request
 * @return the user//from www .j  a va2s . c o m
 */
public static String getUserFromRequest(HttpServletRequest httpRequest) {
    String user = httpRequest.getRemoteUser();
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    user = httpRequest.getParameter("user.name"); // available in query-param
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    user = httpRequest.getHeader("Remote-User"); // backwards-compatibility
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    user = getDoAsUser(httpRequest);
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    return null;
}