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:net.ontopia.topicmaps.nav2.servlets.TreeWidget.java

/**
 * EXPERIMENTAL: Runs the widget, producing the output.
 *//* w  w  w. java2 s. com*/
public void run(PageContext ctxt, Writer writer)
        throws IOException, InvalidQueryException, NavigatorRuntimeException {
    context = FrameworkUtils.getContextTag(ctxt);
    HttpServletRequest request = (HttpServletRequest) ctxt.getRequest();
    Map parameters = request.getParameterMap();

    // check that query has been parsed
    if (query == null)
        query = processor.parse(querystr);

    // get current node
    TopicIF current = null;
    if (parameters.containsKey("current"))
        current = getTopic(get(parameters, "current"));

    int action = getAction(parameters);
    if (action == EXPAND_ALL)
        openNodes = new UniversalSet();
    else if (action == CLOSE_ALL)
        openNodes = new HashSet();
    else {
        openNodes = getOpenNodes(request);
        if (action == OPEN)
            openNodes.add(current);
        else if (action == CLOSE)
            openNodes.remove(current);
    }

    int topline = 0;
    if (parameters.containsKey("topline")) {
        try {
            topline = Integer.parseInt(get(parameters, "topline"));
        } catch (NumberFormatException e) {
        }
    }

    try {
        doQuery(topline, writer);
    } catch (InvalidQueryException e) {
        throw new net.ontopia.utils.OntopiaRuntimeException(e);
    }

    setOpenNodes(request, openNodes);
}

From source file:com.ethercis.vehr.parser.EhrScapeURIParserTest.java

