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.ibm.jaggr.service.impl.transport.AbstractHttpTransport.java

/**
 * Returns the value of the requested parameter from the request, or null
 * //from w ww . j a v  a2 s. c o  m
 * @param request
 *            the request object
 * @param aliases
 *            array of query arg names by which the request may be specified
 * @return the value of the param, or null if it is not specified under the
 *         specified names
 */
protected static String getParameter(HttpServletRequest request, String[] aliases) {
    Map<String, String[]> params = request.getParameterMap();
    String result = null;
    for (Map.Entry<String, String[]> entry : params.entrySet()) {
        String name = entry.getKey();
        for (String alias : aliases) {
            if (alias.equalsIgnoreCase(name)) {
                String[] values = entry.getValue();
                result = values[values.length - 1]; // return last value in array
            }
        }
    }
    return result;
}

From source file:com.redhat.rhn.common.util.RecurringEventPicker.java

/**
 * Prepopulate the request with the picker
 * @param request the http request/*from   w w  w  .j  ava  2 s.co  m*/
 * @param name the name of the picker
 * @param cronEntry if non-null, will set the picker to this.
 * @return The created picker
 */
public static RecurringEventPicker prepopulatePicker(HttpServletRequest request, String name,
        String cronEntry) {

    RecurringEventPicker p = new RecurringEventPicker(name);
    request.setAttribute(name, p);

    String tmpStatus = request.getParameter(name + "_status");
    if (tmpStatus != null) {
        p.setStatus(tmpStatus);
        if (tmpStatus.equals(STATUS_DAILY)) {
            DatePicker timePicker = p.getDailyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            p.setCronEntry(buildCron(minute, hour, null, null, STATUS_DAILY));

        } else if (tmpStatus.equals(STATUS_WEEKLY)) {
            DatePicker timePicker = p.getWeeklyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            String day = request.getParameter(name + WEEKLY_DAY_OF_WEEK);
            p.setCronEntry(buildCron(minute, hour, null, day, STATUS_WEEKLY));
        } else if (tmpStatus.equals(STATUS_MONTHLY)) {
            DatePicker timePicker = p.getMonthlyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            String day = request.getParameter(name + MONTHLY_DAY_OF_MONTH);
            p.setCronEntry(buildCron(minute, hour, day, null, STATUS_MONTHLY));
        } else if (tmpStatus.equals(STATUS_CRON)) {
            p.setCronEntry(request.getParameter(name + CRON_ENTRY));
        } else if (tmpStatus.equals(STATUS_DISABLED)) {
            p.setStatus(STATUS_DISABLED);
        }
    } else if (cronEntry != null) {
        if (cronEntry.split(WHITE_SPACE).length < 6) {
            //The Cron Entry is too short
            return null;
        }

        // here do it the other way around, set the time pickers from
        // the cron time
        if (matches(cronEntry, DAILY_REGEX)) {
            p.setStatus(STATUS_DAILY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getDailyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else if (matches(cronEntry, WEEKLY_REGEX)) {
            p.setStatus(STATUS_WEEKLY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getWeeklyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else if (matches(cronEntry, MONTHLY_REGEX)) {
            p.setStatus(STATUS_MONTHLY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getMonthlyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else {
            p.setStatus(STATUS_CRON);
            p.setCronEntry(cronEntry);
        }
    }

    return p;
}

From source file:com.comcast.cqs.util.Util.java

public static HashMap<String, String> fillAllSetAttributesRequests(HttpServletRequest request)
        throws CMBException {

    HashMap<String, String> filterRequests = new HashMap<String, String>();
    Map<String, String[]> requestParams = request.getParameterMap();
    Pattern p = Pattern.compile("(Attribute\\.(\\d*\\.)?)Name");

    boolean found = false;

    for (String k : requestParams.keySet()) {

        Matcher m = p.matcher(k);

        if (m.find()) {

            found = true;/*from   ww  w. java2  s.com*/
            String v = m.group(1) + "Value";

            if (requestParams.get(v) == null) {
                throw new CMBException(CMBErrorCodes.MissingParameter,
                        "The request must contain the parameter Attribute." + m.group(1) + "Value");
            }

            filterRequests.put(requestParams.get(k)[0], requestParams.get(v)[0]);
        }
    }

    if (!found) {
        throw new CMBException(CMBErrorCodes.MissingParameter,
                "The request must contain the parameter Attribute.Name");
    }

    return filterRequests;
}

From source file:com.wavemaker.runtime.server.ServerUtils.java

/**
 * Merge parameters from fileMap (if it exists) and parametersMap. All parameters are returned in Object[], even
 * those from fileMap./* w ww.  java 2  s  . co m*/
 * 
 * @param request The original request.
 * @return A merged map of all parameters.
 */
@SuppressWarnings("unchecked")
public static Map<String, Object[]> mergeParams(HttpServletRequest request) {

    Map<String, Object[]> params = new HashMap<String, Object[]>();
    // Set<Map.Entry<?, ?>> entries;
    Set<Map.Entry<String, MultipartFile>> entries;

    if (request instanceof MultipartHttpServletRequest) {
        MultipartHttpServletRequest mrequest = (MultipartHttpServletRequest) request;
        entries = mrequest.getFileMap().entrySet();
        for (Map.Entry<?, ?> e : entries) {
            params.put((String) e.getKey(), new Object[] { e.getValue() });
        }
    }

    entries = request.getParameterMap().entrySet();
    for (Map.Entry<?, ?> e : entries) {
        String key = (String) e.getKey();
        Object[] value = (Object[]) e.getValue();
        if (params.get(key) == null) {
            params.put(key, (Object[]) e.getValue());
        } else {
            Object[] newArray = new Object[value.length + params.get(key).length];
            System.arraycopy(params.get(key), 0, newArray, 0, params.get(key).length);
            System.arraycopy(value, 0, newArray, params.get(key).length, value.length);
            params.put(key, newArray);
        }
    }

    return params;
}

From source file:fr.paris.lutece.util.bean.BeanUtil.java

/**
 * Populate a bean using parameters in http request
 * //from   ww  w .  j a va 2  s  .  co m
 * @param bean bean to populate
 * @param request http request
 */
public static void populate(Object bean, HttpServletRequest request) {
    for (Field field : bean.getClass().getDeclaredFields()) {
        try {
            // for all boolean field, init to false
            if (field.getType().getName().equals(Boolean.class.getName())
                    || field.getType().getName().equals(boolean.class.getName())) {
                field.setAccessible(true);
                field.set(bean, false);
            }
        } catch (Exception e) {
            String error = "La valeur du champ " + field.getName() + " de la classe "
                    + bean.getClass().getName() + " n'a pas pu tre rcupr ";
            AppLogService.error(error);
            throw new RuntimeException(error, e);
        }
    }

    try {
        BeanUtils.populate(bean, convertMap(request.getParameterMap()));
    } catch (IllegalAccessException e) {
        AppLogService.error("Unable to fetch data from request", e);
    } catch (InvocationTargetException e) {
        AppLogService.error("Unable to fetch data from request", e);
    }
}

From source file:org.ow2.chameleon.everest.servlet.EverestServlet.java

public static DefaultRequest translate(HttpServletRequest request) {

    String debug = System.getProperty(DEBUG_SERVLET);
    if (debug != null && debug.equalsIgnoreCase("true")) {
        //Trace/*from   www.ja  v  a2  s.c  om*/
        System.out.println("Path info : " + request.getPathInfo());
        //End Trace
    }

    Path path = Path.from(request.getPathInfo());

    Action action;
    if (isGet(request) || isHead(request)) {
        action = Action.READ;
    } else if (isPut(request)) {
        action = Action.CREATE;
    } else if (isPost(request)) {
        action = Action.UPDATE;
    } else if (isDelete(request)) {
        action = Action.DELETE;
    } else {
        return null; // Unsupported request.
    }

    Map<String, ?> params = flat(request.getParameterMap());

    return new DefaultRequest(action, path, params); // TODO Detect JSON.
}

From source file:org.frontcache.core.FCUtils.java

/**
 * /*  w w  w  .  j  ava  2 s.c o m*/
 * @param request
 * @return
 */
public static String getRequestURL(HttpServletRequest request) {
    String requestURL = request.getRequestURL().toString();

    if ("GET".equals(request.getMethod())) {
        // add parameters for storing 
        // POST method parameters are not stored because they can be huge (e.g. file upload)
        StringBuffer sb = new StringBuffer(requestURL);
        if (!request.getParameterMap().isEmpty())
            sb.append("?").append(request.getQueryString());

        requestURL = sb.toString();
    }
    return requestURL;
}

From source file:com.openmeap.util.ServletUtils.java

/**
 * //w  w  w  . j  a v  a 2s  .  co m
 * @param settings
 * @param request
 * @return
 */
static final public Map<Object, Object> cloneParameterMap(Integer maxFileUploadSize, String fileStoragePrefix,
        HttpServletRequest request) {

    // make a tidy package of parameters for the DocumentProcessor
    Map<Object, Object> map = new HashMap<Object, Object>();

    // check for file uploads
    String contentType = request.getContentType();

    if (contentType != null && contentType.startsWith(FormConstants.ENCTYPE_MULTIPART_FORMDATA)) {

        try {
            ServletUtils.handleFileUploads(maxFileUploadSize, fileStoragePrefix, request, map);
        } catch (FileUploadException fue) {
            // TODO: switch over to an error page and pass an event such that the exception is intelligently communicated
            throw new RuntimeException(fue);
        }
    } else {

        @SuppressWarnings(value = { "unchecked" })
        Map<String, String[]> params = (Map<String, String[]>) request.getParameterMap();
        for (Map.Entry<String, String[]> ent : params.entrySet()) {
            if (ent.getValue() != null) {

                String key = ent.getKey();
                String[] values = new String[ent.getValue().length];
                int i = 0;
                for (String val : ent.getValue()) {
                    values[i++] = val;
                }
                map.put(key, values);
            }
        }
    }

    return map;
}

From source file:com.feilong.servlet.http.RequestUtil.java

/**
 * ? map(? TreeMap).//from ww  w .  ja v  a2  s . c o  m
 * 
 * <p>
 * ?tomcatmap ?TreeMap ?,log;?<span style="color:red">map?</span>
 * </p>
 * 
 * <h3>tomcat getParameterMap() <span style="color:red">locked</span>(?):</h3>
 * 
 * <blockquote>
 * ?:tomcat , {@code org.apache.catalina.util#ParameterMap<K, V>},tomcat?,map?locked,<br>
 * <p>
 * ??map??.?,?,WebLogic,Tomcat,Resin,JBoss??.
 * </p>
 * ,??map?:
 * 
 * <ul>
 * <li>{@link Map#clear()}</li>
 * <li>{@link Map#put(Object, Object)}</li>
 * <li>{@link Map#putAll(Map)}</li>
 * <li>{@link Map#remove(Object)}</li>
 * </ul>
 * 
 * </blockquote>
 * 
 * @param request
 *            the request
 * @return the parameter map
 * @see "org.apache.catalina.connector.Request#getParameterMap()"
 */
public static Map<String, String[]> getParameterMap(HttpServletRequest request) {
    // http://localhost:8888/s.htm?keyword&a=
    // ?  map key  keyword,a 

    return sortMapByKeyAsc(request.getParameterMap()); // servlet 3.0   Map<String, String[]>
}

From source file:com.baidu.rigel.biplatform.ma.report.utils.QueryUtils.java

/**
 * //from  w  ww. jav a 2  s  .c o  m
 * @param params
 * @param request
 * @return Map<String, String>
 */
private static Map<String, String> collectRequestParams(Collection<ReportParam> params,
        HttpServletRequest request) {
    Map<String, String> rs = Maps.newHashMap();
    request.getParameterMap().forEach((k, v) -> {
        rs.put(k, v[0]);
    });
    // cookie??url?
    if (request.getCookies() != null) {
        for (Cookie cookie : request.getCookies()) {
            rs.put(cookie.getName(), cookie.getValue());
        }
    }

    // ???cookie?
    rs.putAll(ContextManager.getParams());
    // ???
    rs.remove(Constants.RANDOMCODEKEY);
    rs.remove(Constants.TOKEN);
    rs.remove(Constants.BIPLATFORM_PRODUCTLINE);

    return rs;
}