Java Code Examples for javax.servlet.http.HttpServletRequest.getCharacterEncoding()

The following are Jave code examples for showing how to use getCharacterEncoding() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DKJavaWebApiDemo   File: APIRequest.java   View Source Code Vote up 6 votes
public APIRequest(HttpServletRequest request) {

        this.request = request;

        header = new HashMap<String, Object>();
        Enumeration e = request.getHeaderNames();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            Object value = request.getHeader(name);
            header.put(name, value);
        }

        params = getParamesMap(request.getParameterMap());
        url = request.getRequestURL().toString();
        uri = request.getRequestURI();
        remoteAddr = request.getRemoteAddr();
        remoteHost = request.getRemoteHost();
        remotePort = request.getRemotePort();
        contextPath = request.getContextPath();
        localAddr = request.getLocalAddr();
        characterEncoding = request.getCharacterEncoding();
        localName = request.getLocalName();
        localPort = request.getLocalPort();
        method = request.getMethod();
        queryString = request.getQueryString();
    }
 
Example 2
Project: validator-web   File: RedirectView.java   View Source Code Vote up 6 votes
/**
 * Creates the target URL by checking if the redirect string is a URI template first,
 * expanding it with the given model, and then optionally appending simple type model
 * attributes as query String parameters.
 */
protected final String createTargetUrl(Map<String, Object> model, HttpServletRequest request)
        throws UnsupportedEncodingException {
    // Prepare target URL.
    StringBuilder targetUrl = new StringBuilder();
    if (this.contextRelative && getUrl().startsWith("/")) {
        // Do not apply context path to relative URLs.
        targetUrl.append(request.getContextPath());
    }
    targetUrl.append(getUrl());
    
    String enc = this.encodingScheme;
    if (enc == null) {
        enc = request.getCharacterEncoding();
    }
    if (enc == null) {
        enc = DEFAULT_CHARACTER_ENCODING;
    }
    
    if (this.expandUriTemplateVariables && StringUtils.hasText(targetUrl)) {
        Map<String, String> variables = Collections.<String, String> emptyMap();
        targetUrl = replaceUriTemplateVariables(targetUrl.toString(), model, variables, enc);
    }
    if (this.exposeModelAttributes) {
        appendQueryProperties(targetUrl, model, enc);
    }
    return targetUrl.toString();
}
 
Example 3
Project: logistimo-web-service   File: MediaSecurityFilter.java   View Source Code Vote up 6 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
    throws IOException, ServletException {

  HttpServletRequest req = (HttpServletRequest) request;
  HttpServletResponse resp = (HttpServletResponse) response;
  String servletPath = req.getServletPath() + req.getPathInfo();
  xLogger.fine("Servlet path: ", servletPath);
  if (req.getCharacterEncoding() == null) {
    request.setCharacterEncoding(Constants.UTF8);
  }

  if (!(StringUtils.isNotBlank(servletPath) && servletPath.startsWith(MEDIA_ENDPOINT_URL))) {
    resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    return;
  }
  if (filterChain != null) {
    filterChain.doFilter(request, response);
  }
}
 
Example 4
Project: maintain-robot   File: MyUtil.java   View Source Code Vote up 6 votes
/**
 * 读取请求流
 * @param request
 * @return
 * @throws IOException
 */
public static String binaryReader(HttpServletRequest request) throws IOException {
    String charset = request.getCharacterEncoding();
    if (charset == null) {
        charset = "utf-8";
    }
    BufferedReader in = new BufferedReader(new InputStreamReader(request
            .getInputStream(), charset));

    // Read the request
    CharArrayWriter data = new CharArrayWriter();
    char[] buf = new char[8192];
    int ret;
    while ((ret = in.read(buf, 0, 8192)) != -1) {
        data.write(buf, 0, ret);
    }
    return data.toString();
}
 
Example 5
Project: xproject   File: AbstractHttpAccessLoggingInterceptor.java   View Source Code Vote up 5 votes
/**
 * 从HttpServletRequest中提取请求参数(包括请求体中的参数)
 * @param request
 * @param loggingContext
 * @return
 * @throws Exception
 */
