Example usage for javax.servlet.http HttpServletRequest getParameterNames

List of usage examples for javax.servlet.http HttpServletRequest getParameterNames

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterNames.

Prototype

public Enumeration<String> getParameterNames();

Source Link

Document

Returns an Enumeration of String objects containing the names of the parameters contained in this request.

Usage

From source file:com.adito.applications.actions.LaunchApplicationAction.java

protected ActionForward launch(ActionMapping mapping, LaunchSession launchSession, HttpServletRequest request,
        String returnTo) throws Exception {
    ApplicationShortcut shortcut = (ApplicationShortcut) launchSession.getResource();
    ExtensionDescriptor descriptor = ExtensionStore.getInstance()
            .getExtensionDescriptor(shortcut.getApplication());
    HashMap<String, String> parameters = new HashMap<String, String>();
    Enumeration e = request.getParameterNames();
    while (e.hasMoreElements()) {
        String nameParam = (String) e.nextElement();
        parameters.put(nameParam, request.getParameter(nameParam));
    }//  w  ww  .  ja v  a  2 s.  co m

    // Do the launch
    try {
        if (descriptor.getApplicationBundle().getStatus() != ExtensionBundleStatus.ACTIVATED) {
            throw new Exception("Extension bundle " + descriptor.getApplicationBundle().getId()
                    + " is not activated, cannot launch applicaiton.");
        }
        ActionForward fwd = ((ApplicationLauncherType) descriptor.getExtensionType()).launch(parameters,
                descriptor, shortcut, mapping, launchSession, returnTo, request);

        CoreServlet.getServlet().fireCoreEvent(new ResourceAccessEvent(this,
                ApplicationShortcutEventConstants.APPLICATION_SHORTCUT_LAUNCHED, launchSession.getResource(),
                launchSession.getPolicy(), launchSession.getSession(), CoreEvent.STATE_SUCCESSFUL)
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_NAME, descriptor.getName())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_ID, descriptor.getId()));

        /*
         * If the launch implementation returns its own forward, it is
         * reponsible for setting up its 'launched' message
         */
        if (fwd == null) {
            ActionMessages msgs = new ActionMessages();
            msgs.add(Globals.MESSAGE_KEY, new BundleActionMessage(ApplicationsPlugin.MESSAGE_RESOURCES_KEY,
                    "launchApplication.launched", shortcut.getResourceName()));
            saveMessages(request, msgs);
            return new RedirectWithMessages(returnTo, request);
        }
        return fwd;
    } catch (Exception ex) {
        CoreServlet.getServlet().fireCoreEvent(new ResourceAccessEvent(this,
                ApplicationShortcutEventConstants.APPLICATION_SHORTCUT_LAUNCHED, launchSession.getSession(), ex)
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_NAME, descriptor.getName())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_ID, descriptor.getId()));
        throw ex;

    }
}

From source file:org.geomajas.gwt2.example.base.server.mvc.AjaxProxyController.java

