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:be.fedict.eid.idp.protocol.openid.AbstractOpenIDProtocolService.java

public IncomingRequest handleIncomingRequest(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    LOG.debug("handleIncomingRequest");
    ServerManager serverManager = getServerManager(request);
    ParameterList parameterList = new ParameterList(request.getParameterMap());
    String openIdMode = request.getParameter("openid.mode");
    if ("associate".equals(openIdMode)) {
        return doAssociation(request, response, serverManager, parameterList);
    }/*from   w  ww.ja  v  a2  s. c om*/
    if ("check_authentication".equals(openIdMode)) {
        return doCheckAuthentication(response, serverManager, parameterList);
    }
    if ("checkid_setup".equals(openIdMode)) {
        return doCheckIdSetup(request, serverManager, parameterList);
    }
    throw new ServletException("unknown OpenID mode: " + openIdMode);
}

From source file:dbaccess.servlets.LookupServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// ww w  .  java  2 s  .co m
 *
 * @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 user data bean using
    // apache BeanUtils
    UserData userData = new UserData();
    BookData bookData = new BookData();
    try {
        BeanUtils.populate(userData, request.getParameterMap());
        BeanUtils.populate(bookData, request.getParameterMap());
        String nextPage = null;

        // set up the bean as request parameter
        request.setAttribute("userData", userData);
        request.setAttribute("bookData", bookData);
        // check the operation and dispatch accordingly
        if (request.getParameter("lookup") != null) {
            List<User> results = null;
            if (!"".equals(userData.getId())) {
                // lookup by id
                results = getUserById(em, userData);
            } else if (!"".equals(userData.getName())) {
                // lookup by name
                results = getUsersByName(em, userData);
            } else if (!"".equals(userData.getBirthdate())) {
                // lookup by birthdate
                results = getUsersByBirthDate(em, userData);
            }
            if (results != null) {
                // users have been found
                request.setAttribute("results", results);
                //dispatch to JSP for displaying results
                nextPage = "/userResults.jsp";
            } else {
                // users not found
                // dispatch to error page
                nextPage = "/lookupError.jsp";
            }
        } else if (request.getParameter("add") != null) {
            if (userData.isComplete()) {
                if (DBHelper.addUser(em, utx, userData)) {
                    nextPage = "/successfulAdd.jsp";
                } else {
                    nextPage = "/failedAdd.jsp";
                }
            } else {
                nextPage = "/failedAddIncomplete.jsp";
            }
        } else if (request.getParameter("lookupBook") != null) {
            List<Book> results = null;
            if (!"".equals(bookData.getId())) {
                // lookup by id
                results = getBookById(em, bookData);
            } else if (!"".equals(bookData.getName())) {
                // lookup by name
                results = getBookByName(em, bookData);
            } else if (!"".equals(bookData.getAuthor())) {
                // lookup by author
                results = getBookByAuthor(em, bookData);
            } else if (!"".equals(bookData.getDescription())) {
                // lookup by description
                results = getBookByDescription(em, bookData);
            } else if (!"".equals(bookData.getDescription())) {
                // lookup by price
                results = getBookByPrice(em, bookData);
            } else if (!"".equals(bookData.getType())) {
                // lookup by type
                results = getBookByType(em, bookData);
            }
            if (results != null) {
                // users have been found
                request.setAttribute("results", results);
                //dispatch to JSP for displaying results
                nextPage = "/bookResults.jsp";
            } else {
                // users not found
                // dispatch to error page
                nextPage = "/lookupErrorBook.jsp";
            }
        } else if (request.getParameter("addBook") != null) {
            if (bookData.isComplete()) {
                if (DBHelper.addBook(em, utx, bookData)) {
                    nextPage = "/successfulAddBook.jsp";
                } else {
                    nextPage = "/failedAddBook.jsp";
                }
            } else {
                nextPage = "/failedAddIncompleteBook.jsp";
            }
        } else if (request.getParameter("deleteBook") != null) {
            if (DBHelper.deleteBook(em, utx, bookData.getId())) {
                nextPage = "/successfulDeleteBook.jsp";
            } else {
                nextPage = "/failedDeleteBook.jsp";
            }
        }
        RequestDispatcher dispatcher = request.getRequestDispatcher(nextPage);
        dispatcher.forward(request, response);
    } catch (IllegalAccessException | InvocationTargetException | ServletException | IOException ex) {
    }
}