protected HttpRequestParameter extractRequestParameter(HttpServletRequest request, LoggingContext loggingContext) throws Exception {
	HttpRequestParameter parameter = new HttpRequestParameter();
	Map<String,String[]> originalParamMap = request.getParameterMap();
	Map<String,String> paramMap = new HashMap<String,String>();
	if(originalParamMap != null && !originalParamMap.isEmpty()){
		for(Map.Entry<String, String[]> entry : originalParamMap.entrySet()){
			paramMap.put(entry.getKey(), getStringParameterValue(entry.getValue()));
		}
	}
	parameter.setParameter(paramMap);
	MediaType contentType = loggingContext.getHttpAccessLog().getRequestContentType();
	if(contentType != null){
		if(isContentCachingRequest(request)){
			String charset = request.getCharacterEncoding();
			if(StringUtils.isEmpty(charset)){
				charset = StringUtils.defaultIfEmpty(contentType.getCharset().name(), GlobalConstants.SYSTEM_DEFAULT_CHARSET);
			}
			ContentCachingRequestWrapper requestToUse = (ContentCachingRequestWrapper) request;
			byte[] bytes = requestToUse.getContentAsByteArray();
			if(bytes != null){
				String body = IOUtils.toString(bytes, charset);
				Object bodyObj = body;
				if(MediaType.APPLICATION_JSON.getType().equals(contentType.getType())){ //目前只处理JSON类型的数据
					if(body.startsWith("[") && body.endsWith("]")){ //JSON Array String -> List<Map<String,Object>>
						bodyObj = JsonUtils.json2Object(body, new TypeReference<List<Map<String,Object>>>(){});
					}else if(body.startsWith("{") && body.endsWith("}")){ //JSON Object String -> Map<String,Object>
						bodyObj = JsonUtils.json2Object(body, new TypeReference<Map<String,Object>>(){});
					}
				}
				parameter.setBody(bodyObj);
			}
			
		}
	}
	return excludeRequestParameter(parameter, loggingContext);
}
 
Example 6
Project: oscm   File: IgnoreCharacterEncodingHttpRequestWrapper.java   View Source Code Vote up 5 votes
/**
 * If the character encoding is not initialized, it will be set to UTF-8
 */
public IgnoreCharacterEncodingHttpRequestWrapper(HttpServletRequest request)
        throws UnsupportedEncodingException {

    super(request);
    if (request.getCharacterEncoding() == null) {
        request.setCharacterEncoding(Constants.CHARACTER_ENCODING_UTF8);
    }
}
 
Example 7
Project: myfaces-trinidad   File: UploadRequestManager.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public void setRequest(HttpServletRequest req)
{
  _clearMap();
  _requestParams = req.getParameterMap();
  _encoding = req.getCharacterEncoding();
}
 
Example 8
Project: flume-release-1.7.0   File: JSONHandler.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public List<Event> getEvents(HttpServletRequest request) throws Exception {
  BufferedReader reader = request.getReader();
  String charset = request.getCharacterEncoding();
  //UTF-8 is default for JSON. If no charset is specified, UTF-8 is to
  //be assumed.
  if (charset == null) {
    LOG.debug("Charset is null, default charset of UTF-8 will be used.");
    charset = "UTF-8";
  } else if (!(charset.equalsIgnoreCase("utf-8")
          || charset.equalsIgnoreCase("utf-16")
          || charset.equalsIgnoreCase("utf-32"))) {
    LOG.error("Unsupported character set in request {}. "
            + "JSON handler supports UTF-8, "
            + "UTF-16 and UTF-32 only.", charset);
    throw new UnsupportedCharsetException("JSON handler supports UTF-8, "
            + "UTF-16 and UTF-32 only.");
  }

  /*
   * Gson throws Exception if the data is not parseable to JSON.
   * Need not catch it since the source will catch it and return error.
   */
  List<Event> eventList = new ArrayList<Event>(0);
  try {
    eventList = gson.fromJson(reader, listType);
  } catch (JsonSyntaxException ex) {
    throw new HTTPBadRequestException("Request has invalid JSON Syntax.", ex);
  }

  for (Event e : eventList) {
    ((JSONEvent) e).setCharset(charset);
  }
  return getSimpleEvents(eventList);
}
 
