List of usage examples for javax.servlet ServletRequest getParameterMap
public Map<String, String[]> getParameterMap();
From source file:org.openrepose.powerfilter.PowerFilterChain.java
public void startFilterChain(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) servletRequest; boolean addTraceHeader = traceRequest(request); boolean useTrace = addTraceHeader || (filterTimer != null); tracer = new RequestTracer(useTrace, addTraceHeader); currentFilters = getFilterChainForRequest(request.getRequestURI()); filterChainAvailable = isCurrentFilterChainAvailable(); servletRequest.setAttribute("filterChainAvailableForRequest", filterChainAvailable); servletRequest.setAttribute("http://openrepose.org/requestUrl", ((HttpServletRequest) servletRequest).getRequestURL().toString()); servletRequest.setAttribute("http://openrepose.org/queryParams", servletRequest.getParameterMap()); MutableHttpServletRequest wrappedRequest = MutableHttpServletRequest .wrap((HttpServletRequest) servletRequest); splitRequestHeaders(wrappedRequest); doFilter(wrappedRequest, servletResponse); }
From source file:org.sonar.plugins.openid.OpenIdValidationFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { ParameterList responseParameters = new ParameterList(request.getParameterMap()); HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String receivingURL = requestUrl(httpRequest); UserDetails user;//from ww w.j ava 2 s. c om try { user = openIdClient.verify(receivingURL, responseParameters); } catch (RuntimeException e) { LoggerFactory.getLogger(OpenIdValidationFilter.class).error("Fail to verify OpenId request", e); throw e; } if (user == null) { httpResponse.sendRedirect("/openid/unauthorized"); } else { request.setAttribute(USER_ATTRIBUTE, user); filterChain.doFilter(request, response); } }
From source file:org.sonatype.nexus.extdirect.internal.ExtDirectServlet.java
@Override protected RequestRouter createRequestRouter(final Registry registry, final GlobalConfiguration globalConfiguration) { final Dispatcher dispatcher = createDispatcher(globalConfiguration.getDispatcherClass()); return new RequestRouter(registry, globalConfiguration, dispatcher) { @Override//w w w.j a v a2s .c o m public void processPollRequest(final Reader reader, final Writer writer, final String pathInfo) throws IOException { new PollRequestProcessor(registry, dispatcher, globalConfiguration) { @Override // HACK: we determine parameters from request not by reading request content as request content could had // been already read exactly for getting the params, case when request content is already empty protected Object[] getParameters() { if (reader instanceof RequestBoundReader) { ServletRequest request = ((RequestBoundReader) reader).getRequest(); Map<String, String[]> parameterMap = request.getParameterMap(); Map<String, String> parameters = Maps.newHashMap(); if (parameterMap != null) { parameters = Maps.transformEntries(parameterMap, new EntryTransformer<String, String[], String>() { @Override public String transformEntry(@Nullable final String key, @Nullable final String[] values) { return values == null || values.length == 0 ? null : values[0]; } }); } return new Object[] { parameters }; } return super.getParameters(); } }.process(reader, writer, pathInfo); } }; }
From source file:org.wings.recorder.Recorder.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { try {//from w w w .j av a 2 s. c o m if (servletRequest instanceof HttpServletRequest) { HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; Map map = servletRequest.getParameterMap(); if (map.containsKey(RECORDER_SCRIPT)) { log.info("recorder_script " + map.get(RECORDER_SCRIPT)); String[] values = (String[]) map.get(RECORDER_SCRIPT); scriptName = values[0]; } if (map.containsKey(RECORDER_START)) { if (list != null) return; log.info(RECORDER_START); list = new LinkedList(); } else if (map.containsKey(RECORDER_STOP)) { if (list == null) return; log.info(RECORDER_STOP); writeCode(); list = null; } else if (list != null) { String resource = httpServletRequest.getPathInfo(); log.debug("PATH_INFO: " + resource); Request record; if ("GET".equalsIgnoreCase(httpServletRequest.getMethod())) record = new GET(resource); else record = new POST(resource); Enumeration parameterNames = httpServletRequest.getParameterNames(); while (parameterNames.hasMoreElements()) { String name = (String) parameterNames.nextElement(); String[] values = httpServletRequest.getParameterValues(name); addEvent(record, name, values); } Enumeration headerNames = httpServletRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); if (name.equalsIgnoreCase("cookie") || name.equalsIgnoreCase("referer")) continue; addHeader(record, name, httpServletRequest.getHeader(name)); } list.add(record); } } } finally { if (servletResponse instanceof HttpServletResponse) { filterChain.doFilter(servletRequest, new HttpServletResponseWrapper((HttpServletResponse) servletResponse) { public ServletOutputStream getOutputStream() throws IOException { final ServletOutputStream out = super.getOutputStream(); return new ServletOutputStream() { public void write(int b) throws IOException { out.write(b); } public void close() throws IOException { super.println("<hr/><div align=\"center\">"); super.println("<form method=\"get\" action=\"\">"); super.println("<input type=\"text\" name=\"recorder_script\" value=\"" + scriptName + "\">"); super.println( "<input type=\"submit\" name=\"recorder_start\" value=\"start\">"); super.println( "<input type=\"submit\" name=\"recorder_stop\" value=\"stop\">"); super.println("</div></form>"); super.close(); } }; } }); } else filterChain.doFilter(servletRequest, servletResponse); } }
From source file:org.yes.cart.web.filter.payment.BasePaymentGatewayCallBackFilter.java
/** * {@inheritDoc}/*from w ww.ja va 2 s.c o m*/ */ public ServletRequest doBefore(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IOException, ServletException { final String callbackDump = HttpUtil.dumpRequest((HttpServletRequest) servletRequest); if (isCallerIpAllowed(servletRequest)) { if (LOG.isDebugEnabled()) { LOG.debug(callbackDump); } final Map parameters = servletRequest.getParameterMap(); final PaymentGatewayCallback callback = paymentCallBackHandlerFacade.registerCallback(parameters, paymentGatewayLabel, ShopCodeContext.getShopCode(), callbackDump); try { paymentCallBackHandlerFacade.handlePaymentCallback(callback); ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_OK); } catch (OrderException e) { LOG.error("Transition failed during payment call back for " + paymentGatewayLabel + " payment gateway", e); LOG.error(callbackDump); // Send 500, so that PG know that there was an issue and may resend the update ((HttpServletResponse) servletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } else { if (LOG.isWarnEnabled()) { LOG.warn(Markers.alert(), "Received payment gateway callback from unauthorised IP {}", ipResolver.resolve((HttpServletRequest) servletRequest)); LOG.warn(callbackDump); } // Send forbidden to notify PG that this is a security issue and not error of any kind ((HttpServletResponse) servletResponse).sendError(HttpServletResponse.SC_FORBIDDEN); } return null; //no forwarding, just return }
From source file:servlets.test_servlets.SynonymsServlet.java
/** * Service for the Synonyms servlet//from w ww .j a v a 2 s. c o m * * @param req Required Parameters: * term: The term to find synonyms for * Optional Parameters: * scored: The terms will have scores attached * related: Terms will be minimally related (zeroes will be filtered) * @param res Response will contain a list of synonyms or scored synonyms * @throws ServletException * @throws IOException */ @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { String term = StringUtils.trim(req.getParameter("term")); Map<String, String[]> params = req.getParameterMap(); String response; if (!params.containsKey("scored")) { // If you just want unscored synonyms. Set synonyms = SynonymAdapter.getSynonyms(term); response = JsonCreator.toJson(synonyms); } else { // If you want minimally related terms if (params.containsKey("related")) { List<ScoredTerm> synonyms = SynonymAdapter.getScoredSynonymsWithMinimalRelation(term); response = JsonCreator.toJson(synonyms); } else { // If you want to include everything with the scores List<ScoredTerm> synonyms = SynonymAdapter.getScoredSynonymsWithUnrelatedIncluded(term); response = JsonCreator.toJson(synonyms); } } ResponseUtils.printResponse(res, response); }