List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:com.googlecode.psiprobe.controllers.sessions.RemoveSessAttributeController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String sid = ServletRequestUtils.getStringParameter(request, "sid"); String attrName = ServletRequestUtils.getStringParameter(request, "attr"); Session session = context.getManager().findSession(sid); if (session != null) { session.getSession().removeAttribute(attrName); }/*from w ww. j av a2 s . c o m*/ return new ModelAndView( new RedirectView(request.getContextPath() + getViewName() + "?" + request.getQueryString())); }
From source file:org.esigate.servlet.impl.RequestFactory.java
public IncomingRequest create(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException { HttpServletRequestContext context = new HttpServletRequestContext(request, response, servletContext, filterChain);/* w ww. j ava 2 s. c o m*/ // create request line String uri = UriUtils.createURI(request.getScheme(), request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString(), null); ProtocolVersion protocolVersion = BasicLineParser.parseProtocolVersion(request.getProtocol(), null); IncomingRequest.Builder builder = IncomingRequest .builder(new BasicRequestLine(request.getMethod(), uri, protocolVersion)); builder.setContext(context); // copy headers @SuppressWarnings("rawtypes") Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); @SuppressWarnings("rawtypes") Enumeration values = request.getHeaders(name); while (values.hasMoreElements()) { String value = (String) values.nextElement(); builder.addHeader(name, value); } } // create entity HttpServletRequestEntity entity = new HttpServletRequestEntity(request); builder.setEntity(entity); builder.setRemoteAddr(request.getRemoteAddr()); builder.setRemoteUser(request.getRemoteUser()); HttpSession session = request.getSession(false); if (session != null) { builder.setSessionId(session.getId()); } builder.setUserPrincipal(request.getUserPrincipal()); // Copy cookies // As cookie header contains only name=value so we don't need to copy // all attributes! javax.servlet.http.Cookie[] src = request.getCookies(); if (src != null) { for (int i = 0; i < src.length; i++) { javax.servlet.http.Cookie c = src[i]; BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue()); builder.addCookie(dest); } } builder.setSession(new HttpServletSession(request)); builder.setContextPath(request.getContextPath()); return builder.build(); }
From source file:fr.aliasource.webmail.server.invitation.GetInvitationInfoProxyImpl.java
@SuppressWarnings("unchecked") @Override/*from ww w. ja v a 2 s . com*/ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { IAccount ac = (IAccount) req.getSession().getAttribute("account"); if (ac == null) { GWT.log("Account not found in session", null); resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } PostMethod pm = new PostMethod(backendUrl); if (req.getQueryString() != null) { pm.setQueryString(req.getQueryString()); } Map<String, String[]> params = req.getParameterMap(); for (String p : params.keySet()) { String[] val = params.get(p); pm.setParameter(p, val[0]); } synchronized (hc) { try { int ret = hc.executeMethod(pm); if (ret != HttpStatus.SC_OK) { log("method failed:\n" + pm.getStatusLine() + "\n" + pm.getResponseBodyAsString()); resp.setStatus(ret); } else { InputStream is = pm.getResponseBodyAsStream(); transfer(is, resp.getOutputStream(), false); } } catch (Exception e) { log("error occured on call proxyfication", e); } finally { pm.releaseConnection(); } } }
From source file:com.openmeap.admin.web.servlet.AdminServlet.java
@SuppressWarnings("unchecked") @Override//w w w. j a v a 2 s. c om public void service(HttpServletRequest request, HttpServletResponse response) { logger.trace("Entering service()"); try { DocumentProcessor documentProcessor = null; logger.debug("Request uri: {}", request.getRequestURI()); logger.debug("Request url: {}", request.getRequestURL()); logger.debug("Query string: {}", request.getQueryString()); if (logger.isDebugEnabled()) { logger.debug("Parameter map: {}", ParameterMapUtils.toString(request.getParameterMap())); } if (request.getParameter("logout") != null) { logger.trace("Executing logout"); request.getSession().invalidate(); response.sendRedirect(request.getContextPath() + "/interface/"); } if (request.getParameter("refreshContext") != null && context instanceof AbstractApplicationContext) { logger.trace("Refreshing context"); ((AbstractApplicationContext) context).refresh(); } // support for clearing the persistence context if (request.getParameter("clearPersistenceContext") != null && context instanceof AbstractApplicationContext) { logger.trace("Clearing the persistence context"); ModelServiceImpl ms = (ModelServiceImpl) ((AbstractApplicationContext) context) .getBean("modelService"); ms.clearPersistenceContext(); } // default to the mainOptionPage, unless otherwise specified String pageBean = null; if (request.getParameter(FormConstants.PAGE_BEAN) != null) pageBean = request.getParameter(FormConstants.PAGE_BEAN); else pageBean = FormConstants.PAGE_BEAN_MAIN; logger.debug("Using page bean: {}", pageBean); documentProcessor = (DocumentProcessor) context.getBean(pageBean); ModelManager mgr = getModelManager(); Map<Object, Object> map = new HashMap<Object, Object>(); // TODO: I'm not really happy with this hacky work-around for the login form not being in actual request scope if (documentProcessor.getProcessesFormData()) { GlobalSettings settings = mgr.getGlobalSettings(); map = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), settings.getTemporaryStoragePath(), request); map.put("userPrincipalName", new String[] { request.getUserPrincipal().getName() }); AuthorizerImpl authorizer = (AuthorizerImpl) context.getBean("authorizer"); authorizer.setRequest(request); } response.setContentType(FormConstants.CONT_TYPE_HTML); Map<Object, Object> defaultTemplateVars = new HashMap<Object, Object>(); defaultTemplateVars.put("request", new BeanModel(request, new DefaultObjectWrapper())); documentProcessor.setTemplateVariables(defaultTemplateVars); documentProcessor.handleProcessAndRender(map, response.getWriter()); response.getWriter().flush(); response.getWriter().close(); } catch (IOException te) { throw new RuntimeException(te); } logger.trace("Leaving service()"); }
From source file:com.tremolosecurity.proxy.ProxyRequest.java
public ProxyRequest(HttpServletRequest req, HttpSession session) throws Exception { super(req);/* ww w . j a va 2s . co m*/ this.session = session; ServletRequestContext reqCtx = new ServletRequestContext(req); this.isMultiPart = "POST".equalsIgnoreCase(req.getMethod()) && reqCtx.getContentType() != null && reqCtx.getContentType().toLowerCase(Locale.ENGLISH).startsWith("multipart/form-data"); this.isParamsInBody = true; this.isPush = false; this.paramList = new ArrayList<String>(); this.reqParams = new HashMap<String, ArrayList<String>>(); this.queryString = new ArrayList<NVP>(); HttpServletRequest request = (HttpServletRequest) super.getRequest(); if (request.getQueryString() != null && !request.getQueryString().isEmpty()) { StringTokenizer toker = new StringTokenizer(request.getQueryString(), "&"); while (toker.hasMoreTokens()) { String qp = toker.nextToken(); int index = qp.indexOf('='); if (index > 0) { String name = qp.substring(0, qp.indexOf('=')); String val = URLDecoder.decode(qp.substring(qp.indexOf('=') + 1), "UTf-8"); this.queryString.add(new NVP(name, val)); } } } if (this.isMultiPart) { this.isPush = true; // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(req); this.reqFiles = new HashMap<String, ArrayList<FileItem>>(); for (FileItem item : items) { //this.paramList.add(item.getName()); if (item.isFormField()) { ArrayList<String> vals = this.reqParams.get(item.getFieldName()); if (vals == null) { vals = new ArrayList<String>(); this.reqParams.put(item.getFieldName(), vals); } this.paramList.add(item.getFieldName()); vals.add(item.getString()); } else { ArrayList<FileItem> vals = this.reqFiles.get(item.getFieldName()); if (vals == null) { vals = new ArrayList<FileItem>(); this.reqFiles.put(item.getFieldName(), vals); } vals.add(item); } } } else { Enumeration enumer = req.getHeaderNames(); String contentType = null; while (enumer.hasMoreElements()) { String name = (String) enumer.nextElement(); if (name.equalsIgnoreCase("content-type") || name.equalsIgnoreCase("content-length")) { this.isPush = true; if (name.equalsIgnoreCase("content-type")) { contentType = req.getHeader(name); } } } if (this.isPush) { if (contentType == null || !contentType.startsWith("application/x-www-form-urlencoded")) { this.isParamsInBody = false; ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream in = req.getInputStream(); int len; byte[] buffer = new byte[1024]; while ((len = in.read(buffer)) > 0) { baos.write(buffer, 0, len); } req.setAttribute(ProxySys.MSG_BODY, baos.toByteArray()); } else if (contentType.startsWith("application/x-www-form-urlencoded")) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream in = req.getInputStream(); int len; byte[] buffer = new byte[1024]; while ((len = in.read(buffer)) > 0) { baos.write(buffer, 0, len); } StringTokenizer toker = new StringTokenizer(new String(baos.toByteArray()), "&"); this.orderedList = new ArrayList<NVP>(); while (toker.hasMoreTokens()) { String token = toker.nextToken(); int index = token.indexOf('='); String name = token.substring(0, index); if (name.indexOf('%') != -1) { name = URLDecoder.decode(name, "UTF-8"); } String val = ""; if (index < (token.length() - 1)) { val = URLDecoder.decode(token.substring(token.indexOf('=') + 1), "UTF-8"); } this.orderedList.add(new NVP(name, val)); this.paramList.add(name); ArrayList<String> params = this.reqParams.get(name); if (params == null) { params = new ArrayList<String>(); this.reqParams.put(name, params); } params.add(val); } } } } }
From source file:fr.aliasource.webmail.server.calendar.CalendarProxyImpl.java
@SuppressWarnings("unchecked") @Override//from w w w . ja v a2 s .c o m protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { IAccount ac = (IAccount) req.getSession().getAttribute("account"); if (ac == null) { GWT.log("Account not found in session", null); resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } PostMethod pm = new PostMethod(backendUrl); if (req.getQueryString() != null) { pm.setQueryString(req.getQueryString()); } Map<String, String[]> params = req.getParameterMap(); for (String p : params.keySet()) { String[] val = params.get(p); pm.setParameter(p, val[0]); } synchronized (hc) { try { int ret = hc.executeMethod(pm); if (ret != HttpStatus.SC_OK) { log("method failed:\n" + pm.getStatusLine() + "\n" + pm.getResponseBodyAsString()); resp.setStatus(ret); } else { InputStream is = pm.getResponseBodyAsStream(); transfer(is, resp.getOutputStream(), false); } } catch (Exception e) { log("error occured on call proxyfication", e); } finally { pm.releaseConnection(); } } }
From source file:fr.aliasource.webmail.server.invitation.GoingInvitationProxyImpl.java
@SuppressWarnings("unchecked") @Override/*ww w .j a v a2 s. co m*/ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { IAccount ac = (IAccount) req.getSession().getAttribute("account"); if (ac == null) { GWT.log("Account not found in session", null); resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } PostMethod pm = new PostMethod(backendUrl); if (req.getQueryString() != null) { pm.setQueryString(req.getQueryString()); } Map<String, String[]> params = req.getParameterMap(); for (String p : params.keySet()) { String[] val = params.get(p); pm.setParameter(p, val[0]); } synchronized (hc) { try { int ret = hc.executeMethod(pm); if (ret != HttpStatus.SC_OK) { log("method failed:\n" + pm.getStatusLine() + "\n" + pm.getResponseBodyAsString()); resp.setStatus(ret); } else { InputStream is = pm.getResponseBodyAsStream(); transfer(is, resp.getOutputStream(), false); } } catch (Exception e) { log("error occured on call proxyfication", e); } finally { pm.releaseConnection(); } } }
From source file:com.netspective.sparx.util.HttpServletResponseCache.java
public void cacheResponse(long servletLastModf, HttpServletRequest req, ResponseCache res) { synchronized (pageCache) { String cacheKey = req.getServletPath() + req.getPathInfo() + req.getQueryString(); pageCache.put(cacheKey, new CacheData(res, servletLastModf, req.getServletPath(), req.getPathInfo(), req.getQueryString()));/* w w w .j ava2s . co m*/ } }
From source file:psiprobe.controllers.sessions.RemoveSessAttributeController.java
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String sid = ServletRequestUtils.getStringParameter(request, "sid"); String attrName = ServletRequestUtils.getStringParameter(request, "attr"); Session session = context.getManager().findSession(sid); if (session != null) { session.getSession().removeAttribute(attrName); }/*from w w w.j a va 2 s .c o m*/ return new ModelAndView( new RedirectView(request.getContextPath() + getViewName() + "?" + request.getQueryString())); }
From source file:es.itecban.deployment.executionmanager.gui.swf.service.DeletePlanCreationManager.java
private String getXMLDependencyGraphURL(HttpServletRequest request, String unitName, String unitVersion, String selectedEnv, String containerGraphList) throws Exception { String file = request.getRequestURI(); file = file.substring(0, file.indexOf("/", file.indexOf("/") + 1)); if (request.getQueryString() != null) { // file += '?' + // request.getQueryString()+"&_eventId_getXMLGraph=true&name="+unitName+"&version="+unitVersion+"&environment="+selectedEnv; file += "/unitInverseDependencies.htm" + '?' + "name=" + unitName + "&version=" + unitVersion + "&environment=" + selectedEnv.replace(' ', '+') + "&justGraph=true" + "&containerGraphList=" + containerGraphList;//from w w w . ja va 2 s. c o m } URL reconstructedURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), file); return (reconstructedURL.toString()).substring(request.getScheme().length(), (reconstructedURL.toString().length())); }