From source file:com.thinkgem.jeesite.modules.sys.interceptor.GlobalInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {
    String uri = request.getRequestURI();
    String uriPrefix = request.getContextPath() + Global.ADMIN_PATH;
    // ??POST//  w  w  w.ja va  2  s . c om
    if ("POST".equals(request.getMethod()) && uri.length() > uriPrefix.length()) {
        User user = UserUtils.getUser();
        if (user != null) {
            StringBuilder sb = new StringBuilder();
            sb.append("url: (" + request.getMethod() + ") " + uri);
            int index = 0;
            for (Object param : request.getParameterMap().keySet()) {
                sb.append((index++ == 0 ? "?" : "&") + param + "=");
                sb.append(StringUtils.abbreviate(request.getParameter((String) param), 100));
            }
            sb.append("; userId: " + user.getId());
            sb.append("; userName: " + user.getName());
            sb.append("; loginName: " + user.getLoginName());
            sb.append("; ipAddr: " + request.getLocalAddr());
            sb.append("; datetime: " + DateUtils.getDateTime());
            sb.append("; handler: " + handler.toString());
            logger.info(sb.toString());
        }
    }
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * Parses a HTTPServletRequest and saves the information onto an existing entity
 *
 * @param <T>            - Class of entity
 * @param existingEntity - Entity to be written over
 * @param request        - HTTPRequest information
 * @return - Entity with new information
 *//*from w w  w.j  a v  a  2 s .c  om*/
public <T extends BaseEntity> T parse(final T existingEntity, final HttpServletRequest request) {
    final ParameterMapParser parser = ParameterMapParser.parse(request.getParameterMap());
    parser.loopData((key, value) -> writeToEntity(existingEntity, key, value));

    return existingEntity;
}

From source file:com.nkapps.billing.controllers.PaymentController.java

@RequestMapping(value = "/payment-list", method = RequestMethod.POST)
public @ResponseBody HashMap<String, Object> paymentList(HttpServletRequest request,
        HttpServletResponse response) {//from  www.  j a  va  2 s.com
    HashMap<String, Object> resMap = new LinkedHashMap<String, Object>();

    try {
        // for saving search parameters
        searchService.execSearchBy(request, response);
        searchService.execSearchWithinDate(request, response);
        searchService.execSearchByDate(request, response);

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

        for (String key : map.keySet()) {
            String[] mapValue = map.get(key);
            parameters.put(key, mapValue[0]);
        }

        resMap.put("success", true);
        resMap.put("draw", request.getParameter("draw"));

        resMap.put("data", paymentService.getPaymentList(parameters));

    } catch (Exception e) {
        logger.error(e.getMessage());
        resMap.put("success", false);
        resMap.put("reason", e.getMessage());
    }

    return resMap;
}

From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractMessageWrappingController.java

@SuppressWarnings("unchecked")
protected RESTResource getHeadingWithKnownUrlRequest(HttpServletRequest request, String resourceUrl) {

    return this.getHeading(request.getParameterMap(), resourceUrl);

}

From source file:com.adito.core.actions.AbstractMultiFormDispatchAction.java

private static SubActionWrapper getSubActionWrapper(ActionMapping mapping, ActionForm form,
        ActionMapping subMapping, HttpServletRequest request, int index) throws ClassNotFoundException,
        IllegalAccessException, InstantiationException, InvocationTargetException {
    String formName = subMapping.getName();
    ActionForm subForm = getActionForm(subMapping, request);

    FormBeanConfig formBean = mapping.getModuleConfig().findFormBeanConfig(formName);
    String className = formBean == null ? null : formBean.getType();
    if (className == null)
        return null;

    if (subForm == null || !className.equals(subForm.getClass().getName()))
        subForm = (ActionForm) Class.forName(className).newInstance();

    if ("request".equals(mapping.getScope()))
        request.setAttribute(formName, subForm);
    else//from   w w w .  j a v a  2s . c  om
        request.getSession().setAttribute(formName, subForm);

    subForm.reset(mapping, request);

    /*
     * We dont want to try and populate all forms on a post, only the one
     * that has requested it. For this the form must have a hidden parameter
     * with the name of 'subForm' and the value being the form name to
     * populate
     */
    AbstractMultiFormDispatchForm dispatchForm = (AbstractMultiFormDispatchForm) form;
    if (formName.equals(dispatchForm.getSubForm())) {
        dispatchForm.setSelectedTab(dispatchForm.getTabName(index));
        BeanUtils.populate(subForm, request.getParameterMap());
    }

    return new SubActionWrapper(subForm, subMapping);
}

From source file:com.nkapps.billing.controllers.PaymentController.java

@RequestMapping(value = "/claim-list", method = RequestMethod.POST)
public @ResponseBody HashMap<String, Object> claimList(HttpServletRequest request,
        HttpServletResponse response) {//from www  .  j a va  2  s  .  c  om
    HashMap<String, Object> resMap = new LinkedHashMap<String, Object>();

    try {
        // for saving search parameters
        searchService.execSearchBy(request, response);
        searchService.execSearchWithinDate(request, response);
        searchService.execSearchByDate(request, response);

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

        for (String key : map.keySet()) {
            String[] mapValue = map.get(key);
            parameters.put(key, mapValue[0]);
        }

        resMap.put("success", true);
        resMap.put("draw", request.getParameter("draw"));
        if ("".equals(request.getParameter("searchBy"))) {
            resMap.put("data", new HashMap());
        } else {
            resMap.put("data", paymentService.getClaimList(parameters));
        }

    } catch (Exception e) {
        logger.error(e.getMessage());
        resMap.put("success", false);
        resMap.put("reason", e.getMessage());
    }

    return resMap;
}

From source file:org.dataone.proto.trove.mn.rest.v1.CoreController.java

/**
 * Delete the object requested, and return the pid of object deleted
 *
 * @param request//from w  ww  .  j a  v a2 s.  c  o  m
 * @param response
 * @param pid
 * @throws InvalidToken
 * @throws ServiceFailure
 * @throws IOException
 * @throws NotAuthorized
 * @throws NotFound
 * @throws NotImplemented
 */
@RequestMapping(value = "/v1/log", method = RequestMethod.GET)
public ModelAndView getLogRecords(HttpServletRequest request, HttpServletResponse response) throws InvalidToken,
        ServiceFailure, IOException, NotAuthorized, NotFound, NotImplemented, InvalidRequest {
    debugRequest(request);
    Session cert = new Session();
    Integer start = 0;
    Integer count = 1000;
    Event event = null;
    String pidFilter = null;
    String startTime = null;
    String endTime = null;
    DateTime startDate = null;
    DateTime endDate = null;
    if (request.getParameterMap().keySet().contains("start")) {
        String[] values = (String[]) request.getParameterMap().get("start");
        start = Integer.parseInt(values[0]);
    }
    if (request.getParameterMap().keySet().contains("count")) {
        String[] values = (String[]) request.getParameterMap().get("count");
        count = Integer.parseInt(values[0]);
    }
    if (request.getParameterMap().keySet().contains("event")) {
        String[] values = (String[]) request.getParameterMap().get("event");
        event = Event.valueOf(values[0]);
    }
    if (request.getParameterMap().keySet().contains("pidFilter")) {
        String[] values = (String[]) request.getParameterMap().get("pidFilter");

        pidFilter = values[0];
    }
    if (request.getParameterMap().keySet().contains("fromDate")) {
        String[] values = (String[]) request.getParameterMap().get("fromDate");
        startTime = values[0];
    }
    if (request.getParameterMap().keySet().contains("toDate")) {
        String[] values = (String[]) request.getParameterMap().get("toDate");
        endTime = values[0];
    }
    logger.info("start = " + start + " count = " + count + " format = "
            + (pidFilter == null ? "null" : pidFilter) + " startTime = " + startTime + " endTime = " + endTime);
    if (!((startTime == null) && (endTime == null))) {
        if (startTime == null) {
            startTime = "1900-01-01T00:00:00Z";
        }
        if (endTime == null) {
            endTime = new DateTime().toString();
        }
        startDate = new DateTime(startTime, DateTimeZone.UTC);
        endDate = new DateTime(endTime, DateTimeZone.UTC);
    }
    Log log = mnCore.getLogRecords(cert, (startDate == null ? null : startDate.toDate()),
            (endDate == null ? null : endDate.toDate()), (event == null ? null : event), pidFilter, start,
            count);
    return new ModelAndView("xmlLogViewResolver", "org.dataone.service.types.v1.Log", log);
}