Example 9
Project: lams   File: CharacterEncodingFilter.java   View Source Code Vote up 5 votes
@Override
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);
		}
	}
	filterChain.doFilter(request, response);
}
 
Example 10
Project: hrrs   File: HrrsUrlEncodedFormHelper.java   View Source Code Vote up 5 votes
private byte[] encodeFormParameters(HttpServletRequest request, String defaultEncoding) {
    try {
        String encoding = request.getCharacterEncoding();
        if (encoding == null) {
            encoding = defaultEncoding;
        }
        Map<String, List<String>> formParameters = parseFormParameters(request, encoding);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(outputStream, encoding);
        boolean firstFormParameter = true;
        for (Map.Entry<String, List<String>> formParameter : formParameters.entrySet()) {
            String formParameterName = formParameter.getKey();
            String encodedFormParameterName = URLEncoder.encode(formParameterName, encoding);
            for (String formParameterValue : formParameter.getValue()) {
                String encodedFormParameterValue = URLEncoder.encode(formParameterValue, encoding);
                if (firstFormParameter) {
                    firstFormParameter = false;
                } else {
                    writer.write('&');
                }
                writer.write(encodedFormParameterName);
                writer.write('=');
                writer.write(encodedFormParameterValue);
            }
        }
        writer.close();
        return outputStream.toByteArray();
    } catch (Throwable error) {
        LOGGER.error("failed to encode form parameters", error);
        return new byte[0];
    }
}
 
Example 11
Project: gitlab-branch-source-plugin   File: HookHandler.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
private String getRequestBody(HttpServletRequest request) throws IOException {
    String charset = request.getCharacterEncoding() == null ? CHARSET_UTF_8 : request.getCharacterEncoding();
    String requestBody = IOUtils.toString(request.getInputStream(), charset);
    if (StringUtils.isBlank(requestBody)) {
        throw new IllegalArgumentException("request-body is empty");
    }

    return requestBody;
}
 
Example 12
Project: oscm   File: ServicePmServlet.java   View Source Code Vote up 4 votes
/**
 * Process a HTTP request for a service price model
 * 
 * @param request
 *            a HTTP servlet request
 * @param response
 *            a HTTP servlet response
 * @throws ServletException
 * @throws IOException
 */
@Override
protected void process(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    if (request.getCharacterEncoding() == null) {
        request.setCharacterEncoding("UTF-8");
    }

    response.setHeader("Cache-Control",
            "no-cache, no-store, must-revalidate");
    response.setHeader("Pragma", "no-cache");

    final String locale = request.getParameter(REQUEST_PARAM_LOCALE);
    if (emptyString(locale)) {
        errorForward(request, response, "Please enter a valid locale.");
        return;
    }

    Map<ContextKey, ContextValue<?>> context = evaluateServicePmContext(request);
    if (context != null) {

        PriceModel priceModel = getPriceModel(context,
                createLocaleSet(SUPPORTED_LOCALES));
        if (priceModel == null) {
            errorForward(request, response, "Price model not found.");
            return;
        }

        PriceModelContent priceModelContent = getPriceModelContent(
                priceModel, new Locale(locale));
        if (priceModelContent != null) {
            if (!generatePdfResponse(priceModelContent,
                    generateServicePmFileName(context), response)) {
                errorForward(request, response,
                        "Price model found but its file type was not supported.");
            }
        } else {
            errorForward(request, response,
                    "Price model neither found for specified locale nor for default locale.");
        }
    } else {
        errorForward(request, response, "Please enter all required fields.");
    }

}
 
