List of usage examples for javax.servlet.http HttpServletRequestWrapper getRequest
public ServletRequest getRequest()
From source file:com.flexive.faces.FxJsfUtils.java
/** * Gets the request from the faces context. * <p/>/*from w w w. ja va 2s . co m*/ * The result is null if no faces context is available. * * @return the request from the faces context */ public static FxRequest getRequest() { try { HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) getCurrentInstance() .getExternalContext().getRequest(); while (wrapper != null && !(wrapper instanceof FxRequest)) { wrapper = (HttpServletRequestWrapper) wrapper.getRequest(); } return (FxRequest) wrapper; } catch (Throwable t) { return null; } }
From source file:com.alibaba.citrus.service.requestcontext.parser.impl.ParameterParserImpl.java
/** * ??/*w w w.j a v a2s. c om*/ * <p> * ???.~htmlHTML??? * </p> */ private void postProcessParams() { HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) requestContext.getRequest(); HttpServletRequest wrappedRequest = (HttpServletRequest) wrapper.getRequest(); boolean[] filtering = null; if (!isEmptyArray(filters)) { filtering = new boolean[filters.length]; for (int i = 0; i < filters.length; i++) { filtering[i] = filters[i].isFiltering(wrappedRequest); } } String[] keys = getKeys(); List<String> keysToRemove = createLinkedList(); for (String key : keys) { if (key.endsWith(htmlFieldSuffix)) { keysToRemove.add(key); key = key.substring(0, key.length() - htmlFieldSuffix.length()); if (!containsKey(key)) { setObjects(key, processValues(key, true, filtering)); } continue; } boolean isHtml = !StringUtil.isBlank(getString(key + htmlFieldSuffix)); setObjects(key, processValues(key, isHtml, filtering)); } for (String key : keysToRemove) { remove(key); } }
From source file:com.alibaba.citrus.service.requestcontext.parser.impl.ParameterParserImpl.java
/** requestparametersmultipart-form? */ public ParameterParserImpl(ParserRequestContext requestContext, UploadService upload, boolean trimming, ParameterParserFilter[] filters, String htmlFieldSuffix) { super(requestContext); this.upload = upload; this.trimming = trimming; this.filters = filters; this.htmlFieldSuffix = htmlFieldSuffix; HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) requestContext.getRequest(); HttpServletRequest wrappedRequest = (HttpServletRequest) wrapper.getRequest(); boolean isMultipart = false; // upload/*from ww w .j a v a 2s . c o m*/ if (requestContext.isAutoUpload() && upload != null) { // multipart/*upload service?? isMultipart = upload.isMultipartContent(wrappedRequest); if (isMultipart) { try { parseUpload(); } catch (UploadSizeLimitExceededException e) { add(ParserRequestContext.UPLOAD_FAILED, Boolean.TRUE); add(ParserRequestContext.UPLOAD_SIZE_LIMIT_EXCEEDED, Boolean.TRUE); log.warn("File upload exceeds the size limit", e); } catch (UploadException e) { add(ParserRequestContext.UPLOAD_FAILED, Boolean.TRUE); log.warn("Upload failed", e); } } } // request?? if (!isMultipart) { String method = wrappedRequest.getMethod(); // URL?US-ASCII?URL? // ????? // // ? // 1. ???????? // GBK?????GBK?methodGETPOST // // 2. ???URL????? // Windowsiefirefox?GBK // macsafarifirefox?UTF-8 // // ?? // 1. Tomcatserver.xml<Connector URIEncoding="xxx">??GET?8859_1 // 2. JettyUTF-8??GET? // 3. POSTrequest.setCharacterEncoding("xxx")?8859_1 // 4. Tomcat5?<Connector useBodyEncodingForURI="true">GETrequest.setCharacterEncoding("xxx")? // // ???Tomcat/Jetty8859_1UTF-8??URL query? // // ????POST/PUTGET???servlet engine? // ?useServletEngineParser=true if (requestContext.isUseServletEngineParser() || "post".equalsIgnoreCase(method) || "put".equalsIgnoreCase(method)) { parseByServletEngine(wrappedRequest); } else { parseQueryString(requestContext, wrappedRequest); } postProcessParams(); } }
From source file:org.primeframework.mvc.parameter.RequestBodyWorkflow.java
@Override public void perform(WorkflowChain workflowChain) throws IOException, ServletException { // Let the container parse out the GET and POST parameters by calling the getParameterMap method // After this call, if the method is GET with any content-type or POST with the content-type as // x-www-form-urlencoded the InputStream will be empty Map<String, String[]> parameters = request.getParameterMap(); Map<String, List<String>> parsedParameters = null; String contentType = request.getContentType(); if (contentType != null) { contentType = contentType.toLowerCase(); if (contentType.startsWith("multipart/")) { FilesAndParameters filesAndParameters = handleFiles(); request.setAttribute(RequestKeys.FILE_ATTRIBUTE, filesAndParameters.files); parsedParameters = filesAndParameters.parameters; } else if (contentType.startsWith("application/x-www-form-urlencoded")) { parsedParameters = parse(request.getInputStream(), request.getContentLength(), request.getCharacterEncoding()); }/* ww w . j a v a 2 s . co m*/ } if (parsedParameters != null && parsedParameters.size() > 0) { HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request; HttpServletRequest previous = (HttpServletRequest) wrapper.getRequest(); HttpServletRequest newRequest = new ParameterHttpServletRequestWrapper(previous, combine(parameters, parsedParameters)); wrapper.setRequest(newRequest); } workflowChain.continueWorkflow(); }
From source file:org.tinygroup.weblayer.webcontext.parser.valueparser.impl.ParameterParserImpl.java
/** requestparametersmultipart-form? */ public ParameterParserImpl(ParserWebContext webContext, UploadService upload, boolean trimming, ParameterParserFilter[] filters, String htmlFieldSuffix) { super(webContext); this.upload = upload; this.trimming = trimming; this.filters = filters; this.htmlFieldSuffix = htmlFieldSuffix; HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) webContext.getRequest(); HttpServletRequest wrappedRequest = (HttpServletRequest) wrapper.getRequest(); boolean isMultipart = false; // upload/*from w w w .j av a 2s .c om*/ if (webContext.isAutoUpload() && upload != null) { // multipart/*upload service?? isMultipart = upload.isMultipartContent(wrappedRequest); if (isMultipart) { try { parseUpload(); } catch (UploadSizeLimitExceededException e) { add(ParserWebContext.UPLOAD_FAILED, Boolean.TRUE); add(ParserWebContext.UPLOAD_SIZE_LIMIT_EXCEEDED, Boolean.TRUE); logger.errorMessage("File upload exceeds the size limit", e); throw e; } catch (UploadException e) { add(ParserWebContext.UPLOAD_FAILED, Boolean.TRUE); logger.errorMessage("Upload failed", e); throw e; } } } // request?? if (!isMultipart) { String method = wrappedRequest.getMethod(); // URL?US-ASCII?URL? // ????? // // ? // 1. ???????? // GBK?????GBK?methodGETPOST // // 2. ???URL????? // Windowsiefirefox?GBK // macsafarifirefox?UTF-8 // // ?? // 1. Tomcatserver.xml<Connector // URIEncoding="xxx">??GET?8859_1 // 2. JettyUTF-8??GET? // 3. // POSTrequest.setCharacterEncoding("xxx")?8859_1 // 4. Tomcat5?<Connector // useBodyEncodingForURI="true">GETrequest.setCharacterEncoding("xxx")? // // ???Tomcat/Jetty8859_1UTF-8??URL query? // // ????POST/PUTGET???servlet // engine? // ?useServletEngineParser=true if (webContext.isUseServletEngineParser() || "post".equalsIgnoreCase(method) || "put".equalsIgnoreCase(method)) { parseByServletEngine(wrappedRequest); } else { parseQueryString(webContext, wrappedRequest); } postProcessParams(); } }
From source file:org.tinygroup.weblayer.webcontext.parser.valueparser.impl.ParameterParserImpl.java
/** * ??// w w w . ja v a 2 s .com * <p> * ???.~htmlHTML??? * </p> */ private void postProcessParams() { HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) webContext.getRequest(); HttpServletRequest wrappedRequest = (HttpServletRequest) wrapper.getRequest(); boolean[] filtering = null; if (!isEmptyArray(filters)) { filtering = new boolean[filters.length]; for (int i = 0; i < filters.length; i++) { filtering[i] = filters[i].isFiltering(wrappedRequest); } } String[] keys = getKeys(); List<String> keysToRemove = createLinkedList(); for (String key : keys) { if (key.endsWith(htmlFieldSuffix)) { keysToRemove.add(key); key = key.substring(0, key.length() - htmlFieldSuffix.length()); if (!containsKey(key)) { setObjects(key, processValues(key, true, filtering)); } continue; } boolean isHtml = !StringUtil.isBlank(getString(key + htmlFieldSuffix)); setObjects(key, processValues(key, isHtml, filtering)); } for (String key : keysToRemove) { remove(key); } }
From source file:servletunit.struts.MockStrutsTestCase.java
/** * Set this TestCase to use a given HttpServletRequestWrapper * class when calling Action.execute(). Note that if this * method is not called, then the normal HttpServletRequest * object is used./*www . ja v a 2s .c o m*/ * * @param wrapper an HttpServletRequestWrapper object to be * used when calling Action.execute(). */ public void setRequestWrapper(HttpServletRequestWrapper wrapper) { if (logger.isDebugEnabled()) logger.debug("Entering - wrapper = " + wrapper); init(); if (wrapper == null) throw new IllegalArgumentException("wrapper class cannot be null!"); else { if (wrapper.getRequest() == null) wrapper.setRequest(this.request); this.requestWrapper = wrapper; } if (logger.isDebugEnabled()) logger.debug("Exiting"); }