Example usage for javax.servlet.http HttpServletRequest getParameterMap

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

Introduction

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

Prototype

public Map<String, String[]> getParameterMap();

Source Link

Document

Returns a java.util.Map of the parameters of this request.

Usage

From source file:ProductServlet.java

protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Set<String> keySet = request.getParameterMap().keySet();
    try (PrintWriter out = response.getWriter()) {
        Connection conn = getConnection();
        if (keySet.contains("productID") && keySet.contains("name") && keySet.contains("description")
                && keySet.contains("quantity")) {
            PreparedStatement pstmt = conn.prepareStatement("UPDATE `product` SET `name`='"
                    + request.getParameter("name") + "',`description`='" + request.getParameter("description")
                    + "',`quantity`=" + request.getParameter("quantity") + " WHERE `productID`="
                    + request.getParameter("productID"));
            try {
                pstmt.executeUpdate();/*from  www. ja  v  a  2 s . c  om*/
                doGet(request, response); //shows updated row
            } catch (SQLException ex) {
                Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
                out.println("Error updating values.");
                response.setStatus(500);
            }
        } else {
            out.println("Error: Not enough data to update");
            response.setStatus(500);
        }
    } catch (SQLException ex) {
        Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:classes.Product.java

@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response) {

    Set<String> keySet = request.getParameterMap().keySet();

    try (PrintWriter printer = response.getWriter()) {
        if (keySet.contains("ProductId") && keySet.contains("productName")
                && keySet.contains("productDescription") && keySet.contains("productQuantity")) {

            String productId = request.getParameter("productId");
            String productName = request.getParameter("productName");
            String productDescription = request.getParameter("productDescription");
            String productQuantity = request.getParameter("productQuantity");

            doUpdate(/*from   w  ww . j a v a2  s .c  o  m*/
                    "update products" + " set Product_id = ?," + " product_name = ?, "
                            + "product_description = ?, " + "product_quantity = ? " + "where product_id = ?",
                    productId, productName, productDescription, productQuantity, productId);
        } else {
            printer.println("No matching data found..");
        }
    } catch (IOException ex) {
        System.out.println("IO exception" + ex.getMessage());

    }
}

From source file:net.groupbuy.plugin.tenpayBank.TenpayBankPlugin.java