Example 13
Project: logistimo-web-service   File: SecurityFilter.java   View Source Code Vote up 4 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
    throws IOException, ServletException {
  xLogger.fine("Entered doFilter");
  HttpServletRequest req = (HttpServletRequest) request;
  HttpServletResponse resp = (HttpServletResponse) response;
  String servletPath = req.getServletPath();
  if (req.getCharacterEncoding() == null) {
    request.setCharacterEncoding(Constants.UTF8);
  }
  // BACKWARD COMPATIBILITY - in case people have already bookmarked these links
  if ("/index.jsp".equals(servletPath) || "/login.jsp".equals(servletPath)) {
    resp.sendRedirect(isForceNewUI ? HOME_URL_NEW : HOME_URL);
    return;
  }
  SecureUserDetails
      userDetails = null;
  // END BACKWARD COMPATIBILITY
  if (!LOGIN_URL.equals(servletPath) && !AUTHENTICATE_URL.equals(servletPath) && (
      servletPath.isEmpty() || servletPath.equals("/") || servletPath.startsWith("/s/") || (
          servletPath.startsWith(TASK_URL) && StringUtils
              .isBlank(req.getHeader(Constants.X_APP_ENGINE_TASK_NAME))))) {
    userDetails = SecurityMgr
        .getSessionDetails(req.getSession());
    if (userDetails == null) { // session not authenticated yet; direct to login screen
      if (!(servletPath.startsWith(TASK_ADMIN_URL) && ACTION_UPDATESYSCONFIG
          .equals(request.getParameter(ACTION)))) {
        if (isForceNewUI) {
          resp.sendRedirect(HOME_URL_NEW);  // login please
        } else {
          String redirectPath = LOGIN_URL;
          if (servletPath.startsWith("/s/") || servletPath.startsWith(TASK_URL)) {
            String rUrl = servletPath;
            String queryString = req.getQueryString();
            if (queryString != null && !queryString.isEmpty()) {
              rUrl += "?" + queryString;
            }
            redirectPath += "?rurl=" + URLEncoder.encode(rUrl, "UTF-8");
          }
          resp.sendRedirect(redirectPath);  // login please
        }
        return;
      }
    } else {
      String role = userDetails.getRole();
      if (SecurityConstants.ROLE_KIOSKOWNER
          .equals(role)) { // Kiosk owner cannot access this interface
        SessionMgr.cleanupSession(req.getSession());
        resp.sendRedirect(LOGIN_URL + "?status=4");
        return;
      }
      if ((servletPath.contains("/admin/") || servletPath.startsWith(TASK_URL))
          && !SecurityConstants.ROLE_SUPERUSER.equals(role)) { // only superuser can access
        SessionMgr.cleanupSession(req.getSession());
        resp.sendRedirect(LOGIN_URL + "?status=4"); // access denied
        return;
      }

    }
  }
  if (userDetails != null) {
    SecurityUtils.setUserDetails(userDetails);
  }
  try {
    if (filterChain != null) {
      filterChain.doFilter(request, response);
    }
  } finally {
    if (userDetails != null) {
      SecurityUtils.setUserDetails(null);
    }
  }
}
 
