Example usage for javax.servlet.http HttpServletRequest getCharacterEncoding

List of usage examples for javax.servlet.http HttpServletRequest getCharacterEncoding

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getCharacterEncoding.

Prototype

public String getCharacterEncoding();

Source Link

Document

Returns the name of the character encoding used in the body of this request.

Usage

From source file:net.triptech.buildulator.web.BaseController.java

/**
 * Encode the url path segment.//from   ww w .  j  a  v a 2  s  . c o  m
 *
 * @param pathSegment the path segment
 * @param httpServletRequest the http servlet request
 * @return the string
 */
protected String encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest) {

    String enc = httpServletRequest.getCharacterEncoding();
    if (enc == null) {
        enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
    }
    try {
        pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
    } catch (UnsupportedEncodingException uee) {
    }
    return pathSegment;
}

From source file:cn.clxy.studio.common.web.multipart.GMultipartResolver.java

/**
 * Determine the encoding for the given request. Can be overridden in subclasses.
 * <p>// www .j  a v  a2 s .  co m
 * 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
 * @see #setDefaultEncoding
 */
protected String determineEncoding(HttpServletRequest request) {
    String encoding = request.getCharacterEncoding();
    if (encoding == null) {
        encoding = getDefaultEncoding();
    }
    return encoding;
}

From source file:org.tangram.spring.StreamingMultipartResolver.java

/**
 * Determine the encoding for the given request. Can be overridden in subclasses.
 * <p>/*from  ww  w  .j a v  a 2s  .com*/
 * 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();
    return (encoding == null) ? "UTF-8" : encoding;
}

From source file:com.twinsoft.convertigo.engine.util.HttpServletRequestTwsWrapper.java

public HttpServletRequestTwsWrapper(HttpServletRequest request) {
    super(request);
    try {//  ww w .  j  av a2s  .  co  m
        if (request.getCharacterEncoding() == null) {
            request.setCharacterEncoding("UTF-8");
        }

        if (request.getMethod().equalsIgnoreCase("PUT")
                && MimeType.WwwForm.is(HeaderName.ContentType.getHeader(request))) {
            try {
                String content = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
                addQuery(content);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        // parse GET parameters
        addQuery(request.getQueryString());

        // retrieve POST parameters ( == not defined in GET )
        for (Entry<String, String[]> entry : GenericUtils.<Map<String, String[]>>cast(request.getParameterMap())
                .entrySet()) {
            if (!parameters.containsKey(entry.getKey())) {
                parameters.put(entry.getKey(), entry.getValue());
            }
        }
    } catch (UnsupportedEncodingException e) {
        parameters.clear();
        parameters.putAll(GenericUtils.<Map<String, String[]>>cast(request.getParameterMap()));
    }
}

From source file:org.toobsframework.pres.spring.multipart.MultipartController.java

protected String determineEncoding(HttpServletRequest request) {
    String enc = request.getCharacterEncoding();
    if (enc == null) {
        enc = DEFAULT_ENCODING;//from w  w  w . j a  v  a  2 s  .co m
    }
    return enc;
}

From source file:ubic.gemma.web.util.upload.CommonsMultipartMonitoredResolver.java

/**
 * Determine the encoding for the given request. Can be overridden in subclasses.
 * The default implementation checks the request encoding, falling back to the default encoding specified for this
 * resolver.//from   w  w  w  .j ava  2  s  .com
 *
 * @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 enc = request.getCharacterEncoding();
    if (enc == null) {
        enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
    }
    return enc;
}

From source file:com.asual.summer.xml.XmlView.java

protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    response.setContentType(getContentType());
    response.setCharacterEncoding(request.getCharacterEncoding());

    XmlMapper mapper = new XmlMapper();
    mapper.configure(Feature.AUTO_CLOSE_TARGET, false);
    mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
    mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
    mapper.writeValue(response.getOutputStream(), filterModel(model));
}

From source file:com.google.gerrit.httpd.ProjectBasicAuthFilter.java

private String encoding(HttpServletRequest req) {
    return Objects.firstNonNull(req.getCharacterEncoding(), "UTF-8");
}

From source file:foo.domaintest.action.RequestModule.java

/** Provides the request charset. */
@Provides//from   w w  w.j a  v  a 2 s  .  co m
@RequestData("charset")
String provideRequestCharset(HttpServletRequest request) {
    // Guess UTF-8 if none specified.
    return Optional.fromNullable(request.getCharacterEncoding()).or(UTF_8.name());
}

From source file:com.github.matthesrieke.simplebroker.SimpleBrokerServlet.java

protected String readContent(HttpServletRequest req) throws IOException {
    String enc = req.getCharacterEncoding();
    Scanner sc = new Scanner(req.getInputStream(), enc == null ? "utf-8" : enc);
    StringBuilder sb = new StringBuilder();

    while (sc.hasNext()) {
        sb.append(sc.nextLine());/*from ww  w. j  a  v  a2s. c  o m*/
    }

    sc.close();
    return sb.toString();
}