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.nlp2rdf.webservice.NIFParameterWebserviceFactory.java

/**
 * Factory method//from w w w .j a va2  s.c  om
 *
 * @param httpServletRequest
 * @return
 */
public static NIFParameters getInstance(HttpServletRequest httpServletRequest, String defaultPrefix)
        throws ParameterException, IOException {

    //twice the size to split key value
    String[] args = new String[httpServletRequest.getParameterMap().size() * 2];

    int x = 0;

    for (Object key : httpServletRequest.getParameterMap().keySet()) {
        String pname = (String) key;
        //transform key to CLI style
        pname = (pname.length() == 1) ? "-" + pname : "--" + pname;

        //collect CLI args
        args[x++] = pname;
        args[x++] = httpServletRequest.getParameter((String) key);

    }

    String line;
    String content = "";
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(httpServletRequest.getInputStream()));

        while ((line = reader.readLine()) != null) {
            if (line.startsWith("---") || line.startsWith("Content") || line.startsWith("html"))
                continue;
            content += line;

        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (args.length == 0 && !content.isEmpty()) {
        args = new String[4];
        String[] params = content.split("&");
        if (params.length > 0) {
            String[] i = params[0].split("=");
            String[] id = params[1].split("=");
            if (i.length > 0) {
                args[0] = "--" + i[0];
                args[1] = URLDecoder.decode(i[1], "UTF-8");
            }
            if (id.length > 0) {
                args[2] = "-" + id[0];
                args[3] = URLDecoder.decode(id[1], "UTF-8");
            }
            content = "";
        }
    }

    //        System.out.println(content);

    //parse CLI args
    OptionParser parser = ParameterParser.getParser(args, defaultPrefix);
    OptionSet options = ParameterParser.getOption(parser, args);

    // print help screen
    if (options.has("h")) {
        String addHelp = "";
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        parser.printHelpOn(baos);
        throw new ParameterException(baos.toString());
    }

    // parse options with webservice setted to true
    return ParameterParserMS.parseOptions(options, true, content);
}

From source file:com.avlesh.web.filter.responseheaderfilter.ResponseHeaderFilter.java

/**
 * As long as a parameter is present in the queryString (of the <code>request</code>), the value for that
 * query parameter is <code>request.getParameter(queryParam)</code>. If this turns out to be <code>null</code>
 * the value <code>""</code> (empty string) is assigned to the queryParam. This is done to match the
 * <code>Regex</code> (.*) in the condition. Unavailable queryParams in the <code>request</code> are treated as
 * value <code>null</code>//from   www .j a v  a 2s  .c  om
 *
 * @param request (The incoming request)
 * @param queryParamName (Parameter which needs to be looked up)
 * @return String (The "value" of this parameter in the queryString)
 *
 * @see ResponseHeaderFilter
 * @see ResponseHeaderFilter#doFilter(ServletRequest, ServletResponse, FilterChain)
 */
private static String getRequestParamValue(HttpServletRequest request, String queryParamName) {
    String paramValue = null;
    if (request.getParameterMap().containsKey(queryParamName)) {
        paramValue = request.getParameter(queryParamName);
        if (paramValue == null) {
            paramValue = "";
        }
    }
    return paramValue;
}

From source file:org.oncoblocks.centromere.web.controller.RequestUtils.java

/**
 * Extracts the requested filtered fields parameter from a request.
 * /*from www . j  a  va2s .  c o m*/
 * @param request
 * @return
 */
public static Set<String> getFilteredFieldsFromRequest(HttpServletRequest request) {
    Set<String> fields = null;
    if (request.getParameterMap().containsKey("fields")) {
        fields = new HashSet<>();
        String[] params = request.getParameter("fields").split(",");
        for (String field : params) {
            fields.add(field.trim());
        }
    }
    return fields;
}

From source file:org.oncoblocks.centromere.web.controller.RequestUtils.java

/**
 * Extracts the requested filtered fields parameter from a request.
 *
 * @param request//from   ww w  .  j a  v  a2s.c o  m
 * @return
 */
public static Set<String> getExcludedFieldsFromRequest(HttpServletRequest request) {
    Set<String> exclude = null;
    if (request.getParameterMap().containsKey("exclude")) {
        exclude = new HashSet<>();
        String[] params = request.getParameter("exclude").split(",");
        for (String field : params) {
            exclude.add(field.trim());
        }
    }
    return exclude;
}

From source file:eu.europeana.core.util.web.ClickStreamLoggerImpl.java

