List of usage examples for javax.servlet.http HttpServletRequest getCharacterEncoding
public String getCharacterEncoding();
From source file:org.jkcsoft.web.struts.http.controllers.HttpHelper.java
public static String urlEncode(HttpServletRequest request, String str) throws UnsupportedEncodingException { String retVal = null;/*from w w w . jav a 2 s . c o m*/ retVal = URLEncoder.encode(str, request.getCharacterEncoding()); return retVal; }
From source file:org.jkcsoft.web.struts.http.controllers.HttpHelper.java
public static String urlDecode(HttpServletRequest request, String str) throws UnsupportedEncodingException { String retVal = null;/*ww w . j a v a2s. c om*/ retVal = URLDecoder.decode(str, request.getCharacterEncoding()); return retVal; }
From source file:edu.cornell.mannlib.vitro.webapp.search.controller.UpdateUrisInIndex.java
/** * Get the encoding of the request, default to UTF-8 since that is in the * vitro install instructions to put on the connector. *//*from w w w.j ava 2 s . com*/ private Charset getEncoding(HttpServletRequest req) { String enc = req.getCharacterEncoding(); if (StringUtils.isBlank(enc)) { log.debug("No encoding on POST request, That is acceptable."); enc = "UTF-8"; } else if (enc.length() > 30) { log.debug("Ignoring odd encoding of '" + enc + "'"); enc = "UTF-8"; } else { log.debug("Encoding set on POST request: " + enc); } log.debug("Reading POSTed URIs with encoding " + enc); return Charset.forName(enc); }
From source file:org.biokoframework.http.response.impl.AbstractHttpResponseBuilder.java
/** * @param request/* w ww. ja v a 2 s . c o m*/ * @return the string "; charset=" followed by the charset used in the request or "utf-8" */ protected String withCharsetFrom(HttpServletRequest request) { String charset = request.getCharacterEncoding(); if (StringUtils.isEmpty(charset)) { return "; charset=" + "utf-8"; } else { return "; charset=" + charset; } }
From source file:org.seasar.mayaa.impl.MayaaServlet.java
protected void setupCharacterEncoding(HttpServletRequest request, String encoding) { if (request.getCharacterEncoding() == null) { try {/*from www . j a va2s.co m*/ request.setCharacterEncoding(encoding); } catch (UnsupportedEncodingException e) { String message = StringUtil.getMessage(MayaaServlet.class, 0, encoding); LOG.warn(message, e); } } }
From source file:ee.jaaaar.dreamestate.core.StreamingMultipartResolver.java
/** * Determine the encoding for the given request. * Can be overridden in subclasses./* ww w. ja va2s . c o m*/ * <p>The default implementation checks the request encoding, * falling back to the default encoding specified for this resolver. * * @param request current HTTP request * @return the encoding for the request (never <code>null</code>) * @see javax.servlet.ServletRequest#getCharacterEncoding */ protected String determineEncoding(HttpServletRequest request) { String encoding = request.getCharacterEncoding(); if (encoding == null) { encoding = "UTF-8"; } return encoding; }
From source file:org.springframework.http.server.reactive.ServletServerHttpRequest.java
private static HttpHeaders initHeaders(HttpServletRequest request) { HttpHeaders headers = new HttpHeaders(); for (Enumeration<?> names = request.getHeaderNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); for (Enumeration<?> values = request.getHeaders(name); values.hasMoreElements();) { headers.add(name, (String) values.nextElement()); }//from w ww . j a v a 2s . com } MediaType contentType = headers.getContentType(); if (contentType == null) { String requestContentType = request.getContentType(); if (StringUtils.hasLength(requestContentType)) { contentType = MediaType.parseMediaType(requestContentType); headers.setContentType(contentType); } } if (contentType != null && contentType.getCharset() == null) { String encoding = request.getCharacterEncoding(); if (StringUtils.hasLength(encoding)) { Charset charset = Charset.forName(encoding); Map<String, String> params = new LinkedCaseInsensitiveMap<>(); params.putAll(contentType.getParameters()); params.put("charset", charset.toString()); headers.setContentType(new MediaType(contentType.getType(), contentType.getSubtype(), params)); } } if (headers.getContentLength() == -1) { int contentLength = request.getContentLength(); if (contentLength != -1) { headers.setContentLength(contentLength); } } return headers; }
From source file:com.enonic.cms.web.filter.CharacterEncodingFilter.java
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (request.getCharacterEncoding() == null) { request.setCharacterEncoding(encoding); }/*w w w. ja va 2 s . co m*/ final String forcedCharset = request.getParameter("_charset"); if (!StringUtils.isBlank(forcedCharset)) { response.setCharacterEncoding(forcedCharset); } else { response.setCharacterEncoding(encoding); } filterChain.doFilter(request, response); }
From source file:org.apache.shindig.gadgets.servlet.RpcServlet.java
private String getRequestCharacterEncoding(HttpServletRequest request) { String encoding = request.getCharacterEncoding(); if (encoding == null) { encoding = "UTF-8"; }// w w w . j a v a2 s.c om return encoding; }
From source file:org.biokoframework.http.fields.impl.JsonFieldsParser.java
@Override public Fields safelyParse(HttpServletRequest request) throws RequestNotSupportedException { Reader reader;/* ww w . j a v a 2 s . c o m*/ try { if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("utf-8"); } reader = request.getReader(); Writer writer = new StringWriter(); IOUtils.copy(reader, writer); return Fields.fromJson(writer.toString()); } catch (IOException exception) { // TODO log exception throw new RequestNotSupportedException(exception); } }