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:com.commerce4j.storefront.controllers.CartController.java

@SuppressWarnings("unchecked")
public void update(HttpServletRequest request, HttpServletResponse response) {

    Gson gson = new GsonBuilder().create();
    List<Message> errors = new ArrayList<Message>();
    Map<String, Object> responseModel = new HashMap<String, Object>();

    List<CartDTO> cartEntries = getCart(request);
    Iterator inputSet = request.getParameterMap().keySet().iterator();
    while (inputSet.hasNext()) {
        String paramName = (String) inputSet.next();
        if (StringUtils.contains(paramName, "qty")) {
            String paramValue = request.getParameter(paramName);
            String paramId = StringUtils.substring(paramName, 4, paramName.length());
            if (paramId != null && StringUtils.isNumeric(paramId)) {
                for (CartDTO cartEntry : cartEntries) {
                    int entryId = cartEntry.getItem().getItemId().intValue();
                    int itemId = new Integer(paramId).intValue();
                    int cartQuantity = new Integer(paramValue).intValue();
                    if (entryId == itemId) {
                        cartEntry.setCartQuantity(cartQuantity);
                        cartEntry.setCartSubTotal(cartEntry.getItem().getItemPrice() * cartQuantity);
                        break;
                    }/*from   w  ww  . ja v  a2  s. co m*/
                }
            }
        }
    }

    // fill response model
    if (errors.isEmpty()) {
        responseModel.put("responseCode", SUCCESS);
        responseModel.put("responseMessage", "Cart succesfully updated");
    } else {
        responseModel.put("responseCode", FAILURE);
        responseModel.put("responseMessage", "Error, Cart was not updated");
        responseModel.put("errors", errors);
    }

    // serialize output
    try {
        response.setContentType("application/json");
        OutputStreamWriter os = new OutputStreamWriter(response.getOutputStream());
        String data = gson.toJson(responseModel);
        os.write(data);
        os.flush();
        os.close();
    } catch (IOException e) {
        logger.fatal(e);
    }

}

From source file:info.magnolia.voting.voters.RequestHasParametersVoter.java

@Override
protected boolean boolVote(Object value) {
    HttpServletRequest request;
    if (value instanceof HttpServletRequest) {
        request = (HttpServletRequest) value;
    } else {//ww  w  .j ava2s .  c o m
        if (MgnlContext.isWebContext()) {
            request = MgnlContext.getWebContext().getRequest();
        } else {
            return false;
        }
    }
    if (StringUtils.equalsIgnoreCase(request.getMethod(), "POST")) {
        return true;
    }

    if (!request.getParameterMap().isEmpty()) {
        return true;
    }

    return false;
}

From source file:com.cnnic.whois.controller.oauth.EchoController.java

/**
 * access query api/*from   w w w  . ja va  2 s  .  c o m*/
 * @param accessToken
 * @param request
 * @param response
 * @throws Exception
 */
private void accessApi(String accessToken, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    OAuthAccessorBean oauthAccessorBean = oauthAccessorDao.getOAuthAccessorBeanByAccessToken(accessToken);
    AuthenticationHolder.setAuthentication(new Authentication(oauthAccessorBean.getOauth_user_role()));

    for (Object item : request.getParameterMap().entrySet()) {
        Map.Entry parameter = (Map.Entry) item;
        String[] values = (String[]) parameter.getValue();
        for (String value : values) {

            if (value.equals("ip")) {

                String net = "0";
                String ip = StringUtils.trim("1.1.1.1");

                Map<String, Object> resultMap = null;
                IpQueryParam queryParam = super.praseIpQueryParams(request);
                String strInfo = ip;
                if (!ValidateUtils.verifyIP(strInfo, net)) {
                    resultMap = WhoisUtil.processError(WhoisUtil.COMMENDRRORCODE, queryParam);
                    viewResolver.writeResponse(queryParam.getFormat(), queryParam.getQueryType(), request,
                            response, resultMap);
                    return;
                }
                queryParam.setQ(ip);
                queryParam.setIpInfo(strInfo);
                queryParam.setIpLength(Integer.parseInt(net));
                resultMap = queryService.queryIP(queryParam);
                request.setAttribute("queryPara", ip);
                request.setAttribute("queryType", "ip");
                viewResolver.writeResponse(queryParam.getFormat(), queryParam.getQueryType(), request, response,
                        resultMap);
            }
            if (value.equals("domain")) {
                String domainName = StringUtils.trim("z.cn");
                String queryParaPuny = IDN.toASCII(domainName);
                Map<String, Object> resultMap = null;
                QueryParam queryParam = super.praseQueryParams(request);
                if (!ValidateUtils.validateDomainNameIsValidIdna(queryParaPuny)) {
                    resultMap = WhoisUtil.processError(WhoisUtil.COMMENDRRORCODE, queryParam);
                } else {
                    queryParam.setQ(domainName);
                    resultMap = queryService.queryDomain(queryParam);
                    System.err.println(resultMap);
                }
                viewResolver.writeResponse(queryParam.getFormat(), queryParam.getQueryType(), request, response,
                        resultMap);
            }
            if (value.equals("entity")) {
                EntityQueryParam queryParam = super.praseEntityQueryParams(request);
                queryParam.setQ("IBM-1");
                Map<String, Object> resultMap = queryService.queryEntity(queryParam);
                request.setAttribute("queryType", "entity");
                request.setAttribute("queryPara", "IBM-1");
                renderResponse(request, response, resultMap, queryParam);
            }
        }
    }
}