@RequestMapping(value = "/")
public final void proxyAjaxCall(@RequestParam(required = true, value = "url") String url,
        HttpServletRequest request, HttpServletResponse response) throws IOException {

    // URL needs to be url decoded
    url = URLDecoder.decode(url, "utf-8");

    HttpClient client = new DefaultHttpClient();
    try {//  ww  w  . j  a va 2s.  c o  m
        HttpRequestBase proxyRequest;

        // Split this according to the type of request
        if ("GET".equals(request.getMethod())) {
            Enumeration<?> paramNames = request.getParameterNames();
            while (paramNames.hasMoreElements()) {
                String paramName = (String) paramNames.nextElement();
                if (!paramName.equalsIgnoreCase("url")) {
                    url = addParam(url, paramName, request.getParameter(paramName));
                }
            }

            proxyRequest = new HttpGet(url);
        } else if ("POST".equals(request.getMethod())) {
            proxyRequest = new HttpPost(url);

            // Set any eventual parameters that came with our original
            HttpParams params = new BasicHttpParams();
            Enumeration<?> paramNames = request.getParameterNames();
            while (paramNames.hasMoreElements()) {
                String paramName = (String) paramNames.nextElement();
                if (!"url".equalsIgnoreCase("url")) {
                    params.setParameter(paramName, request.getParameter(paramName));
                }
            }
            proxyRequest.setParams(params);
        } else {
            throw new NotImplementedException("This proxy only supports GET and POST methods.");
        }

        // Execute the method
        HttpResponse proxyResponse = client.execute(proxyRequest);

        // Set the content type, as it comes from the server
        Header[] headers = proxyResponse.getAllHeaders();
        for (Header header : headers) {
            if ("Content-Type".equalsIgnoreCase(header.getName())) {
                response.setContentType(header.getValue());
            }
        }

        // Write the body, flush and close
        proxyResponse.getEntity().writeTo(response.getOutputStream());
    } catch (IOException e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:com.pureinfo.tgirls.servlet.TestServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    System.out.println("=================parameter from request====================");
    Enumeration ereq = request.getParameterNames();
    while (ereq.hasMoreElements()) {
        String name = (String) ereq.nextElement();
        System.out.println(name + "[" + request.getParameter(name) + "]");
    }// w  w w .j  a  v  a 2 s  .c  o m
    System.out.println("=================end====================");

    String userTabaoId = request.getParameter("id");

    if (StringUtils.isEmpty(userTabaoId)) {
        userTabaoId = "1";
    }
    try {
        IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class);
        User _loginUser = mgr.getUserByTaobaoId(userTabaoId);

        addCookie(_loginUser, request, response);

        Cookie[] cookies = request.getCookies();

        if (cookies == null) {
            System.out.println("=====cookie is null=======");
        } else {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = cookies[i];
                System.out.println("cookie[" + i + "]:[" + cookie.getName() + ":" + cookie.getValue() + "("
                        + cookie.getMaxAge() + ")]");
            }

        }

        //request.getSession().setAttribute(ArkHelper.ATTR_LOGIN_USER, _loginUser);

        System.out.println("loginuser:" + _loginUser);

        response.sendRedirect(request.getContextPath());
        return;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace(System.err);
    }

}

From source file:cz.strmik.cmmitool.web.controller.MethodController.java

private RuleAggregation getRulesFromRequest(Set<RatingScale> scales, HttpServletRequest request) {
    RuleAggregation ra = new RuleAggregation();
    ra.setSources(new HashSet<ScaleRule>());
    ra.setTargets(new HashSet<ScaleRule>());
    for (RatingScale scale : scales) {
        Enumeration en = request.getParameterNames();
        ScaleRule rule = null;/* ww w  .ja  v  a 2s  .  c  o m*/
        while (en.hasMoreElements()) {
            String attrName = (String) en.nextElement();
            if (attrName.startsWith(scale.getId().toString())) {
                rule = new ScaleRule();
                rule.setScale(scale);
                rule.setRuleCompletion(RuleCompletion.valueOf(request.getParameter(attrName)));

                if (attrName.endsWith("-source")) {
                    ra.getSources().add(rule);
                }
                if (attrName.endsWith("-target")) {
                    ra.getTargets().add(rule);
                }
            }
        }
    }
    return ra;
}

From source file:com.autentia.intra.servlet.ReportServlet.java

