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:org.sventon.web.ctrl.template.AbstractTemplateController.java

/**
 * Prepares the authentication model. This sets up a model and redirect view with
 * all stuff needed to redirect control to the login page.
 *
 * @param request Request./* w  w w.  jav a 2  s .co  m*/
 * @param model   Pre-populated model.
 * @return Redirect view for logging in, with original request info stored in
 *         session to enable the authentication control to proceed with
 *         original request once the user is authenticated.
 */
private ModelAndView prepareAuthenticationRequiredView(final HttpServletRequest request,
        Map<String, Object> model) {
    final Map<String, Object> authenticationModel = new HashMap<String, Object>(model);
    authenticationModel.put("parameters", request.getParameterMap());
    authenticationModel.put("action", request.getRequestURL());
    logger.debug("Forwarding to 'authenticationRequired' view");
    return new ModelAndView("error/authenticationRequired", authenticationModel);
}

From source file:it.greenvulcano.gvesb.debug.DebuggerServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//*from  w  w w . j av a2s  . co m*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {

        StringBuffer sb = new StringBuffer();
        dump(request, sb);
        LOG.debug(sb.toString());

        DebugCommand debugOperation = Optional.ofNullable(request.getParameter("debugOperation"))
                .map(DebugCommand::valueOf).orElseThrow(IllegalArgumentException::new);

        PrintWriter writer = response.getWriter();

        Map<DebugKey, String> params = request.getParameterMap().keySet().stream().filter(KEYS::contains)
                .map(DebugKey::valueOf)
                .collect(Collectors.toMap(Function.identity(), k -> request.getParameter(k.name())));

        DebuggerObject dObj = gvDebugger.processCommand(debugOperation, params);

        if (dObj == null) {
            dObj = DebuggerObject.FAIL_DEBUGGER_OBJECT;
        }
        String debugOperationResponse = dObj.toXML();

        LOG.debug("Debug operation response: " + debugOperationResponse);
        writer.println(debugOperationResponse);
    } catch (IllegalArgumentException e) {
        LOG.error("Fail to process debug operation: missing or invalid value for parameter debugOperation");
        response.getWriter().println("Missing or invalid value for parameter debugOperation");
    } catch (Exception e) {
        LOG.error("Fail to process debug operation", e);
        throw new ServletException(e);
    }
}

From source file:com.yoshio3.modules.AzureADServerAuthModule.java

public boolean containsAuthenticationData(HttpServletRequest httpRequest) {
    //        System.out.println("containsAuthenticationData ??" + httpRequest.getUserPrincipal().getName());

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

    return httpRequest.getMethod().equalsIgnoreCase("POST") && (httpRequest.getParameterMap().containsKey(ERROR)
            || httpRequest.getParameterMap().containsKey(ID_TOKEN)
            || httpRequest.getParameterMap().containsKey(CODE));
}

From source file:com.reachcall.pretty.http.ProxyServlet.java

@SuppressWarnings("unchecked")
private void doPost(HttpPost method, HttpServletRequest req) throws IOException {
    copyHeaders(req, method);/*from  w w w . ja  va 2 s .c  o m*/
    if (CONTENT_TYPE_FORM.equalsIgnoreCase(req.getContentType())) {
        Map<String, String[]> params = (Map<String, String[]>) req.getParameterMap();
        List<NameValuePair> pairs = new LinkedList<NameValuePair>();

        for (String name : params.keySet()) {
            String[] values = params.get(name);

            for (String value : values) {
                NameValuePair pair = new BasicNameValuePair(name, value);
                pairs.add(pair);
            }
        }

        method.setEntity(new UrlEncodedFormEntity(pairs, "UTF-8"));
    } else {
        method.setEntity(new InputStreamEntity(req.getInputStream(), req.getContentLength()));
    }
}

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