From source file:com.infinity.controller.ClientsController.java

@RequestMapping(value = {
        "/client/job/criteria/techno/update/{offerId}/{clienId}" }, method = RequestMethod.POST)
public String UpdateCriteriaTechnoList(HttpServletRequest request, HttpServletResponse httpServletResponse,
        @PathVariable String offerId) throws IOException, InterruptedException, ExecutionException {

    Map<String, String[]> parameterMap = request.getParameterMap();
    ArrayList<TechnoCriteria> technoList = new ArrayList<>();

    for (int i = 0; i < parameterMap.size(); i++) {
        TechnoCriteria technoCriteria = new TechnoCriteria();

        if (parameterMap.containsKey("technoName-" + i)) {

            technoCriteria.setTechnoName(parameterMap.get("technoName-" + i)[0]);

        }//from w  ww .  j  av  a 2 s . c  om
        if (parameterMap.containsKey("expDurationStart-" + i)) {

            technoCriteria.setExpDurationStart(Integer.valueOf(parameterMap.get("expDurationStart-" + i)[0]));

        }
        if (parameterMap.containsKey("expDurationEnd-" + i)) {

            technoCriteria.setExpDurationEnd(Integer.valueOf(parameterMap.get("expDurationEnd-" + i)[0]));

        }
        if (technoCriteria.getTechnoName() != null) {
            technoList.add(technoCriteria);
        }

    }
    ClientOffers fromDb = clientsJobsService.getById(offerId);
    fromDb.setTechnoCriterias(technoList);
    clientsJobsService.updateOneById(fromDb);

    return "redirect:/client/job/update/{offerId}/{clienId}";
}

From source file:com.pliu.azuremgmtsdk.BasicFilter.java

private void processAuthenticationData(HttpServletRequest httpRequest, String currentUri, String fullUrl)
        throws Throwable {
    Map<String, String> params = new HashMap();
    for (String key : httpRequest.getParameterMap().keySet()) {
        params.put(key, httpRequest.getParameterMap().get(key)[0]);
    }//from w w  w.ja v  a 2s .  co m
    // validate that state in response equals to state in request
    StateData stateData = validateState(httpRequest.getSession(), params.get(STATE));

    AuthenticationResponse authResponse = AuthenticationResponseParser.parse(new URI(fullUrl), params);
    if (AuthHelper.isAuthenticationSuccessful(authResponse)) {
        AuthenticationSuccessResponse oidcResponse = (AuthenticationSuccessResponse) authResponse;
        // validate that OIDC Auth Response matches Code Flow (contains only requested artifacts)
        validateAuthRespMatchesCodeFlow(oidcResponse);

        userTenant = httpRequest.getSession().getAttribute("userTenant").toString();
        AuthenticationResult authData = getAccessToken(oidcResponse.getAuthorizationCode(), currentUri);
        // validate nonce to prevent reply attacks (code maybe substituted to one with broader access)
        validateNonce(stateData, getClaimValueFromIdToken(authData.getIdToken(), "nonce"));

        setSessionPrincipal(httpRequest, authData);
    } else {
        AuthenticationErrorResponse oidcResponse = (AuthenticationErrorResponse) authResponse;
        throw new Exception(String.format("Request for auth code failed: %s - %s",
                oidcResponse.getErrorObject().getCode(), oidcResponse.getErrorObject().getDescription()));
    }
}

From source file:dbaccess.servlets.ModifyServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  www.  j a v  a 2 s  .  c om
 *
 * @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 {

    // extract request parameters to a book data bean using
    // apache BeanUtils
    BookData bookData = new BookData();
    try {
        BeanUtils.populate(bookData, request.getParameterMap());
        String nextPage = null;

        // set up the bean as request parameter
        request.setAttribute("bookData", bookData);

        // ADD A BOOK
        if (request.getParameter("add") != null) {
            if (bookData.isComplete()) {
                if (DBHelper.addBook(em, utx, bookData)) {
                    nextPage = "/index.jsp";
                } else {
                    nextPage = "/failedAdd.jsp";
                }
            } else {
                nextPage = "/failedAdd.jsp";
            }
        }
        // DELETE A BOOK
        else if (request.getParameter("delete") != null) {
            if (DBHelper.deleteBook(em, utx, bookData)) {
                nextPage = "/index.jsp";
            } else {
                nextPage = "/failedDelete.jsp";
            }

        }
        // GO TO KIDS PAGE
        else if (request.getParameter("kidspage") != null) {
            if (DBHelper.getAllKidsBookIDS(em) != null) {
                nextPage = "/KidsBooksPage";
            } else {
                nextPage = "/emptyDatabaseError.jsp";
            }
        }

        // GO TO TECH PAGE
        else if (request.getParameter("techpage") != null) {
            if (DBHelper.getAllTechBookIDS(em) != null) {
                nextPage = "/TechBooksPage";
            } else {
                nextPage = "/emptyDatabaseError.jsp";
            }
        }

        // SHOW RESULTS in table, if any
        fillTable(em, request, nextPage);

        RequestDispatcher dispatcher = request.getRequestDispatcher(nextPage);
        dispatcher.forward(request, response);
    } catch (IllegalAccessException | InvocationTargetException | ServletException | IOException ex) {
    }

}