@Test
public void testTemplateQueryParser() throws ServiceManagerException {

    // get a template with templateId = 'template_id'
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template/template_id");
    Map<String, String[]> parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    Map<String, String[]> headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("GET");
    uriParser.parse(request);/*from  w  ww .  j ava2  s.  co  m*/
    assertEquals("GET", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template", uriParser.identifyPath());
    assertEquals("template_id",
            uriParser.identifyParametersAsProperties().getClientProperty("templateId").toString());

    //get an example for a templateId = 'template_id'
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template/template_id/example");
    parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("GET");
    uriParser.parse(request);
    assertEquals("GET", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template/example", uriParser.identifyPath());
    assertEquals("template_id",
            uriParser.identifyParametersAsProperties().getClientProperty("templateId").toString());

    //get the list of templates
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template");
    parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("GET");
    uriParser.parse(request);
    assertEquals("GET", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template", uriParser.identifyPath());

    //delete a template
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template/template_id");
    parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("DELETE");
    uriParser.parse(request);
    assertEquals("DELETE", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template", uriParser.identifyPath());
    assertEquals("template_id",
            uriParser.identifyParametersAsProperties().getClientProperty("templateId").toString());

    //post a template
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template");
    parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("POST");
    uriParser.parse(request);
    assertEquals("POST", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template", uriParser.identifyPath());

}

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

@RequestMapping(value = "/click-list", method = RequestMethod.POST)
public @ResponseBody HashMap<String, Object> clickList(HttpServletRequest request,
        HttpServletResponse response) {/*w w w  .j av a 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"));

        resMap.put("data", reportService.getClickList(parameters));

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

    return resMap;
}

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

@RequestMapping(value = "/smst-list", method = RequestMethod.POST)
public @ResponseBody HashMap<String, Object> smstList(HttpServletRequest request,
        HttpServletResponse response) {//  ww  w.  j  av  a  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", reportService.getSmstList(parameters));

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

    return resMap;
}

From source file:controler.category.UpdateCategoryServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Category category = new Category();
    category.setName(request.getParameter("name").trim());
    category.setId(Integer.parseInt(request.getParameter("id").trim()));
    category.setDescription(request.getParameter("description").trim());
    category.setProductNum(Integer.parseInt(request.getParameter("productNum").trim()));
    CategoryDAO categoryDAO = new CategoryDAO();
    try {/*from   w w  w .ja  v a  2 s .  co  m*/
        BeanUtils.populate(category, request.getParameterMap());
        if (categoryDAO.connect()) {
            categoryDAO.updateCategory(category);
        }

    } catch (IllegalAccessException ex) {
        Logger.getLogger(UpdateCategoryServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException ex) {
        Logger.getLogger(UpdateCategoryServlet.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        categoryDAO.disconnect();
        response.sendRedirect("AdminViewCategory");
    }

}

From source file:jp.co.opentone.bsol.framework.web.extension.jsf.RequestLoggingPhaseListener.java

@Override
public void beforePhase(PhaseEvent event) {
    HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
            .getRequest();/* w w  w. jav  a  2s  .c  o m*/

    log.info("Requested: {} {}", req.getMethod(), req.getRequestURI());
    Enumeration<?> enm = req.getHeaderNames();
    log.info("Header:");
    while (enm.hasMoreElements()) {
        String name = (String) enm.nextElement();
        log.info("   {} = {}", name, req.getHeader(name));
    }

    log.info(" Parameters:");
    @SuppressWarnings("unchecked")
    Map<String, String[]> parameterMap = req.getParameterMap();
    for (Map.Entry<String, String[]> e : parameterMap.entrySet()) {
        log.info("  {} = {}", e.getKey(), StringUtils.join(e.getValue()));
    }
}

From source file:mx.edu.um.mateo.inventario.web.SalidaController.java

@RequestMapping(value = "/productos", params = "term", produces = "application/json")
public @ResponseBody List<LabelValueBean> productos(HttpServletRequest request,
        @RequestParam("term") String filtro) {
    for (String nombre : request.getParameterMap().keySet()) {
        log.debug("Param: {} : {}", nombre, request.getParameterMap().get(nombre));
    }//from   ww w.ja v  a2  s .c o m
    List<Producto> productos = productoDao.listaParaSalida(filtro,
            (Long) request.getSession().getAttribute("almacenId"));
    List<LabelValueBean> valores = new ArrayList<>();
    for (Producto producto : productos) {
        StringBuilder sb = new StringBuilder();
        sb.append(producto.getSku());
        sb.append(" | ");
        sb.append(producto.getNombre());
        sb.append(" | ");
        sb.append(producto.getDescripcion());
        sb.append(" | ");
        sb.append(producto.getExistencia()).append(" ").append(producto.getUnidadMedida());
        sb.append(" | ");
        sb.append(producto.getPrecioUnitario());
        valores.add(new LabelValueBean(producto.getId(), sb.toString()));
    }
    return valores;
}

From source file:es.pode.soporte.seguridad.openId.ui.openid.consumers.OpenID4JavaConsumer.java

public OpenIDAuthenticationToken endConsumption(HttpServletRequest request) throws OpenIDConsumerException {
    // extract the parameters from the authentication response
    // (which comes in as a HTTP request from the OpenID provider)
    ParameterList openidResp = new ParameterList(request.getParameterMap());
    try {/*  w  w w.j a va 2 s. c o  m*/
        if ((this.getAgregaPropertyValue(AgregaProperties.USAPROXY)).equalsIgnoreCase("true")) {
            if (log.isDebugEnabled())
                log.debug("La aplicacion necesita proxy");
            ProxyProperties proxyProps = new ProxyProperties();
            proxyProps.setProxyHostName(this.getAgregaPropertyValue(AgregaProperties.HOSTPROXY));
            proxyProps.setProxyPort(
                    new Integer(this.getAgregaPropertyValue(AgregaProperties.PORTPROXY)).intValue());
            proxyProps.setUserName(this.getAgregaPropertyValue(AgregaProperties.USUARIOPROXY));
            proxyProps.setPassword(this.getAgregaPropertyValue(AgregaProperties.CLAVEPROXY));
            HttpClientFactory.setProxyProperties(proxyProps);
        }
    } catch (IOException ioe) {
        log.error("Exception al obtener datos del proxy del fichero agrega.properties", ioe);
    }

    // retrieve the previously stored discovery information
    DiscoveryInformation discovered = (DiscoveryInformation) request.getSession()
            .getAttribute(DiscoveryInformation.class.getName());

    // extract the receiving URL from the HTTP request
    StringBuffer receivingURL = request.getRequestURL();
    String queryString = request.getQueryString();

    if ((queryString != null) && (queryString.length() > 0)) {
        receivingURL.append("?").append(request.getQueryString());
    }

    // verify the response
    VerificationResult verification;

    try {
        verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered);
        if (log.isDebugEnabled())
            log.debug("verification vale  " + verification);
    } catch (MessageException e) {
        throw new OpenIDConsumerException("Error verifying openid response", e);
    } catch (DiscoveryException e) {
        throw new OpenIDConsumerException("Error verifying openid response", e);
    } catch (AssociationException e) {
        throw new OpenIDConsumerException("Error verifying openid response", e);
    }

    // examine the verification result and extract the verified identifier
    Identifier verified = verification.getVerifiedId();
    if (log.isDebugEnabled())
        log.debug("verified vale  " + verified);

    if (verified != null) {
        String signedText = "";
        String email = "";
        try {
            AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
            ////////Saco los atributos de authSuccess //////////

            //Se comprueba si en la cadena SignedText de authSuccess nos llega el email. Slo se tendr en cuenta como usuario de openId
            //si es una cuenta de correo de gmail, para el resto de proveedores (yahoo) se va a considerar la uri de openid

            signedText = authSuccess.getSignedText();
            if (log.isDebugEnabled())
                log.debug("[signedText ]" + signedText);
            if (!((authSuccess.getSignedText()).indexOf("ext1.value.email:") == -1)) {
                if (log.isDebugEnabled())
                    log.debug("Nos llega el email del proveedor");
                int longitudCadenaEmail = 17; //longitud de la cadena ext1.type.email:

                email = (signedText.substring(
                        (authSuccess.getSignedText()).indexOf("ext1.value.email:") + longitudCadenaEmail))
                                .trim();
                if (log.isDebugEnabled())
                    log.debug("[email] " + email);
            }

            if (log.isDebugEnabled())
                log.debug("authSuccess " + authSuccess);
            if (log.isDebugEnabled())
                log.debug("authSuccess.hasExtension(AxMessage.OPENID_NS_AX) "
                        + authSuccess.hasExtension(AxMessage.OPENID_NS_AX));
            if (log.isDebugEnabled())
                log.debug("authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG) "
                        + authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG));
            if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
                MessageExtension ext = authSuccess.getExtension(AxMessage.OPENID_NS_AX);

                if (ext instanceof FetchResponse) {
                    if (log.isDebugEnabled())
                        log.debug("ext instanceof FetchResponse");
                    FetchResponse fetchResp = (FetchResponse) ext;
                    if (log.isDebugEnabled())
                        log.debug("fetchResp " + fetchResp);

                    // can have multiple values
                    List emails = fetchResp.getAttributeValues("Email");
                    if (log.isDebugEnabled())
                        log.debug("[emails ]" + emails);
                } else {
                    if (log.isDebugEnabled())
                        log.debug("No es  instance of FetchResponse");
                }
            }

        } catch (Exception e) {
            log.error("Se produce una exception " + e);
        }
        //Slo se considera el email cuando el proveedor es gmail
        if (!(email.indexOf("gmail") == -1)) {
            return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS, email, "some message");
        } else {
            return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS, verified.getIdentifier(),
                    "some message");
        }

    } else {
        if (discovered == null) {
            return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE, "",
                    "Discovered information verification failed ");
        } else {
            return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE,
                    discovered.getClaimedIdentifier().getIdentifier(),
                    "Verification status message: [" + verification.getStatusMsg() + "]");
        }

    }
}

From source file:com.sammyun.plugin.alipayWap.AlipayWapPlugin.java

/**
 * RSA??//  www . j  a v  a 2s. com
 * 
 * @return ??
 * @throws Exception
 */
private Map<String, Object> generateMobileSign(HttpServletRequest request) {
    // ??POST????
    Map<String, Object> params = new HashMap<String, Object>();
    Map requestParams = request.getParameterMap();
    for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
        String name = (String) iter.next();
        String[] values = (String[]) requestParams.get(name);
        String valueStr = "";
        for (int i = 0; i < values.length; i++) {
            valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
        }
        // ???mysignsign???
        params.put(name, valueStr);
    }
    return params;
}