Example 14
Project: logistimo-web-service   File: APISecurityFilter.java   View Source Code Vote up 4 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
    throws IOException, ServletException {

  HttpServletRequest req = (HttpServletRequest) request;
  HttpServletResponse resp = (HttpServletResponse) response;
  String servletPath = req.getServletPath() + req.getPathInfo();
  xLogger.fine("Servlet path: ", servletPath);
  if (req.getCharacterEncoding() == null) {
    request.setCharacterEncoding(Constants.UTF8);
  }

  if (StringUtils.isNotEmpty(req.getHeader("app-name"))) {
    filterChain.doFilter(request, response);
  }
  try {
    //this is meant for internal api client
    if (StringUtils.isNotBlank(req.getHeader(X_ACCESS_USER))) {
      try {
        SecurityMgr.setSessionDetails(req.getHeader(X_ACCESS_USER));
      } catch (Exception e) {
        xLogger.severe("Issue with api client authentication", e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        return;
      }

    } else if (StringUtils.isBlank(req.getHeader(Constants.X_APP_ENGINE_TASK_NAME)) && !(
        StringUtils.isNotBlank(servletPath) && (servletPath.startsWith(ASSET_STATUS_URL)
            || servletPath.startsWith(SMS_API_URL) || servletPath.startsWith(M_AUTH_URL)))) {
      String recvdCookie = getAppCookie(req);
      if (appVerAvailable && recvdCookie != null && !appVersion.equals(recvdCookie)) {
        resp.setHeader(ERROR_HEADER_NAME, UPGRADE_REQUIRED_RESPONSE_CODE);
        resp.sendError(HttpServletResponse.SC_CONFLICT, "Upgrade required");
        return;
      }
      if (StringUtils.isNotBlank(servletPath) && !(servletPath.startsWith(APP_STATUS_URL)
          || servletPath.startsWith(AUTHENTICATE_URL))) {
        SecureUserDetails
            userDetails = SecurityMgr
            .getSessionDetails(req.getSession());
        if (userDetails == null) {
          resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Required.");
          return;
        }
        SecurityUtils.setUserDetails(userDetails);
        String reqDomainId = SecurityUtils.getReqCookieUserDomain(req);
        if (reqDomainId != null && !reqDomainId.equals(
            userDetails.getUsername() + CharacterConstants.COLON + SecurityUtils
                .getCurrentDomainId())) {
          resp.setHeader(ERROR_HEADER_NAME, DOMAIN_CHANGE_RESPONSE_CODE);
          resp.sendError(HttpServletResponse.SC_CONFLICT, "Invalid session on client");
          return;
        }
      }

    }

    if (filterChain != null) {
      filterChain.doFilter(request, response);
    }
  } finally {
    SecurityUtils.setUserDetails(null);
  }
}
 
Example 15
Project: lams   File: CommonsMultipartRequestHandler.java   View Source Code Vote up 4 votes
/**
 * Adds a regular text parameter to the set of text parameters for this
 * request and also to the list of all parameters. Handles the case of
 * multiple values for the same parameter by using an array for the
 * parameter value.
 *
 * @param request The request in which the parameter was specified.
 * @param item    The file item for the parameter to add.
 */
protected void addTextParameter(HttpServletRequest request, FileItem item) {
    String name = item.getFieldName();
    String value = null;
    boolean haveValue = false;
    String encoding = request.getCharacterEncoding();

    if (encoding != null) {
        try {
            value = item.getString(encoding);
            haveValue = true;
        } catch (Exception e) {
            // Handled below, since haveValue is false.
        }
    }
    if (!haveValue) {
        try {
             value = item.getString("ISO-8859-1");
        } catch (java.io.UnsupportedEncodingException uee) {
             value = item.getString();
        }
        haveValue = true;
    }

    if (request instanceof MultipartRequestWrapper) {
        MultipartRequestWrapper wrapper = (MultipartRequestWrapper) request;
        wrapper.setParameter(name, value);
    }

    String[] oldArray = (String[]) elementsText.get(name);
    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);
}
 
Example 16
Project: lams   File: LearningDesignSVGServlet.java   View Source Code Vote up 4 votes
@Override
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
    String serverId = request.getParameter(CentralConstants.PARAM_SERVER_ID);
    String datetime = request.getParameter(CentralConstants.PARAM_DATE_TIME);
    String hashValue = request.getParameter(CentralConstants.PARAM_HASH_VALUE);
    String username = request.getParameter(CentralConstants.PARAM_USERNAME);

    // in case lsId parameter is provided - get learningDesignId from the responsible lesson, otherwise try to get
    // it from a request as "ldId" parameter
    Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, true);
    Long learningDesignId = (lessonId == null) ? WebUtil.readLongParam(request, CentralConstants.PARAM_LEARNING_DESIGN_ID) : 
	lessonService.getLessonDetails(lessonId).getLearningDesignID();

    if (serverId == null || datetime == null || hashValue == null || username == null) {
	String msg = "Parameters missing";
	log.error(msg);
	response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameters missing");
    }

    // LDEV-2196 preserve character encoding if necessary
    if (request.getCharacterEncoding() == null) {
	log.debug(
		"request.getCharacterEncoding is empty, parsing username and courseName as 8859_1 to UTF-8...");
	username = new String(username.getBytes("8859_1"), "UTF-8");
    }

    // get Server map
    ExtServer extServer = integrationService.getExtServer(serverId);

    // authenticate
    Authenticator.authenticate(extServer, datetime, username, hashValue);

    String imagePath = LearningDesignService.getLearningDesignSVGPath(learningDesignId);
    File imageFile = new File(imagePath);
    if (!imageFile.canRead()) {
	response.sendError(HttpServletResponse.SC_NOT_FOUND);
	return;
    }

    boolean download = WebUtil.readBooleanParam(request, "download", false);
    // should the image be downloaded or a part of page?
    if (download) {
	String name = learningDesignService
		.getLearningDesignDTO(learningDesignId, Configuration.get(ConfigurationKeys.SERVER_LANGUAGE))
		.getTitle();
	name += "." + "svg";
	name = FileUtil.encodeFilenameForDownload(request, name);
	response.setContentType("application/x-download");
	response.setHeader("Content-Disposition", "attachment;filename=" + name);
    } else {
	response.setContentType("image/svg+xml");
    }

    FileInputStream input = new FileInputStream(imagePath);
    OutputStream output = response.getOutputStream();
    IOUtils.copy(input, output);
    IOUtils.closeQuietly(input);
    IOUtils.closeQuietly(output);
} catch (Exception e) {
    log.error("Problem with LearningDesignSVGServlet request", e);
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Problem with LearningDesignSVGServlet request");
}
   }
 
