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:org.seasar.teeda.extension.filter.MultipartFormDataRequestWrapper.java

protected void parseRequest(final HttpServletRequest request) {
    try {/* ww w .ja  va 2  s  .  c om*/
        final String encoding = request.getCharacterEncoding();
        final List requestParameters = fileUpload.parseRequest(request);
        for (final Iterator it = requestParameters.iterator(); it.hasNext();) {
            final FileItem fileItem = (FileItem) it.next();
            if (fileItem.isFormField()) {
                final String name = fileItem.getFieldName();
                final String value = fileItem.getString(encoding);
                addParameter(name, value);
            } else {
                fileItems.put(fileItem.getFieldName(), fileItem);
            }
        }
    } catch (final SizeLimitExceededException e) {
        logger.log("ETDA0110", new Object[0], e);
        ExternalMessageUtil.addMessage(request, ExtensionConstants.FILE_UPLOAD_SIZE_ERROR_MESSAGE,
                new Object[] { new Long(e.getPermittedSize()), new Long(e.getActualSize()) });
    } catch (final FileSizeLimitExceededException e) {
        logger.log("ETDA0110", new Object[0], e);
        ExternalMessageUtil.addMessage(request, ExtensionConstants.FILE_UPLOAD_FILE_SIZE_ERROR_MESSAGE,
                new Object[] { new Long(e.getPermittedSize()), new Long(e.getActualSize()) });
    } catch (final Exception e) {
        logger.log("ETDA0110", new Object[0], e);
        ExternalMessageUtil.addMessage(request, ExtensionConstants.FILE_UPLOAD_ERROR_MESSAGE);
    }

    for (final Iterator it = request.getParameterMap().entrySet().iterator(); it.hasNext();) {
        final Entry entry = (Entry) it.next();
        final String name = (String) entry.getKey();
        final String[] values = (String[]) entry.getValue();
        addParameters(name, values);
    }
}

From source file:ar.com.zauber.commons.web.uri.factory.RelativePathUriFactory.java

/**
 * Genera el path hasta la ruta de la aplicacin.
 * @param request/*from  ww  w.  ja  va  2  s  .c  o  m*/
 * @return path
 */
private String generarPath(final HttpServletRequest request, final String destination) {
    try {
        String encoding = request.getCharacterEncoding();
        if (StringUtils.isBlank(encoding)) {
            encoding = defaultEncoding;
        }
        // si estamos en un jsp...
        String uri = (String) request.getAttribute("javax.servlet.forward.request_uri");

        if (uri == null) {
            uri = request.getRequestURI();
        }
        uri = URLDecoder.decode(uri, encoding);

        // Saco el contexto
        uri = uri.substring(URLDecoder.decode(request.getContextPath(), encoding).length());

        final String[] ret = comunDenominador(uri, destination);
        uri = ret[0];
        // cuento los subs
        int slashes = StringUtils.countMatches(uri, "/");

        // si empezaba en barra resto 1
        if (uri.startsWith("/")) {
            slashes--;
        }

        final StringBuilder sb = new StringBuilder();
        boolean empty = true;
        for (int i = 0; i < slashes; i++) {
            empty = false;
            sb.append("..");
            if (i + 1 < slashes) {
                sb.append('/');
            }
        }
        if (empty) {
            sb.append('.');
        }

        sb.append(ret[1]);
        return sb.toString();
    } catch (UnsupportedEncodingException e) {
        throw new UnhandledException(e);
    }
}

From source file:org.springframework.web.multipart.cos.CosMultipartResolver.java

/**
 * Determine the encoding for the given request.
 * Can be overridden in subclasses.// ww  w . j a  v a  2 s.  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
 * @see #setDefaultEncoding
 */
protected String determineEncoding(HttpServletRequest request) {
    String enc = request.getCharacterEncoding();
    if (enc == null) {
        enc = this.defaultEncoding;
    }
    return enc;
}

From source file:de.decidr.workflowmodeleditor.server.servicetask.WSDLUploadServletImpl.java

private FileItemStream getFileItem(HttpServletRequest request) {
    ServletFileUpload upload = new ServletFileUpload();
    upload.setHeaderEncoding(request.getCharacterEncoding());
    upload.setSizeMax(10000000);//from w  w  w .  ja  va  2  s. co  m

    try {
        FileItemIterator items = upload.getItemIterator(request);
        while (items.hasNext()) {
            FileItemStream item = items.next();
            if (!item.isFormField()) {
                return item;
            }
        }
    } catch (FileUploadException e) {
        return null;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:nl.strohalm.cyclos.http.EncodingFilter.java

@Override
protected void execute(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) throws IOException, ServletException {
    try {/*from  w w  w .jav  a  2  s . c  o m*/
        final String requestEncoding = request.getCharacterEncoding();
        if (StringUtils.isEmpty(requestEncoding)) {
            request.setCharacterEncoding(encoding);
        }
        response.setCharacterEncoding(encoding);
    } catch (final Exception e) {
    }
    chain.doFilter(request, response);
}

From source file:com.nominanuda.web.http.ServletHelper.java

public @Nullable String getCharacterEncoding(HttpServletRequest servletRequest) {
    return servletRequest.getCharacterEncoding();
}

From source file:com.investdata.common.filter.CharacterEncodingFilter.java

protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    if (this.encoding != null && (this.forceEncoding || request.getCharacterEncoding() == null)) {
        request.setCharacterEncoding(this.encoding);//?  
        if (this.forceEncoding) {
            response.setCharacterEncoding(this.encoding);
        }//  ww  w  .ja  va  2 s.c  o  m
    }
    filterChain.doFilter(request, response);//  

    /*
    if (this.encoding != null && (this.forceEncoding || request.getCharacterEncoding() == null)) {
       request.setCharacterEncoding(this.encoding);
       if (this.forceEncoding && setCharacterEncodingAvailable) {
    response.setCharacterEncoding(this.encoding);
       }
    }
    filterChain.doFilter(request, response);
    */
}

From source file:info.magnolia.cms.security.auth.callback.FormClientCallback.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response) {
    try {//from  w  w  w  . java  2  s.co m
        if (!response.isCommitted()) {
            response.setContentType("text/html");
            if (null == request.getCharacterEncoding()) {
                response.setCharacterEncoding(MIMEMapping.getContentEncodingOrDefault("text/html"));
            }
        }
        FreemarkerUtil.process(getLoginForm(), getMessages(), response.getWriter());
    } catch (Throwable t) {
        log.error("exception while writing login template", t);
    }
}

From source file:eu.dime.dnsregister.controllers.RecordsController.java

String encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest) {
    String enc = httpServletRequest.getCharacterEncoding();
    if (enc == null) {
        enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
    }//from   w w w.ja  v  a 2s.  com
    try {
        pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
    } catch (UnsupportedEncodingException uee) {
    }
    return pathSegment;
}

From source file:com.ms.commons.summer.web.multipart.CommonsMultipartEngancedResolver.java

protected String determineEncoding(HttpServletRequest request) {
    String encoding = request.getCharacterEncoding();
    if (encoding == null) {
        encoding = getDefaultEncoding();
    }/*w w w .j a  va  2 s .  co  m*/
    return encoding;
}