@Test
public void testEhrQueryParser() throws ServiceManagerException {
    //        Request request = client.newRequest("http://" + hostname + ":8080/rest/v1/ehr?subjectId=1234&subjectNamespace=ABCDEF");
    //        request.method(HttpMethod.POST);
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/ehr");
    Map<String, String[]> parameters = new HashMap<String, String[]>();
    parameters.put("subjectId", new String[] { "1234" });
    parameters.put("subjectNamespace", new String[] { "ABCDEF" });
    when(request.getParameterMap()).thenReturn(parameters);
    Map<String, String[]> headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/json" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/json");
    when(request.getMethod()).thenReturn("POST");
    uriParser.parse(request);//from w  w w  .j a  v  a  2  s.  co m
    assertEquals("POST", uriParser.identifyMethod().toUpperCase());
    assertEquals("1234", uriParser.identifyParametersAsProperties().getClientProperty("subjectId").toString());
    assertEquals("ABCDEF",
            uriParser.identifyParametersAsProperties().getClientProperty("subjectNamespace").toString());

    ///ehr/{ehrId} retrieve an ehr Status from its id
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/ehr/8fd2bea0-9e0e-11e5-8994-feff819cdc9f");
    parameters = new HashMap<>();
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<>();
    headers.put("Content-Type", new String[] { "application/json" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/json");
    when(request.getMethod()).thenReturn("GET");
    uriParser.parse(request);
    assertEquals("GET", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/ehr/status", uriParser.identifyPath());
    assertEquals("8fd2bea0-9e0e-11e5-8994-feff819cdc9f",
            uriParser.identifyParametersAsProperties().getClientProperty("ehrId").toString());

    //Returns a JSON representation of the state of the EHR for a subject Id and namespace (STATUS)
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/ehr");
    parameters = new HashMap<>();
    parameters.put("subjectId", new String[] { "1234" });
    parameters.put("subjectNamespace", new String[] { "ABCDEF" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<>();
    headers.put("Content-Type", new String[] { "application/json" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/json");
    when(request.getMethod()).thenReturn("GET");
    uriParser.parse(request);
    assertEquals("GET", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/ehr/status", uriParser.identifyPath());
    assertEquals("1234", uriParser.identifyParametersAsProperties().getClientProperty("subjectId").toString());
    assertEquals("ABCDEF",
            uriParser.identifyParametersAsProperties().getClientProperty("subjectNamespace").toString());

    //update the status of an EHR
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/ehr/status/8fd2bea0-9e0e-11e5-8994-feff819cdc9f");
    parameters = new HashMap<>();
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<>();
    headers.put("Content-Type", new String[] { "application/json" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/json");
    when(request.getMethod()).thenReturn("PUT");
    uriParser.parse(request);
    assertEquals("PUT", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/ehr/status", uriParser.identifyPath());
    assertEquals("8fd2bea0-9e0e-11e5-8994-feff819cdc9f",
            uriParser.identifyParametersAsProperties().getClientProperty("ehrId").toString());
}

From source file:com.formkiq.core.service.workflow.WorkflowServiceImpl.java

@Deprecated
@Override//  w w w  .j a  va  2  s  .  c  o  m
public Pair<ModelAndView, WebFlow> transition(final HttpServletRequest request) throws IOException {

    Map<String, String[]> parameterMap = request.getParameterMap();
    // TODO change to FlowEventService
    if (parameterMap.containsKey("_eventId_next")) {
        return next(request);
    } else if (parameterMap.containsKey("_eventId_prev")) {
        return previous(request);
    } else if (parameterMap.containsKey("execution")) {
        WebFlow flow = FlowManager.get(request);
        return Pair.of(
                new ModelAndView("redirect:/flow/workflow?execution=" + request.getParameter("execution")),
                flow);
    }

    throw new FlowEndedException();
}

From source file:com.wordpress.metaphorm.authProxy.httpClient.impl.OAuthProxyConnectionApacheHttpCommonsClientImpl.java

/**
 * Sets up the given {@link PostMethod} to send the same standard POST
 * data as was sent in the given {@link HttpServletRequest}
 * @param postMethodProxyRequest The {@link PostMethod} that we are
 *                                configuring to send a standard POST request
 * @param httpServletRequest The {@link HttpServletRequest} that contains
 *                            the POST data to be sent via the {@link PostMethod}
 *///from w w w. j a v a  2 s.c o  m
@SuppressWarnings("unchecked")
private void handleStandardPost(PostMethod postMethodProxyRequest, HttpServletRequest httpServletRequest) {

    _log.debug("handleStandardPost()");

    // Get the client POST data as a Map
    Map<String, String[]> mapPostParameters = (Map<String, String[]>) httpServletRequest.getParameterMap();
    // Create a List to hold the NameValuePairs to be passed to the PostMethod
    List<NameValuePair> listNameValuePairs = new ArrayList<NameValuePair>();
    // Iterate the parameter names
    for (String stringParameterName : mapPostParameters.keySet()) {

        StringBuffer debugMsg = new StringBuffer();
        debugMsg.append("Post param: " + stringParameterName);

        // Iterate the values for each parameter name
        String[] stringArrayParameterValues = mapPostParameters.get(stringParameterName);
        for (String stringParamterValue : stringArrayParameterValues) {

            debugMsg.append(" \"" + stringParamterValue + "\"");

            // Create a NameValuePair and store in list
            NameValuePair nameValuePair = new NameValuePair(stringParameterName, stringParamterValue);
            listNameValuePairs.add(nameValuePair);
        }
        _log.debug(debugMsg.toString());
    }
    // Set the proxy request POST data 
    postMethodProxyRequest.setRequestBody(listNameValuePairs.toArray(new NameValuePair[] {}));
}

From source file:fr.aliasource.webmail.server.invitation.GetInvitationInfoProxyImpl.java

@SuppressWarnings("unchecked")
@Override/*from   w  ww. j  a  va  2 s.c om*/
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    IAccount ac = (IAccount) req.getSession().getAttribute("account");

    if (ac == null) {
        GWT.log("Account not found in session", null);
        resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    PostMethod pm = new PostMethod(backendUrl);
    if (req.getQueryString() != null) {
        pm.setQueryString(req.getQueryString());
    }
    Map<String, String[]> params = req.getParameterMap();
    for (String p : params.keySet()) {
        String[] val = params.get(p);
        pm.setParameter(p, val[0]);
    }

    synchronized (hc) {
        try {
            int ret = hc.executeMethod(pm);
            if (ret != HttpStatus.SC_OK) {
                log("method failed:\n" + pm.getStatusLine() + "\n" + pm.getResponseBodyAsString());
                resp.setStatus(ret);
            } else {
                InputStream is = pm.getResponseBodyAsStream();
                transfer(is, resp.getOutputStream(), false);
            }

        } catch (Exception e) {
            log("error occured on call proxyfication", e);
        } finally {
            pm.releaseConnection();
        }
    }
}

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

@RequestMapping(value = "/crea", method = RequestMethod.POST)
public String crea(HttpServletRequest request, HttpServletResponse response, @Valid FacturaAlmacen factura,
        BindingResult bindingResult, Errors errors, Model modelo, RedirectAttributes redirectAttributes) {
    for (String nombre : request.getParameterMap().keySet()) {
        log.debug("Param: {} : {}", nombre, request.getParameterMap().get(nombre));
    }/*from  w w w .  j a v a2 s  .c  o m*/

    try {
        Usuario usuario = ambiente.obtieneUsuario();
        if (request.getParameter("cliente.id") == null) {
            log.warn("No se puede crear la factura si no ha seleccionado un cliente");
            errors.rejectValue("cliente", "facturaAlmacen.sin.cliente.message");
            return "inventario/factura/nueva";
        }
        Cliente cliente = clienteDao.obtiene(new Long(request.getParameter("cliente.id")));
        factura.setCliente(cliente);
        factura = facturaDao.crea(factura, usuario);
    } catch (ConstraintViolationException e) {
        log.error("No se pudo crear la factura", e);
        errors.rejectValue("factura", "campo.duplicado.message", new String[] { "factura" }, null);

        return "inventario/factura/nueva";
    }

    redirectAttributes.addFlashAttribute("message", "facturaAlmacen.creada.message");
    redirectAttributes.addFlashAttribute("messageAttrs", new String[] { factura.getFolio() });

    return "redirect:/inventario/factura/ver/" + factura.getId();
}

From source file:fr.aliasource.webmail.server.calendar.CalendarProxyImpl.java

@SuppressWarnings("unchecked")
@Override// w  ww. j av a  2 s .  co m
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    IAccount ac = (IAccount) req.getSession().getAttribute("account");

    if (ac == null) {
        GWT.log("Account not found in session", null);
        resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    PostMethod pm = new PostMethod(backendUrl);
    if (req.getQueryString() != null) {
        pm.setQueryString(req.getQueryString());
    }
    Map<String, String[]> params = req.getParameterMap();
    for (String p : params.keySet()) {
        String[] val = params.get(p);
        pm.setParameter(p, val[0]);
    }

    synchronized (hc) {
        try {
            int ret = hc.executeMethod(pm);
            if (ret != HttpStatus.SC_OK) {
                log("method failed:\n" + pm.getStatusLine() + "\n" + pm.getResponseBodyAsString());
                resp.setStatus(ret);
            } else {
                InputStream is = pm.getResponseBodyAsStream();
                transfer(is, resp.getOutputStream(), false);
            }
        } catch (Exception e) {
            log("error occured on call proxyfication", e);
        } finally {
            pm.releaseConnection();
        }
    }
}