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:com.contact.UrlUtil.java

public static String encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest) {
    String enc = httpServletRequest.getCharacterEncoding();

    if (enc == null) {
        enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
    }//w  ww.j a  v  a 2 s . c  o  m

    try {
        pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
    } catch (UnsupportedEncodingException uee) {
        //
    }

    return pathSegment;
}

From source file:de.ifgi.mosia.wpswfs.Util.java

public static String readContent(HttpServletRequest req) throws IOException {
    String enc = req.getCharacterEncoding();
    return readContent(req.getInputStream(), enc);
}

From source file:arena.utils.ServletUtils.java

public static String getRequestCharacterEncoding(HttpServletRequest request) {
    String encoding = request.getCharacterEncoding();
    if (encoding == null) {
        encoding = "8859_1";
    }//from  w ww.  ja  v a2  s  . com
    return encoding;
}

From source file:info.magnolia.cms.filters.MultipartRequestFilter.java

/**
 * Adds all request paramaters as request attributes.
 * @param request HttpServletRequest//from w w  w . j  a v a 2s.c  o m
 */
private static void parseParameters(HttpServletRequest request) throws IOException {
    MultipartForm form = new MultipartForm();
    String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8"); //$NON-NLS-1$
    MultipartRequest multi = new MultipartRequest(request, Path.getTempDirectoryPath(), MAX_FILE_SIZE, encoding,
            null);
    Enumeration params = multi.getParameterNames();
    while (params.hasMoreElements()) {
        String name = (String) params.nextElement();
        String value = multi.getParameter(name);
        form.addParameter(name, value);
        String[] s = multi.getParameterValues(name);
        if (s != null) {
            form.addparameterValues(name, s);
        }
    }
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements()) {
        String name = (String) files.nextElement();
        form.addDocument(name, multi.getFilesystemName(name), multi.getContentType(name), multi.getFile(name));
    }
    request.setAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME, form);
}

From source file:info.magnolia.cms.filters.CosMultipartRequestFilter.java

/**
 * Adds all request paramaters as request attributes.
 * @param request HttpServletRequest// w w w. jav a2s.c om
 */
private static MultipartForm parseParameters(HttpServletRequest request) throws IOException {
    MultipartForm form = new MultipartForm();
    String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8");
    MultipartRequest multi = new MultipartRequest(request, Path.getTempDirectoryPath(), MAX_FILE_SIZE, encoding,
            null);
    Enumeration params = multi.getParameterNames();
    while (params.hasMoreElements()) {
        String name = (String) params.nextElement();
        String value = multi.getParameter(name);
        form.addParameter(name, value);
        String[] s = multi.getParameterValues(name);
        if (s != null) {
            form.addparameterValues(name, s);
        }
    }
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements()) {
        String name = (String) files.nextElement();
        form.addDocument(name, multi.getFilesystemName(name), multi.getContentType(name), multi.getFile(name));
    }
    request.setAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME, form);
    return form;
}

From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthGitFilter.java

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

From source file:info.magnolia.cms.core.Path.java

/**
 * Returns the decoded URI of the current request, without the context path.
 * @param req request//from   www.  j a  v a  2s  .c  om
 * @return request URI without servlet context
 */
private static String getDecodedURI(HttpServletRequest req) {
    String encoding = StringUtils.defaultString(req.getCharacterEncoding(), ENCODING_DEFAULT);
    String decodedURL = null;
    try {
        decodedURL = URLDecoder.decode(req.getRequestURI(), encoding);
    } catch (UnsupportedEncodingException e) {
        decodedURL = req.getRequestURI();
    }
    return StringUtils.substringAfter(decodedURL, req.getContextPath());
}

From source file:org.apache.shindig.social.core.oauth.OAuthAuthenticationHandler.java

public static String readBodyString(HttpServletRequest request) throws IOException {
    byte[] rawBody = readBody(request);
    return IOUtils.toString(new ByteArrayInputStream(rawBody), request.getCharacterEncoding());
}

From source file:com.telefonica.iot.perseo.Utils.java

/**
 * Return body as a String//from w  ww  .j a v  a 2s .c o m
 *
 * @param request HttpServletRequest incomming request
 * @return String (body of the request)
 * @throws java.io.IOException
 *
 */
public static String getBodyAsString(HttpServletRequest request) throws IOException {
    logger.debug("request.getCharacterEncoding() " + request.getCharacterEncoding());
    if (request.getCharacterEncoding() == null) {
        request.setCharacterEncoding("UTF-8");
    }
    StringBuilder sb = new StringBuilder();
    BufferedReader br = request.getReader();
    String read = br.readLine();
    while (read != null) {
        sb.append(read);
        read = br.readLine();
    }
    return sb.toString();
}

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

private static String encoding(HttpServletRequest req) {
    return MoreObjects.firstNonNull(req.getCharacterEncoding(), UTF_8.name());
}