private static String getRequestUrl(HttpServletRequest request) {
    String base = ControllerUtil.getFullServletUrl(request);
    String queryStringParameters = request.getQueryString();
    Map postParameters = request.getParameterMap();
    StringBuilder out = new StringBuilder();
    out.append(base);//from w  ww . j a  v a 2 s.  c o  m
    String queryString;
    if (queryStringParameters != null) {
        out.append("?").append(queryStringParameters);
        queryString = out.toString();
    } else if (postParameters.size() > 0) {
        out.append("?");
        for (Object entryKey : postParameters.entrySet()) {
            Map.Entry entry = (Map.Entry) entryKey;
            String key = entry.getKey().toString();
            String[] values = (String[]) entry.getValue();
            for (String value : values) {
                out.append(key).append("=").append(value).append("&");
            }
        }
        queryString = out.toString().substring(0, out.toString().length() - 1);
    } else {
        queryString = out.toString();
    }
    return queryString;
}

From source file:org.esgf.web.LiveSearchController.java

private static List<String> getFacetParamList(HttpServletRequest request) {

    List<String> facetParams = new ArrayList<String>();

    for (Object key : request.getParameterMap().keySet()) {
        String keyStr = (String) key;

        facetParams.add(keyStr);//from w ww .  j  av a2s.c o m
    }

    return facetParams;

}

From source file:info.magnolia.cms.util.RequestFormUtil.java

public static Map getParameters(HttpServletRequest request) {
    MultipartForm form = Resource.getPostedForm(request);
    if (form == null) {
        // if get use UTF8 decoding
        if (request.getMethod() == "GET") {
            return getURLParametersDecoded(request, "UTF8");
        }// w w  w.ja va 2s.  c om
        return request.getParameterMap();
    }
    return form.getParameters();
}

From source file:com.ecbeta.common.util.JSONUtils.java

public static JSONObject toJSON(HttpServletRequest request) {
    MapJSONBean json = new MapJSONBean();
    for (Object s : request.getParameterMap().keySet()) {
        for (String value : request.getParameterValues(s.toString())) {
            json.add(s.toString(), value);
        }/*from   w ww  . j a  v a 2 s.  co m*/
    }

    try {
        BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
        String line;
        String data = "";
        while ((line = br.readLine()) != null) {
            data += line;
        }
        data = URLDecoder.decode(data, "UTF-8");
        try {
            JSONObject oo = JSONObject.fromObject(data);
            return oo;
        } catch (Exception ex) {
            Map<String, List<String>> params = parseParameters(data);
            for (Map.Entry<String, List<String>> entry : params.entrySet()) {
                for (String value : entry.getValue()) {
                    json.add(entry.getKey(), value);
                }
            }
        }

    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    }

    JSONObject job = json.toJson();
    logger.info("~~~~~~~~~AutoCreating~~~~~~~~~");
    logger.info(json == null ? "" : job.toString(2));
    logger.info("~~~~~~~~~End~~~~~~~~~");
    return job;
}

From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java

public static String getDetinationUri(HttpServletRequest req) { // for action that specify the destination of the action in the request
    if (req.getParameterMap().containsKey(REQUEST_PARAMENTER_MOVE_TO))
        return req.getParameter(REQUEST_PARAMENTER_MOVE_TO);

    if (req.getParameterMap().containsKey(REQUEST_PARAMENTER_COPY_TO))
        return req.getParameter(REQUEST_PARAMENTER_COPY_TO);

    return null;//w w w  . j  av a  2s  .c o m
}

From source file:dk.statsbiblioteket.doms.surveillance.surveyor.SurveyorServletUtils.java

/**
 * Handle actions given a servlet request on a surveyor.
 * Will handle requests to mark a log message as handled, and requests
 * never to show a given message again.//from ww w .j  a v a  2 s.co m
 * @param request The request containing the parameters.
 * @param surveyor The surveyor to call the actions on.
 */
public static void handlePostedParameters(HttpServletRequest request, Surveyor surveyor) {
    log.trace("Enter handlePostedParameters()");
    String applicationName;

    try {
        request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException e) {
        //UTF-8 must be supported as per spec.
        throw new Error("UTF-8 unsupported by JVM", e);
    }

    applicationName = request.getParameter("applicationname");
    if (applicationName != null) {
        Map<String, String[]> parameters = request.getParameterMap();
        for (String key : parameters.keySet()) {
            if (key.startsWith("handle:") && Arrays.equals(new String[] { "Handled" }, parameters.get(key))) {
                surveyor.markHandled(applicationName, key.substring("handle:".length()));
            }
        }
        if (request.getParameter("notagain") != null) {
            surveyor.notAgain(applicationName, request.getParameter("notagain"));
        }
    }
}