Example 17
Project: alfresco-remote-api   File: TenantWebScriptServlet.java   View Source Code Vote up 4 votes
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
    if (logger.isDebugEnabled())
        logger.debug("Processing tenant request ("  + req.getMethod() + ") " + req.getRequestURL() + (req.getQueryString() != null ? "?" + req.getQueryString() : ""));
    
    if (req.getCharacterEncoding() == null)
    {
        req.setCharacterEncoding("UTF-8");
    }
    
    setLanguageFromRequestHeader(req);
    
    try
    {
    	WebScriptServletRuntime runtime = getRuntime(req, res);
        runtime.executeScript();
    }
    catch (IllegalStateException e) 
    {
       if(e.getMessage().contains("getOutputStream() has already been called for this response"))
       {
           if(logger.isDebugEnabled())
           {
               logger.warn("Client has cut off communication", e);
           }
           else
           {
               logger.warn("Client has cut off communication");
           }
       }
       else
       {
           throw e;
       }
    }		
    finally
    {
        // clear threadlocal
        I18NUtil.setLocale(null);
        // clear authentication and tenant context
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
 
Example 18
Project: atbash-octopus   File: WebUtils.java   View Source Code Vote up 3 votes
/**
 * Determine the encoding for the given request.
 * Can be overridden in subclasses.
 * <p>The default implementation checks the request's
 * {@link ServletRequest#getCharacterEncoding() character encoding}, and if that
 * <code>null</code>, falls back to the {@link #DEFAULT_CHARACTER_ENCODING}.
 *
 * @param request current HTTP request
 * @return the encoding for the request (never <code>null</code>)
 * @see ServletRequest#getCharacterEncoding()
 */
protected static String determineEncoding(HttpServletRequest request) {
    String enc = request.getCharacterEncoding();
    if (enc == null) {
        enc = DEFAULT_CHARACTER_ENCODING;
    }
    return enc;
}
 
Example 19
Project: lams   File: CommonsMultipartResolver.java   View Source Code Vote up 3 votes
/**
 * Determine the encoding for the given request.
 * Can be overridden in subclasses.
 * <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})
 * @see javax.servlet.ServletRequest#getCharacterEncoding
 * @see #setDefaultEncoding
 */
protected String determineEncoding(HttpServletRequest request) {
	String encoding = request.getCharacterEncoding();
	if (encoding == null) {
		encoding = getDefaultEncoding();
	}
	return encoding;
}
 
Example 20
Project: lams   File: UrlPathHelper.java   View Source Code Vote up 3 votes
/**
 * Determine the encoding for the given request.
 * Can be overridden in subclasses.
 * <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})
 * @see javax.servlet.ServletRequest#getCharacterEncoding()
 * @see #setDefaultEncoding
 */
protected String determineEncoding(HttpServletRequest request) {
	String enc = request.getCharacterEncoding();
	if (enc == null) {
		enc = getDefaultEncoding();
	}
	return enc;
}