@SuppressWarnings("unchecked")
@Override/*from  ww w.  j a  v a  2 s  .  c  o  m*/
public boolean verifyNotify(String sn, NotifyMethod notifyMethod, HttpServletRequest request) {
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);
    if (generateSign(request.getParameterMap()).equals(request.getParameter("sign"))
            && pluginConfig.getAttribute("partner").equals(request.getParameter("partner"))
            && sn.equals(request.getParameter("out_trade_no"))
            && "0".equals(request.getParameter("trade_state"))
            && payment.getAmount().multiply(new BigDecimal(100))
                    .compareTo(new BigDecimal(request.getParameter("total_fee"))) == 0) {
        try {
            Map<String, Object> parameterMap = new HashMap<String, Object>();
            parameterMap.put("input_charset", "utf-8");
            parameterMap.put("sign_type", "MD5");
            parameterMap.put("partner", pluginConfig.getAttribute("partner"));
            parameterMap.put("notify_id", request.getParameter("notify_id"));
            String verifyUrl = "https://gw.tenpay.com/gateway/simpleverifynotifyid.xml?input_charset=utf-8&sign_type=MD5&partner="
                    + pluginConfig.getAttribute("partner") + "&notify_id=" + request.getParameter("notify_id")
                    + "&sign=" + generateSign(parameterMap);
            Document document = new SAXReader().read(new URL(verifyUrl));
            Node node = document.selectSingleNode("/root/retcode");
            if ("0".equals(node.getText().trim())) {
                return true;
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    return false;
}

From source file:net.seedboxer.web.security.AuthenticationAPIKeyFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    @SuppressWarnings("unchecked")
    Map<String, String[]> parms = request.getParameterMap();

    if (parms.containsKey(APIKEY_PARAM)) {
        String apikey = parms.get(APIKEY_PARAM)[0];

        if (Token.validate(apikey)) {
            try {

                UserDetails userDetails = seedboxerUDS.loadUserByAPIKey(apikey);
                Authentication authentication = createSuccessfulAuthentication(request, userDetails);
                SecurityContextHolder.getContext().setAuthentication(authentication);

            } catch (UsernameNotFoundException notFound) {
                fail(request, response,//from   ww w  . java 2  s.  c om
                        new BadCredentialsException(
                                messages.getMessage("DigestAuthenticationFilter.usernameNotFound",
                                        new Object[] { apikey }, "User with APIKey {0} not found")));

                return;
            }
        } else {
            fail(request, response,
                    new BadCredentialsException(
                            messages.getMessage("DigestAuthenticationFilter.usernameNotFound",
                                    new Object[] { apikey }, "Invalid APIKey {0}")));

            return;
        }
    }
    chain.doFilter(request, response);
}

From source file:ProductServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Set<String> keySet = request.getParameterMap().keySet();
    try (PrintWriter out = response.getWriter()) {
        Connection conn = getConnection();
        if (keySet.contains("name") && keySet.contains("description") && keySet.contains("quantity")) {
            PreparedStatement pstmt = conn
                    .prepareStatement("INSERT INTO `product`(`productID`, `name`, `description`, `quantity`) "
                            + "VALUES (" + "null, '" + request.getParameter("name") + "', '"
                            + request.getParameter("description") + "', " + request.getParameter("quantity")
                            + ");");
            try {
                pstmt.executeUpdate();//w  w w. j a v a  2 s.c o  m
                request.setAttribute("productID", 2);
                request.getParameter("productID");
                doGet(request, response); //shows updated row
            } catch (SQLException ex) {
                Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
                out.println("Error with inserting values.");
                response.setStatus(500);
            }
        } else {
            out.println("Error: Not enough data to input");
            response.setStatus(500);
        }
    } catch (SQLException ex) {
        Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.cloudfoundry.identity.uaa.authentication.ClientParametersAuthenticationFilter.java

private Map<String, String> getSingleValueMap(HttpServletRequest request) {
    Map<String, String> map = new HashMap<String, String>();
    @SuppressWarnings("unchecked")
    Map<String, String[]> parameters = request.getParameterMap();
    for (String key : parameters.keySet()) {
        String[] values = parameters.get(key);
        map.put(key, values != null && values.length > 0 ? values[0] : null);
    }// w w w.  j a  v a 2 s.co  m
    return map;
}

From source file:com.carlos.projects.billing.ui.controllers.SelectComponentsController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ModelAndView mav = super.handleRequestInternal(request, response);
    mav.getModelMap().addAttribute("components",
            getComponents((Map<String, String[]>) request.getParameterMap()));
    mav.getModelMap().addAttribute("familyName", request.getParameter("familyName"));

    String documentId = request.getParameter("documentId");
    if (!isEmpty(documentId) && isNumeric(documentId)) {
        mav.getModelMap().addAttribute("documentId", Long.parseLong(documentId));
    }/* w w  w  .  j  a v  a2s.c o  m*/
    return mav;
}

From source file:is.idega.idegaweb.egov.application.servlet.filter.ApplicationUrlRedirector.java

private boolean getIfDoRedirect(HttpServletRequest request) {
    @SuppressWarnings("rawtypes")
    Map map = request.getParameterMap();
    return map.containsKey(ApplicationBlock.PARAMETER_APPLICATION_PK);
}

From source file:mecha.http.servlets.ProxyServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*from w  w w .  jav  a2  s.c om*/
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Access-Control-Allow-Origin", "*");

        Map<String, String[]> requestParamMap = request.getParameterMap();
        String u = requestParamMap.get("u")[0];
        response.getWriter().print(HTTPUtils.fetch(u));
    } catch (Exception ex) {
        Mecha.getMonitoring().error("mecha.http.servlets.macro-servlet", ex);
        ex.printStackTrace();
    }
}

From source file:com.neurologic.oauth.service.impl.OAuth2Service.java

@Override
public final void execute(HttpServletRequest request, HttpServletResponse response) throws OAuthException {
    // TODO Auto-generated method stub
    Map<String, String> parameterMap = extractParameterMap(request.getParameterMap());

    if (parameterMap.containsKey("error")) {
        throwOAuthErrorException(parameterMap);
    }//from  www.j av  a 2 s .  c om

    //Process when we received "code" from request parameter.
    if (parameterMap.containsKey(ResponseType.CODE.toString())) {
        if (logger.isDebugEnabled()) {
            logger.debug("\"" + ResponseType.CODE.toString() + "\" received.");
        }

        String code = parameterMap.remove(ResponseType.CODE.toString());
        String accessTokenUrl = processReceivedAuthorization(request, code, parameterMap);
        try {
            if (accessTokenUrl != null && !accessTokenUrl.isEmpty()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Redirecting to \"" + accessTokenUrl + "\".");
                }
                response.sendRedirect(accessTokenUrl);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            throw new OAuthException(e);
        }
    }

    //Process when we received "access_token" from request parameter.
    if (parameterMap.containsKey(OAuth2Parameters.ACCESS_TOKEN)) {
        if (logger.isDebugEnabled()) {
            logger.debug("\"" + OAuth2Parameters.ACCESS_TOKEN + "\" received.");
        }
        String accessToken = parameterMap.remove(OAuth2Parameters.ACCESS_TOKEN);
        request.getSession().setAttribute(Globals.SESSION_OAUTH2_ACCESS_TOKEN, accessToken);
        processAdditionalReceivedAccessTokenParameters(request, parameterMap);

        if (logger.isInfoEnabled()) {
            logger.info("Access Token stored under \"" + Globals.SESSION_OAUTH2_ACCESS_TOKEN + "\" key.");
        }
    }
}