List of usage examples for javax.servlet.http HttpServletRequest getCharacterEncoding
public String getCharacterEncoding();
From source file:com.bluexml.side.framework.alfresco.shareLanguagePicker.CustomWebScriptView.java
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Expose the model object as request attributes. exposeModelAsRequestAttributes(model, request); if (logger.isDebugEnabled()) logger.debug("Processing request (" + request.getMethod() + ") " + request.getRequestURL() + (request.getQueryString() != null ? "?" + request.getQueryString() : "")); if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("UTF-8"); }//from w ww .j ava 2 s .c o m Locale resolveLocale = localeResolver.resolveLocale(request); localeResolver.setLocale(request, response, resolveLocale); // hand off to the WebScript Servlet View runtime WebScriptViewRuntime runtime = new WebScriptViewRuntime(getUrl(), container, authenticatorFactory, request, response, serverProperties); runtime.executeScript(); }
From source file:com.niconico.mylasta.direction.sponsor.NiconicoMultipartRequestHandler.java
protected void addTextParameter(HttpServletRequest request, FileItem item) { final String name = item.getFieldName(); final String encoding = request.getCharacterEncoding(); String value = null;// w w w. j ava2 s .c o m boolean haveValue = false; if (encoding != null) { try { value = item.getString(encoding); haveValue = true; } catch (Exception e) { } } if (!haveValue) { try { value = item.getString("ISO-8859-1"); } catch (java.io.UnsupportedEncodingException uee) { value = item.getString(); } haveValue = true; } if (request instanceof MultipartRequestWrapper) { final MultipartRequestWrapper wrapper = (MultipartRequestWrapper) request; wrapper.setParameter(name, value); } final String[] oldArray = elementsText.get(name); final String[] newArray; if (oldArray != null) { newArray = new String[oldArray.length + 1]; System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); newArray[oldArray.length] = value; } else { newArray = new String[] { value }; } elementsText.put(name, newArray); elementsAll.put(name, newArray); }
From source file:com.concursive.connect.web.controller.servlets.URLControllerServlet.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { LOG.debug("service called"); LOG.debug("requestCharacterEncoding=" + request.getCharacterEncoding()); try {/* w w w. jav a 2 s .co m*/ request.setCharacterEncoding("UTF-8"); } catch (Exception e) { LOG.warn("Unsupported encoding"); } // Check the preferences to see if the correct domain name is being used, else do a redirect ApplicationPrefs prefs = (ApplicationPrefs) request.getSession().getServletContext() .getAttribute("applicationPrefs"); boolean redirect = false; String contextPath = request.getContextPath(); String uri = request.getRequestURI(); String queryString = request.getQueryString(); String path = uri.substring(contextPath.length()) + (queryString == null ? "" : "?" + queryString); LOG.debug("path: " + path); request.setAttribute("requestedURL", path); // It's important the user is using the correct URL for accessing content; // The portal has it's own redirect scheme, this is a another catch all // to see if an old domain name or context is used PortalBean bean = new PortalBean(request); String expectedDomainName = prefs.get(ApplicationPrefs.WEB_DOMAIN_NAME); LOG.debug("expectedDomainName: " + expectedDomainName); LOG.debug("domainName: " + bean.getServerName()); String expectedContext = prefs.get(ApplicationPrefs.WEB_CONTEXT); LOG.debug("expectedContextPath: " + expectedContext); LOG.debug("contextPath: " + contextPath); if (StringUtils.hasText(expectedContext) && !expectedContext.equals(contextPath) || (expectedDomainName != null && path.length() > 0 && !"127.0.0.1".equals(bean.getServerName()) && !"127.0.0.1".equals(expectedDomainName) && !"localhost".equals(bean.getServerName()) && !"localhost".equals(expectedDomainName) && !bean.getServerName().startsWith("10.") && !bean.getServerName().startsWith("172.") && !bean.getServerName().startsWith("192.") && !bean.getServerName().equals(expectedDomainName))) { if (uri.length() > 0 && !uri.substring(1).equals(prefs.get("PORTAL.INDEX"))) { String newUrl = URLFactory.createURL(prefs.getPrefs()) + path; request.setAttribute("redirectTo", newUrl); LOG.debug("redirectTo: " + newUrl); request.removeAttribute(Constants.REQUEST_PAGE_LAYOUT); redirect = true; } } if (redirect) { try { RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/redirect301.jsp"); dispatcher.forward(request, response); } catch (Exception e) { } } else { mapToMVCAction(request, response); } }
From source file:com.easyjf.web.core.FrameworkEngine.java
/** * ?requestform//from w w w. jav a 2s . c om * * @param request * @param formName * @return ??Form */ public static WebForm creatWebForm(HttpServletRequest request, String formName, Module module) { Map textElement = new HashMap(); Map fileElement = new HashMap(); String contentType = request.getContentType(); String reMethod = request.getMethod(); if ((contentType != null) && (contentType.startsWith("multipart/form-data")) && (reMethod.equalsIgnoreCase("post"))) { // multipart/form-data File file = new File(request.getSession().getServletContext().getRealPath("/temp")); if (!file.exists()) { file.getParentFile().mkdirs(); } DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(webConfig.getUploadSizeThreshold()); factory.setRepository(file); ServletFileUpload sf = new ServletFileUpload(factory); sf.setSizeMax(webConfig.getMaxUploadFileSize()); sf.setHeaderEncoding(request.getCharacterEncoding()); List reqPars = null; try { reqPars = sf.parseRequest(request); for (int i = 0; i < reqPars.size(); i++) { FileItem it = (FileItem) reqPars.get(i); if (it.isFormField()) { textElement.put(it.getFieldName(), it.getString(request.getCharacterEncoding()));// ?? } else { fileElement.put(it.getFieldName(), it);// ??? } } } catch (Exception e) { logger.error(e); } } else if ((contentType != null) && contentType.equals("text/xml")) { StringBuffer buffer = new StringBuffer(); try { String s = request.getReader().readLine(); while (s != null) { buffer.append(s + "\n"); s = request.getReader().readLine(); } } catch (Exception e) { logger.error(e); } textElement.put("xml", buffer.toString()); } else { textElement = request2map(request); } // logger.debug("????"); WebForm wf = findForm(formName); wf.setValidate(module.isValidate());// ?validate?Form if (wf != null) { wf.setFileElement(fileElement); wf.setTextElement(textElement); } return wf; }
From source file:org.codelibs.fess.mylasta.direction.sponsor.FessMultipartRequestHandler.java
protected void addTextParameter(final HttpServletRequest request, final FileItem item) { final String name = item.getFieldName(); final String encoding = request.getCharacterEncoding(); String value = null;/* www. ja v a 2 s . c om*/ boolean haveValue = false; if (encoding != null) { try { value = item.getString(encoding); haveValue = true; } catch (final Exception e) { } } if (!haveValue) { try { value = item.getString("ISO-8859-1"); } catch (final java.io.UnsupportedEncodingException uee) { value = item.getString(); } haveValue = true; } if (request instanceof MultipartRequestWrapper) { final MultipartRequestWrapper wrapper = (MultipartRequestWrapper) request; wrapper.setParameter(name, value); } final String[] oldArray = elementsText.get(name); final String[] newArray; if (oldArray != null) { newArray = new String[oldArray.length + 1]; System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); newArray[oldArray.length] = value; } else { newArray = new String[] { value }; } elementsText.put(name, newArray); elementsAll.put(name, newArray); }
From source file:com.asual.summer.core.RequestFilter.java
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { requestHolder.set(request);// w ww.j av a 2 s . c o m HttpServletRequest defaultRequest = new DefaultRequest(request); if (multipartResolver != null && multipartResolver.isMultipart(request)) { defaultRequest = multipartResolver.resolveMultipart(defaultRequest); } try { long time = System.currentTimeMillis(); requestHolder.set(defaultRequest); if (defaultRequest.getCharacterEncoding() == null) { defaultRequest.setCharacterEncoding((String) ResourceUtils.getProperty("app.encoding")); } if (RequestUtils.isTrident()) { response.setHeader("X-UA-Compatible", "IE=Edge,chrome=1"); } filterChain.doFilter(requestHolder.get(), response); logger.debug("The request for '" + defaultRequest.getRequestURI() + "' took " + (System.currentTimeMillis() - time) + "ms."); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (multipartResolver != null && defaultRequest instanceof MultipartHttpServletRequest) { multipartResolver.cleanupMultipart((MultipartHttpServletRequest) defaultRequest); } requestHolder.set(null); } }
From source file:org.esigate.servlet.impl.HttpServletRequestEntity.java
HttpServletRequestEntity(HttpServletRequest request) { this.request = request; String contentLengthHeader = request.getHeader(HttpHeaders.CONTENT_LENGTH); if (contentLengthHeader != null) { length = Long.parseLong(contentLengthHeader); } else {// ww w . j a v a 2s . co m length = -1; } String contentTypeHeader = request.getContentType(); if (contentTypeHeader != null) { this.setContentType(contentTypeHeader); } String contentEncodingHeader = request.getCharacterEncoding(); if (contentEncodingHeader != null) { this.setContentEncoding(contentEncodingHeader); } }
From source file:com.googlesource.gerrit.plugins.gitblit.auth.GerritAuthenticationFilter.java
public boolean filterBasicAuth(HttpServletRequest request, HttpServletResponse response, String hdr) throws IOException, UnsupportedEncodingException { if (!hdr.startsWith(LIT_BASIC)) { response.setHeader("WWW-Authenticate", "Basic realm=\"Gerrit Code Review\""); response.sendError(SC_UNAUTHORIZED); return false; }//from w w w. j av a 2 s . co m final byte[] decoded = new Base64().decode(hdr.substring(LIT_BASIC.length()).getBytes()); String encoding = request.getCharacterEncoding(); if (encoding == null) { encoding = "UTF-8"; } String usernamePassword = new String(decoded, encoding); int splitPos = usernamePassword.indexOf(':'); if (splitPos < 1) { response.setHeader("WWW-Authenticate", "Basic realm=\"Gerrit Code Review\""); response.sendError(SC_UNAUTHORIZED); return false; } request.setAttribute("gerrit-username", usernamePassword.substring(0, splitPos)); request.setAttribute("gerrit-password", usernamePassword.substring(splitPos + 1)); return true; }
From source file:org.oscarehr.common.printing.HtmlToPdfServlet.java
private byte[] convertToPdf(HttpServletRequest req, String content) throws IOException, FileNotFoundException { File contentFile = File.createTempFile("pdfservlet.", ".html"); contentFile.deleteOnExit();// w ww . ja va 2 s. c o m OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(contentFile)); IOUtils.write(content, os, req.getCharacterEncoding()); } finally { if (os != null) IOUtils.closeQuietly(os); } byte[] pdf = WKHtmlToPdfUtils.convertToPdf(contentFile.getAbsolutePath()); return pdf; }
From source file:org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionMedia.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w .j ava2 s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs * @throws CerberusException */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException { String charset = request.getCharacterEncoding(); String type = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("type"), "", charset); String test = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("test"), "", charset); String testcase = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testcase"), "", charset); String fileName = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("filename"), "", charset); String fileType = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("filetype"), "", charset); String fileDesc = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("filedesc"), "", charset); int step = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("step"), 0, charset); int index = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("index"), 1, charset); int sequence = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("sequence"), 0, charset); int sequenceControl = ParameterParserUtil .parseIntegerParamAndDecode(request.getParameter("sequenceControl"), 0, charset); int iterator = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("iterator"), 0, charset); boolean autoContentType = ParameterParserUtil.parseBooleanParam(request.getParameter("autoContentType"), true); long id = ParameterParserUtil.parseLongParamAndDecode(request.getParameter("id"), 0, charset); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IParameterService parameterService = appContext.getBean(IParameterService.class); BufferedImage b = null; AnswerList al = new AnswerList<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED)); TestCaseExecutionFile tceFile = null; if (!(fileName.equals(""))) { IFactoryTestCaseExecutionFile factoryTestCaseExecutionFile = appContext .getBean(IFactoryTestCaseExecutionFile.class); tceFile = factoryTestCaseExecutionFile.create(0, 0, "", fileDesc, fileName, fileType, "", null, "", null); } else { ITestCaseExecutionFileService testCaseExecutionFileService = appContext .getBean(ITestCaseExecutionFileService.class); String levelFile = ""; if (type.equals("action")) { levelFile = test + "-" + testcase + "-" + step + "-" + index + "-" + sequence; } else if (type.equals("control")) { levelFile = test + "-" + testcase + "-" + step + "-" + index + "-" + sequence + "-" + sequenceControl; } al = testCaseExecutionFileService.readByVarious(id, levelFile); if (al.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && !al.getDataList().isEmpty()) { Iterator i = al.getDataList().iterator(); int indexIterator = -1; while (i.hasNext() && indexIterator != iterator) { indexIterator++; TestCaseExecutionFile tctemp = (TestCaseExecutionFile) i.next(); if (indexIterator == iterator) { tceFile = tctemp; } } } else { // If previous read failed we try without index. (that can be removed few moths after step index has been introduced in Jan 2017) if (type.equals("action")) { levelFile = test + "-" + testcase + "-" + step + "-" + sequence; } else if (type.equals("control")) { levelFile = test + "-" + testcase + "-" + step + "-" + sequence + "-" + sequenceControl; } al = testCaseExecutionFileService.readByVarious(id, levelFile); if (al.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && !al.getDataList().isEmpty()) { Iterator i = al.getDataList().iterator(); int indexIterator = -1; while (i.hasNext() && indexIterator != iterator) { indexIterator++; TestCaseExecutionFile tctemp = (TestCaseExecutionFile) i.next(); if (indexIterator == iterator) { tceFile = tctemp; } } } } } if (tceFile != null) { String pathString = parameterService.getParameterStringByKey("cerberus_mediastorage_path", "", ""); switch (tceFile.getFileType()) { case "JPG": case "PNG": case "GIF": case "JPEG": returnImage(request, response, tceFile, pathString); break; case "HTML": if (autoContentType) { response.setContentType("text/html"); } returnFile(request, response, tceFile, pathString); break; case "XML": if (autoContentType) { response.setContentType("application/xml"); } returnFile(request, response, tceFile, pathString); break; case "JSON": if (autoContentType) { response.setContentType("application/json"); } returnFile(request, response, tceFile, pathString); break; case "TXT": returnFile(request, response, tceFile, pathString); break; default: returnNotSupported(request, response, tceFile, pathString); } } }