private Map getParametersAsMapAndSubReport(HttpServletRequest request, String reportCategory,
        JasperReport subReport) throws Exception {
    Map args = new HashMap();
    Enumeration e = request.getParameterNames();
    while (e.hasMoreElements()) {
        String arg = (String) e.nextElement();
        final String value = request.getParameter(arg);
        Object obj = null;//from w  w  w  .j ava 2  s.  co m
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date value_date = sdf.parse(value);
            java.sql.Timestamp ts = new Timestamp(value_date.getTime());

            obj = ts;
        } catch (Exception ex) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date value_date = sdf.parse(value);
                obj = value_date;
            } catch (Exception ex2) {
                try {
                    Integer value_int = Integer.parseInt(value);
                    obj = value_int;
                } catch (Exception ex3) {
                    obj = value;
                    if (value != null && "".equals(value)) {
                        obj = null;
                    }
                }
            }
        }

        if (arg.startsWith("SUBREPORT")) {
            if (reportCategory.equals("personal/")) {
                String path = ConfigurationUtil.getDefault().getReportPath();
                String target = path + SUBREPORT_PREFIX + obj;
                if (null == getClass().getClassLoader().getResource(target + REPORT_DEFINITION_SUFFIX)) {
                    JasperCompileManager.compileReportToFile(target + REPORT_DEFINITION_SUFFIX);
                }
                subReport = (JasperReport) JRLoader.loadObject(target + REPORT_SUFFIX);
                obj = target + REPORT_SUFFIX;
            } else {
                String destino = REPORT_PREFIX + reportCategory + SUBREPORT_PREFIX + obj + REPORT_SUFFIX;
                if (null == getResourceAsURL(destino)) {
                    JasperCompileManager.compileReportToFile(getResourceAsString(REPORT_PREFIX + reportCategory
                            + SUBREPORT_PREFIX + obj + REPORT_DEFINITION_SUFFIX));
                }

                subReport = (JasperReport) JRLoader.loadObject(getResourceAsURL(destino));
                obj = destino;
            }
        }
        args.put(arg, obj);
    }

    return args;
}

From source file:geotheme.servlet.wms.java

/**
 * @see HttpServlet#service(HttpServletRequest req, HttpServletResponse res)
 *//*w  w  w  .j av  a2 s.  com*/
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    OutputStreamWriter wr = null;
    InputStream in = null;
    OutputStream out = null;

    //req.setCharacterEncoding("UTF-8");

    try {
        Map<String, Object> reqMap = new HashMap<String, Object>();

        Enumeration<?> en = req.getParameterNames();
        String key = new String();

        /**
         * Converting all Map Keys into Upper Case
         **/
        while (en.hasMoreElements()) {
            key = (String) en.nextElement();
            reqMap.put(key.toUpperCase(), req.getParameter(key));
        }

        wmsParamBean wmsBean = new wmsParamBean();
        BeanUtils.populate(wmsBean, reqMap);

        HttpSession session = req.getSession(true);

        /**
         * Reading the saved SLD
         **/
        String sessionName = wmsBean.getLAYER();

        if (sessionName.length() < 1)
            sessionName = wmsBean.getLAYERS();

        if (session.getAttribute(sessionName) != null) {

            wmsBean.setSLD_BODY((String) session.getAttribute(sessionName));
            wmsBean.setSLD("");
            wmsBean.setSTYLES("");
        }

        if (wmsBean.getREQUEST().compareToIgnoreCase("GetPDFGraphic") == 0) {
            /**
             * Generate PDF Request
             */
            generatePDF pdf = new generatePDF(this.pdfURL, this.pdfLayers);

            ByteArrayOutputStream baos = pdf.createPDFFromImage(wmsBean, this.geoserverURL);

            res.addHeader("Content-Type", "application/force-download");
            res.addHeader("Content-Disposition", "attachment; filename=\"MapOutput.pdf\"");

            res.getOutputStream().write(baos.toByteArray());
        } else {
            /**
             * Generating Map from GeoServer
             **/
            URL geoURL = new URL(this.geoserverURL);

            URLConnection geoConn = geoURL.openConnection();
            geoConn.setDoOutput(true);

            wr = new OutputStreamWriter(geoConn.getOutputStream(), "UTF-8");
            wr.write(wmsBean.getURL_PARAM());
            wr.flush();

            in = geoConn.getInputStream();
            out = res.getOutputStream();

            res.setContentType(wmsBean.getFORMAT());

            int b;
            while ((b = in.read()) != -1) {
                out.write(b);
            }
        }
    } catch (Exception e) {
        //e.printStackTrace();
    } finally {
        if (out != null) {
            out.flush();
            out.close();
        }
        if (in != null) {
            in.close();
        }
        if (wr != null) {
            wr.close();
        }
    }
}

From source file:com.adito.boot.Util.java

