List of usage examples for javax.servlet.http HttpServletRequest getParameterMap
public Map<String, String[]> getParameterMap();
From source file:eu.europeana.core.util.web.ClickStreamLoggerImpl.java
@Override public void logBriefResultView(HttpServletRequest request, BriefBeanView briefBeanView, SolrQuery solrQuery, ModelAndView page) {//w w w.ja va2 s . co m String query = briefBeanView.getPagination().getPresentationQuery().getUserSubmittedQuery(); // String queryConstraints = ""; if (solrQuery.getFilterQueries() != null) { queryConstraints = StringUtils.join(solrQuery.getFilterQueries(), ","); } // String pageId; // private String state; UserAction userAction = UserAction.BRIEF_RESULT; Map params = request.getParameterMap(); if (params.containsKey("bt")) { if (request.getParameter("bt").equalsIgnoreCase("savedSearch")) { userAction = UserAction.BRIEF_RESULT_FROM_SAVED_SEARCH; } } else if (params.containsKey("rtr") && request.getParameter("rtr").equalsIgnoreCase("true")) { userAction = UserAction.RETURN_TO_RESULTS; } int pageNr = briefBeanView.getPagination().getPageNumber(); int nrResults = briefBeanView.getPagination().getNumFound(); String languageFacets = briefBeanView.getFacetLogs().get("LANGUAGE"); String countryFacet = briefBeanView.getFacetLogs().get("COUNTRY"); log.info(MessageFormat.format( "[action={0}, view={1}, query={2}, queryType={7}, queryConstraints=\"{3}\", page={4}, " + "numFound={5}, langFacet={8}, countryFacet={9}, {6}]", userAction, page.getViewName(), query, queryConstraints, pageNr, nrResults, printLogAffix(request), solrQuery.getQueryType(), languageFacets, countryFacet)); }
From source file:com.formkiq.core.service.workflow.WorkflowServiceImpl.java
@Override public ModelAndView actions(final HttpServletRequest request, final HttpServletResponse response) throws IOException { WebFlow flow = FlowManager.get(request); Map<String, String[]> parameterMap = request.getParameterMap(); if (parameterMap.containsKey("_eventId_print")) { return getModelAndView(flow, DEFAULT_PDF_VIEW); }/*from w ww . j ava 2 s . c o m*/ byte[] bytes = generatePDF(request, flow); response.setContentType("application/pdf"); response.setContentLengthLong(bytes.length); IOUtils.write(bytes, response.getOutputStream()); response.getOutputStream().flush(); return null; }
From source file:edu.stanford.muse.webapp.JSPHelper.java
public static String getRequestParamsAsString(HttpServletRequest request) { // could probably also do it by looking at request url etc. String requestParams = ""; Map<String, String[]> rpmap = request.getParameterMap(); for (String key : rpmap.keySet()) for (String value : rpmap.get(key)) // rpmap has a string array for each param requestParams += (key + '=' + value + "&"); return requestParams; }
From source file:com.concursive.connect.web.portal.ProjectPortalURLParserImpl.java
/** * Parse a servlet request to a portal URL. * * @param request the servlet request to parse. * @return the portal URL./*from w w w. j av a 2 s . co m*/ */ public PortalURL parse(HttpServletRequest request) { LOG.debug("Parsing URL: " + request.getRequestURI()); StringBuffer url = new StringBuffer(); // Build the URL from various items... if (request.getParameterMap() != null) { String action = request.getParameter("portlet-action"); String projectValue = request.getParameter("portlet-pid"); String object = request.getParameter("portlet-object"); String value = request.getParameter("portlet-value"); String params = request.getParameter("portlet-params"); // Append the portlet action // @note TEST TEST TEST //url.append("/").append(action); url.append("/").append(StringUtils.encodeUrl(action)); // Append the targeted profile Project project = ProjectUtils.loadProject(Integer.parseInt(projectValue)); url.append("/").append(project.getUniqueId()); // Append the object in the profile // @note TEST TEST TEST //url.append("/").append(object); url.append("/").append(StringUtils.encodeUrl(object)); // Append any object value, like object id if (StringUtils.hasText(value)) { url.append("/").append(StringUtils.encodeUrl(value)); } // Append any parameters if (StringUtils.hasText(params)) { // @note TEST TEST TEST //url.append("/").append(params); url.append("/").append(StringUtils.encodeUrl(params)); } LOG.debug("reconstructed url: " + url.toString()); } String servletName = url.toString(); // Construct portal URL using info retrieved from servlet request. String contextPath = request.getContextPath(); LOG.debug("contextPath: " + contextPath); PortalURL portalURL = new RelativePortalURLImpl(contextPath, servletName, getParser()); // Action window definition: portalURL.setActionWindow(). String portletAction = request.getParameter("portletAction"); if (portletAction != null && portletAction.startsWith(PREFIX + ACTION)) { LOG.debug("found action"); portalURL.setActionWindow(decodeControlParameter(portletAction)[0]); portalURL.setRenderPath(contextPath + "."); } // Window state definition: portalURL.setWindowState(). String portletWindowState = null; int windowStateCount = 0; while ((portletWindowState = request.getParameter("portletWindowState" + (++windowStateCount))) != null) { String[] decoded = decodeControlParameter(portletWindowState); portalURL.setWindowState(decoded[0], new WindowState(decoded[1])); } // Portlet mode definition: portalURL.setPortletMode(). String portletMode = request.getParameter("portletMode"); if (portletMode != null) { String[] decoded = decodeControlParameter(portletMode); portalURL.setPortletMode(decoded[0], new PortletMode(decoded[1])); } // Portal URL parameter: portalURL.addParameter(). Enumeration params = request.getParameterNames(); while (params.hasMoreElements()) { String parameter = (String) params.nextElement(); if (parameter.startsWith(PREFIX + RENDER_PARAM)) { String value = request.getParameter(parameter); LOG.debug("parameter: " + parameter); portalURL.addParameter(decodeParameter(parameter, value)); } } // Return the portal URL. return portalURL; }
From source file:io.hops.hopsworks.api.kibana.KibanaProxyServlet.java
/** * Authorize user to access particular index. * * @param servletRequest//from w ww .j a v a2s . c o m * @param servletResponse * @throws ServletException * @throws IOException */ @Override protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (servletRequest.getUserPrincipal() == null) { servletResponse.sendError(401, "User is not logged in"); return; } String email = servletRequest.getUserPrincipal().getName(); if (servletRequest.getParameterMap().containsKey("projectId")) { String projectId = servletRequest.getParameterMap().get("projectId")[0]; try { ProjectDTO projectDTO = projectController.getProjectByID(Integer.parseInt(projectId)); currentProjects.put(email, projectDTO.getProjectName()); } catch (ProjectException ex) { LOG.log(Level.SEVERE, null, ex); servletResponse.sendError(403, "Kibana was not accessed from Hopsworks, no current project information is available."); return; } } //Do not authorize admin if (email.equals(Settings.AGENT_EMAIL)) { super.service(servletRequest, servletResponse); return; } MyRequestWrapper myRequestWrapper = new MyRequestWrapper((HttpServletRequest) servletRequest); KibanaFilter kibanaFilter = null; //Filter requests based on path if (servletRequest.getRequestURI().contains("api/saved_objects")) { kibanaFilter = KibanaFilter.KIBANA_SAVED_OBJECTS_API; } else if (servletRequest.getRequestURI().contains("elasticsearch/*/_search")) { kibanaFilter = KibanaFilter.ELASTICSEARCH_SEARCH; } else if (servletRequest.getRequestURI().contains("legacy_scroll_start") || servletRequest.getRequestURI().contains("settings/defaultIndex")) { return; } //initialize request attributes from caches if unset by a subclass by this point if (servletRequest.getAttribute(ATTR_TARGET_URI) == null) { servletRequest.setAttribute(ATTR_TARGET_URI, targetUri); } if (servletRequest.getAttribute(ATTR_TARGET_HOST) == null) { servletRequest.setAttribute(ATTR_TARGET_HOST, targetHost); } // Make the Request //note: we won't transfer the protocol version because I'm not sure it would truly be compatible String method = servletRequest.getMethod(); String proxyRequestUri = rewriteUrlFromRequest(servletRequest); HttpRequest proxyRequest; //spec: RFC 2616, sec 4.3: either of these two headers signal that there is a message body. if (servletRequest.getHeader(HttpHeaders.CONTENT_LENGTH) != null || servletRequest.getHeader(HttpHeaders.TRANSFER_ENCODING) != null) { HttpEntityEnclosingRequest eProxyRequest = new BasicHttpEntityEnclosingRequest(method, proxyRequestUri); // Add the input entity (streamed) // note: we don't bother ensuring we close the servletInputStream since the container handles it eProxyRequest.setEntity( new InputStreamEntity(myRequestWrapper.getInputStream(), servletRequest.getContentLength())); proxyRequest = eProxyRequest; } else { proxyRequest = new BasicHttpRequest(method, proxyRequestUri); } copyRequestHeaders(servletRequest, proxyRequest); super.setXForwardedForHeader(servletRequest, proxyRequest); HttpResponse proxyResponse = null; try { // Execute the request LOG.log(Level.FINE, "proxy " + method + " uri: " + servletRequest.getRequestURI() + " -- " + proxyRequest.getRequestLine().getUri()); proxyResponse = super.proxyClient.execute(super.getTargetHost(myRequestWrapper), proxyRequest); // Process the response int statusCode = proxyResponse.getStatusLine().getStatusCode(); if (doResponseRedirectOrNotModifiedLogic(myRequestWrapper, servletResponse, proxyResponse, statusCode)) { //the response is already "committed" now without any body to send //TODO copy response headers? return; } // Pass the response code. This method with the "reason phrase" is // deprecated but it's the only way to pass the reason along too. //noinspection deprecation servletResponse.setStatus(statusCode, proxyResponse.getStatusLine().getReasonPhrase()); copyResponseHeaders(proxyResponse, servletRequest, servletResponse); // Send the content to the client copyResponseEntity(proxyResponse, servletResponse, kibanaFilter, email); } catch (Exception e) { //abort request, according to best practice with HttpClient if (proxyRequest instanceof AbortableHttpRequest) { AbortableHttpRequest abortableHttpRequest = (AbortableHttpRequest) proxyRequest; abortableHttpRequest.abort(); } if (e instanceof RuntimeException) { throw (RuntimeException) e; } if (e instanceof ServletException) { throw (ServletException) e; } //noinspection ConstantConditions if (e instanceof IOException) { throw (IOException) e; } throw new RuntimeException(e); } finally { // make sure the entire entity was consumed, so the connection is released if (proxyResponse != null) { consumeQuietly(proxyResponse.getEntity()); } //Note: Don't need to close servlet outputStream: // http://stackoverflow.com/questions/1159168/should-one-call-close-on- //httpservletresponse-getoutputstream-getwriter } }
From source file:com.sourcesense.confluence.servlets.CMISProxyServlet.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 om*/ @SuppressWarnings({ "unchecked", "ToArrayCallWithZeroLengthArrayArgument" }) private void handleStandardPost(PostMethod postMethodProxyRequest, HttpServletRequest httpServletRequest) { // 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()) { // Iterate the values for each parameter name String[] stringArrayParameterValues = mapPostParameters.get(stringParameterName); for (String stringParamterValue : stringArrayParameterValues) { // Create a NameValuePair and store in list NameValuePair nameValuePair = new NameValuePair(stringParameterName, stringParamterValue); listNameValuePairs.add(nameValuePair); } } // Set the proxy request POST data postMethodProxyRequest.setRequestBody(listNameValuePairs.toArray(new NameValuePair[] {})); }
From source file:mx.edu.um.mateo.inventario.web.FacturaAlmacenController.java
@SuppressWarnings("unchecked") @RequestMapping/* w w w . jav a 2s. c o m*/ public String lista(HttpServletRequest request, HttpServletResponse response, Usuario usuario, Errors errors, Model modelo) throws ParseException { log.debug("Mostrando lista de facturas"); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Map<String, Object> params = this.convierteParams(request.getParameterMap()); Long almacenId = (Long) request.getSession().getAttribute("almacenId"); params.put("almacen", almacenId); if (params.containsKey("fechaIniciado")) { log.debug("FechaIniciado: {}", params.get("fechaIniciado")); params.put("fechaIniciado", sdf.parse((String) params.get("fechaIniciado"))); } if (params.containsKey("fechaTerminado")) { params.put("fechaTerminado", sdf.parse((String) params.get("fechaTerminado"))); } if (params.containsKey("tipo") && StringUtils.isNotBlank((String) params.get("tipo"))) { params.put("reporte", true); params = facturaDao.lista(params); try { generaReporte((String) params.get("tipo"), (List<FacturaAlmacen>) params.get("facturas"), response, "facturasAlmacen", Constantes.ALM, almacenId); return null; } catch (ReporteException e) { log.error("No se pudo generar el reporte", e); params.remove("reporte"); errors.reject("error.generar.reporte"); } } if (params.containsKey("correo") && StringUtils.isNotBlank((String) params.get("correo"))) { params.put("reporte", true); params = facturaDao.lista(params); params.remove("reporte"); try { enviaCorreo((String) params.get("correo"), (List<FacturaAlmacen>) params.get("facturas"), request, "facturasAlmacen", Constantes.ALM, almacenId); modelo.addAttribute("message", "lista.enviada.message"); modelo.addAttribute("messageAttrs", new String[] { messageSource.getMessage("facturaAlmacen.lista.label", null, request.getLocale()), ambiente.obtieneUsuario().getUsername() }); } catch (ReporteException e) { log.error("No se pudo enviar el reporte por correo", e); } } params = facturaDao.lista(params); modelo.addAttribute("facturas", params.get("facturas")); Long pagina = 1l; if (params.containsKey("pagina")) { pagina = (Long) params.get("pagina"); } this.pagina(params, modelo, "facturas", pagina); return "inventario/factura/lista"; }
From source file:cherry.foundation.springmvc.OperationLogHandlerInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { Principal principal = request.getUserPrincipal(); if (principal == null) { SecurityContext context = SecurityContextHolder.getContext(); if (context != null) { principal = context.getAuthentication(); }//w ww . j ava 2s.c o m } if (principal != null) { MDC.put(LOGIN_ID, principal.getName()); } StringBuilder builder = createBasicInfo(request); builder.append(" {"); boolean first = true; for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) { String key = entry.getKey(); String lkey = key.toLowerCase(); String[] val = entry.getValue(); if (!first) { builder.append(", "); } first = false; builder.append(key).append(": "); if (lkey.contains("password")) { builder.append("<MASKED>"); } else { builder.append(ToStringBuilder.reflectionToString(val, ToStringStyle.SIMPLE_STYLE)); } for (int i = 0; i < paramPattern.size(); i++) { if (paramPattern.get(i).matcher(lkey).matches()) { if (val != null && val.length == 1) { MDC.put(paramMdcKey.get(i), val[0]); } else { MDC.put(paramMdcKey.get(i), ToStringBuilder.reflectionToString(val, ToStringStyle.SIMPLE_STYLE)); } } } } builder.append("}"); loggerEnter.info(builder.toString()); return true; }
From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.ProxyServlet.java
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { LOGGER.debug("ProxyServlet - GET"); StringBuilder uri = new StringBuilder(500); uri.append(getTargetUri());//w w w . j a va2s.c om // Handle the path given to the servlet if (servletRequest.getPathInfo() != null) {//ex: /my/path.html uri.append(servletRequest.getPathInfo()); } LOGGER.debug("uri: " + uri.toString()); try { String response = servicesClient.proxyGet(uri.toString(), getQueryParamsFromURI(servletRequest.getParameterMap())); servletResponse.getWriter().write(response); } catch (ClientException e) { e.printStackTrace(); } }
From source file:ro.raisercostin.web.DebuggingFilter.java
public String debug(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, DebuggingPrinter debuggingPrinter, boolean debugAll, boolean debugRequest) { final JspFactory jspFactory = JspFactory.getDefaultFactory(); HttpSession session = request.getSession(); debuggingPrinter.addHeader();//from w w w . j av a2 s .c om debuggingPrinter.addSection("Request Parameters"); for (Iterator iterator = request.getParameterMap().entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> parameter = (Map.Entry<String, Object>) iterator.next(); addRow(debuggingPrinter, parameter.getKey(), StringUtils.arrayToCommaDelimitedString((Object[]) parameter.getValue())); } debuggingPrinter.endSection(); if (debugRequest) { debuggingPrinter.addSection("Request Header"); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); addRow(debuggingPrinter, parameterName, debuggingPrinter.transform(request.getHeader(parameterName))); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Request Attributes"); java.util.Enumeration en = request.getAttributeNames(); while (en.hasMoreElements()) { String attrName = (String) en.nextElement(); try { addRow(debuggingPrinter, split(attrName, 50), toString2(request.getAttribute(attrName), 120)); } catch (Exception e) { addRow(debuggingPrinter, split(attrName, 50), toString(e, 120)); } } debuggingPrinter.endSection(); debuggingPrinter.addSection("Session Attributes"); en = session.getAttributeNames(); while (en.hasMoreElements()) { String attrName = (String) en.nextElement(); try { addRow(debuggingPrinter, split(attrName, 50), toString2(session.getAttribute(attrName), 120)); } catch (Exception e) { addRow(debuggingPrinter, split(attrName, 50), toString(e, 120)); } } debuggingPrinter.endSection(); debuggingPrinter.addSection("Request Info"); addRow(debuggingPrinter, "AuthType", request.getAuthType()); addRow(debuggingPrinter, "ContextPath", request.getContextPath()); addRow(debuggingPrinter, "Method", request.getMethod()); addRow(debuggingPrinter, "PathInfo", request.getPathInfo()); addRow(debuggingPrinter, "PathTranslated", request.getPathTranslated()); addRow(debuggingPrinter, "Protocol", request.getProtocol()); addRow(debuggingPrinter, "QueryString", request.getQueryString()); addRow(debuggingPrinter, "RemoteAddr", request.getRemoteAddr()); addRow(debuggingPrinter, "RemoteUser", request.getRemoteUser()); addRow(debuggingPrinter, "RequestedSessionId", request.getRequestedSessionId()); addRow(debuggingPrinter, "RequestURI", request.getRequestURI()); addRow(debuggingPrinter, "RequestURL", request.getRequestURL().toString()); addRow(debuggingPrinter, "ServletPath", request.getServletPath()); addRow(debuggingPrinter, "Scheme", request.getScheme()); addRow(debuggingPrinter, "ServletPath", request.getServletPath()); } if (debugAll) { debuggingPrinter.addSection("Server"); addRow(debuggingPrinter, "Server Info", servletContext.getServerInfo()); addRow(debuggingPrinter, "Servlet Engine Version", servletContext.getMajorVersion() + "." + servletContext.getMinorVersion()); addRow(debuggingPrinter, "JSP Version", jspFactory.getEngineInfo().getSpecificationVersion()); debuggingPrinter.endSection(); debuggingPrinter.addSection("JVM Properties"); for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); addRow(debuggingPrinter, parameterName, debuggingPrinter.transform(System.getProperty(parameterName))); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Environment"); for (Map.Entry<String, String> property : System.getenv().entrySet()) { addRow(debuggingPrinter, property.getKey(), debuggingPrinter.transform(property.getValue())); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Debugger Provided by"); addRow(debuggingPrinter, "provided by", "raisercostin"); debuggingPrinter.addRow("source", "<a target='_blank' href='http://code.google.com/p/raisercostin/wiki/DebuggingFilter'>http://code.google.com/p/raisercostin/wiki/DebuggingFilter</a>"); addRow(debuggingPrinter, "version", "1.0"); addRow(debuggingPrinter, "timestamp", "2008.June.14"); addRow(debuggingPrinter, "license", "<a target='_blank' href='http://www.apache.org/licenses/LICENSE-2.0.html'>Apache License 2.0</a>"); debuggingPrinter.endSection(); } debuggingPrinter.addFooter(); return debuggingPrinter.getString(); }