From source file:com.formkiq.core.api.FolderFilesController.java

/**
 * Folder File Ledger.//from w  w  w  . j a  va 2s . com
 * @param request {@link HttpServletRequest}
 * @return {@link FolderFormsListDTO}
 * @throws MissingServletRequestParameterException Exception
 */
@Transactional
@RequestMapping(value = API_FOLDER_FILE_LEDGER, method = GET)
public FolderFormLedgerListDTO fileledger(final HttpServletRequest request)
        throws MissingServletRequestParameterException {

    Map<String, String[]> map = request.getParameterMap();

    String folder = getParameter(map, "folder", true);
    String uuid = getParameter(map, "uuid", true);

    return this.folderService.findFormLedger(folder, uuid);
}

From source file:edu.cornell.kfs.sys.web.controller.DataObjectRestServiceController.java

protected List<? extends BusinessObject> getSearchResults(HttpServletRequest request,
        FinancialSystemBusinessObjectEntry boe) {
    Map<String, String> fieldValues = new HashMap<String, String>();
    for (Object o : request.getParameterMap().keySet()) {
        String[] value = (String[]) request.getParameterMap().get(o);
        fieldValues.put(o.toString(), value[0]);
    }/*from w  w  w .ja  v a  2  s  .c om*/

    LookupableHelperService lookupableHelperService = getLookupableHelperService(
            boe.getLookupDefinition().getLookupableID());
    lookupableHelperService.setBusinessObjectClass(boe.getBusinessObjectClass());

    String limitByParameter = fieldValues.remove(LIMIT_BY_PARAMETER);
    String maxObjectsToReturn = fieldValues.remove(MAX_OBJECTS_TO_RETURN);

    List<? extends BusinessObject> searchResults;
    if (StringUtils.isEmpty(limitByParameter) || limitByParameter.equalsIgnoreCase("Y")) {
        searchResults = lookupableHelperService.getSearchResults(fieldValues);
    } else {
        try {
            searchResults = lookupableHelperService.getSearchResultsUnbounded(fieldValues);
        } catch (UnsupportedOperationException e) {
            LOG.warn(
                    "lookupableHelperService.getSearchResultsUnbounded failed. Retrying the lookup using the default search.",
                    e);
            searchResults = lookupableHelperService.getSearchResults(fieldValues);
        }
    }

    if (StringUtils.isNotEmpty(maxObjectsToReturn)) {
        int searchLimit = Integer.parseInt(maxObjectsToReturn);
        if (searchLimit > 0) {
            return searchResults.subList(0, Math.min(searchResults.size(), searchLimit));
        }
    }

    return searchResults;
}

From source file:net.nan21.dnet.core.web.controller.AbstractDnetController.java

/**
 * Collect parameters from request.//from   w  w  w . j  a  v  a  2  s  .c o  m
 * 
 * ATTENTION!: Only the first value is considered.
 * 
 * @param request
 * @param prefix
 *            Collect only parameters which start with this prefix
 * @param suffix
 *            Collect only parameters which ends with this suffix
 * @return
 */
protected Map<String, String> collectParams(HttpServletRequest request, String prefix, String suffix) {
    @SuppressWarnings("unchecked")
    Map<String, String[]> paramMap = (Map<String, String[]>) request.getParameterMap();
    Map<String, String> result = new HashMap<String, String>();
    for (Map.Entry<String, String[]> e : paramMap.entrySet()) {
        String k = e.getKey();
        if (prefix != null && k.startsWith(prefix)) {
            if (suffix != null && k.endsWith(suffix)) {
                result.put(k, e.getValue()[0]);
            }
        }
    }
    return result;
}

From source file:com.ibm.util.merge.web.rest.servlet.RequestData.java

public RequestData(HttpServletRequest request) {
    method = request.getMethod();/*from  w w  w.  j  av  a  2  s .  c  om*/
    byte[] bytes = readRequestBody(request);
    requestBody = bytes;
    contentType = request.getContentType();
    preferredLocale = request.getLocale();
    List<Locale> tlocales = getAllRequestLocales(request);
    locales = new ArrayList<>(tlocales);
    params = request.getParameterMap();
    pathInfo = request.getPathInfo();
    queryString = request.getQueryString();
    Map<String, List<String>> headerValues = readHeaderValues(request);
    headers = headerValues;
    requestUrl = request.getRequestURL().toString();
}