/**
 * Dump all request parameters to {@link System#err}
 * //  w w  w  .ja  v a  2 s .co  m
 * @param request request to get parameters from
 */
public static void dumpRequestParameters(HttpServletRequest request) {
    System.err.println("Request parameters for session #" + request.getSession().getId());
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
        String n = (String) e.nextElement();
        String[] vals = request.getParameterValues(n);
        for (int i = 0; i < vals.length; i++) {
            System.err.println("   " + n + " = " + vals[i]);
        }
    }

}

From source file:fr.paris.lutece.portal.web.user.AuthenticationFilter.java

/**
 * Build the url to redirect to if not logged. This is actually the login page of the authentication module, completed with the request parameters.
 * // www.  ja v  a 2  s . c  o m
 * @param request
 *            the http request
 * @return the string representation of the redirection url - absolute - with request parameters.
 */
private String getRedirectUrl(HttpServletRequest request) {
    String strLoginUrl = getLoginUrl(request);

    if (strLoginUrl == null) {
        return null;
    }

    UrlItem url = new UrlItem(strLoginUrl);

    Enumeration<String> enumParams = request.getParameterNames();

    String strParamName;

    while (enumParams.hasMoreElements()) {
        strParamName = enumParams.nextElement();

        if (!strParamName.equals(Parameters.ACCESS_CODE) && !strParamName.equals(Parameters.PASSWORD)
                && !strParamName.equals(SecurityTokenService.PARAMETER_TOKEN)) {
            url.addParameter(strParamName, request.getParameter(strParamName));
        }
    }

    return url.getUrl();
}

From source file:info.magnolia.debug.DumpHeadersFilter.java

@Override
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    long nr = count++;
    LoggingResponse wrappedResponse = new LoggingResponse(response);
    log.info("{} uri: {}", Long.toString(nr), request.getRequestURI());
    log.info("{} session: {}", Long.toString(nr), Boolean.valueOf(request.getSession(false) != null));

    StringBuffer params = new StringBuffer();
    for (Enumeration paramEnum = request.getParameterNames(); paramEnum.hasMoreElements();) {
        String name = (String) paramEnum.nextElement();
        params.append(name).append(" = ").append(StringUtils.join(request.getParameterValues(name), ","));
        if (paramEnum.hasMoreElements()) {
            params.append("; ");
        }// w ww  . j a  va2  s.co  m
    }
    log.info("{} parameters: {}", Long.toString(nr), params);
    log.info("{} method: {}", Long.toString(nr), request.getMethod());
    for (Enumeration en = request.getHeaderNames(); en.hasMoreElements();) {
        String name = (String) en.nextElement();
        log.info("{} header: {}={}", new String[] { String.valueOf(nr), name, request.getHeader(name) });
    }
    chain.doFilter(request, wrappedResponse);
    log.info("{} response status: {}", Long.toString(nr), Integer.toString(wrappedResponse.getStatus()));
    log.info("{} response length: {}", Long.toString(nr), Long.toString(wrappedResponse.getLength()));
    log.info("{} response mime type: {}", Long.toString(nr), wrappedResponse.getContentType());
    for (Iterator iter = wrappedResponse.getHeaders().keySet().iterator(); iter.hasNext();) {
        String name = (String) iter.next();
        log.info(request.getRequestURI() + " response: " + name + " = "
                + wrappedResponse.getHeaders().get(name));
    }
}

From source file:com.dvdprime.server.mobile.filter.JerseyServletLoggingFilter.java

private Map<String, String> getTypesafeRequestMap(HttpServletRequest request) {

    Map<String, String> typesafeRequestMap = new HashMap<String, String>();

    Enumeration<?> requestParamNames = request.getParameterNames();

    while (requestParamNames.hasMoreElements()) {

        String requestParamName = (String) requestParamNames.nextElement();

        String requestParamValue = request.getParameter(requestParamName);

        typesafeRequestMap.put(requestParamName, requestParamValue);

    }/*from  www  .  j a  va2 s  .  c o m*/

    return typesafeRequestMap;
}