List of usage examples for javax.servlet.http HttpServletRequest getAttribute
public Object getAttribute(String name);
Object
, or null
if no attribute of the given name exists. From source file:org.obiba.mica.config.locale.AngularCookieLocaleResolver.java
private void parseLocaleCookieIfNecessary(HttpServletRequest request) { if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) { // Retrieve and parse cookie value. Cookie cookie = WebUtils.getCookie(request, getCookieName()); Locale locale = null;//from w w w. j a v a2s .c om TimeZone timeZone = null; if (cookie != null) { String value = cookie.getValue(); // Remove the double quote value = StringUtils.replace(value, "%22", ""); String localePart = value; String timeZonePart = null; int spaceIndex = localePart.indexOf(' '); if (spaceIndex != -1) { localePart = value.substring(0, spaceIndex); timeZonePart = value.substring(spaceIndex + 1); } locale = "-".equals(localePart) ? null : StringUtils.parseLocaleString(localePart); if (timeZonePart != null) { timeZone = StringUtils.parseTimeZoneString(timeZonePart); } if (logger.isTraceEnabled()) { logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale + "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : "")); } } request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME, locale == null ? determineDefaultLocale(request) : locale); request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME, timeZone == null ? determineDefaultTimeZone(request) : timeZone); } }
From source file:com.marklogic.samplestack.web.SessionController.java
/** * Exposes endpoint that returns CSRF token information and a session for use in login. * @param request The Http Request./*w ww . ja va 2s .c o m*/ * @param response The Http response. * @return A JsonNode with bare-bones acknowledgement. */ @RequestMapping(value = "session", method = RequestMethod.GET) public @ResponseBody JsonNode hello(HttpServletRequest request, HttpServletResponse response) { CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf"); String headerName = csrfToken.getHeaderName(); String token = csrfToken.getToken(); HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); responseWrapper.addHeader(headerName, token); return errors.makeJsonResponse(200, "New Session"); }
From source file:fi.helsinki.opintoni.config.locale.AngularCookieLocaleResolver.java
@Override public LocaleContext resolveLocaleContext(final HttpServletRequest request) { parseLocaleCookieIfNecessary(request); return () -> (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME); }
From source file:com.thoughtworks.go.server.web.IgnoreResolver.java
private boolean isHttpMethod(HttpServletRequest request, String targetingMethod) { String method = (String) request.getAttribute("_method"); return StringUtils.isNotEmpty(method) ? method.equalsIgnoreCase(targetingMethod) : request.getMethod().equalsIgnoreCase(targetingMethod); }
From source file:com.miserablemind.butter.apps.butterApp.controller.error.HTTPErrorController.java
/** * @param request HTTP request to handle * @return never gets to return value. Always throws an exception. * @throws com.miserablemind.butter.apps.butterApp.exception.HTTPInternalServerErrorException a 500 Exception that gets handled by {@link com.miserablemind.butter.apps.butterApp.controller.ControllerExceptionHandler} *//*from www . j a v a 2 s.c om*/ @RequestMapping(method = RequestMethod.GET, value = "/500") public String handle500(HttpServletRequest request) throws HTTPInternalServerErrorException { String originalUrl = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI); throw new HTTPInternalServerErrorException("URL: " + originalUrl); }
From source file:org.craftercms.engine.controller.HttpProxyRequestHandler.java
protected String getUrlToProxy(HttpServletRequest request) { String url = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); if (StringUtils.isEmpty(url)) { throw new IllegalStateException("Required request attribute '" + HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE + "' is not set"); }/* w w w .j a v a2s. co m*/ return url; }
From source file:io.github.jhipster.config.locale.AngularCookieLocaleResolver.java
private void parseLocaleCookieIfNecessary(HttpServletRequest request) { if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) { // Retrieve and parse cookie value. Cookie cookie = WebUtils.getCookie(request, getCookieName()); Locale locale = null;/*from w w w . j a va 2 s . com*/ TimeZone timeZone = null; if (cookie != null) { String value = cookie.getValue(); // Remove the double quote value = StringUtils.replace(value, "%22", ""); String localePart = value; String timeZonePart = null; int spaceIndex = localePart.indexOf(' '); if (spaceIndex != -1) { localePart = value.substring(0, spaceIndex); timeZonePart = value.substring(spaceIndex + 1); } locale = !"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null; if (timeZonePart != null) { timeZone = StringUtils.parseTimeZoneString(timeZonePart); } if (logger.isTraceEnabled()) { logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale + "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : "")); } } request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME, locale != null ? locale : determineDefaultLocale(request)); request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME, timeZone != null ? timeZone : determineDefaultTimeZone(request)); } }
From source file:net.sourceforge.subsonic.i18n.SubsonicLocaleResolver.java
/** * Resolve the current locale via the given request. * * @param request Request to be used for resolution. * @return The current locale./* ww w . j av a 2 s . co m*/ */ public Locale resolveLocale(HttpServletRequest request) { Locale locale = (Locale) request.getAttribute("subsonic.locale"); if (locale != null) { return locale; } // Optimization: Cache locale in the request. locale = doResolveLocale(request); request.setAttribute("subsonic.locale", locale); return locale; }
From source file:com.bstek.dorado.web.resolver.WebContextSupportedController.java
/** * URI?ContentPathURI/*from ww w.j av a 2s . c om*/ */ protected String getRelativeRequestURI(HttpServletRequest request) throws UnsupportedEncodingException { String uri = (String) request.getAttribute("originalUrlPath"); if (uri == null) { uri = request.getRequestURI().substring(getContextPath(request).length()); } uri = StringUtils.replaceChars(URLDecoder.decode(uri, Configure.getString("view.uriEncoding")), ESCAPED_PATH_DELIM, PathUtils.PATH_DELIM); if (uri.length() > 1 && uri.charAt(0) == PathUtils.PATH_DELIM) { uri = uri.substring(1); } return uri; }
From source file:com.alibaba.dragoon.patrol.webx3.DragoonStatValve.java
public String getRequestURI(HttpServletRequest request) { String uri = (String) request.getAttribute("web-rpc.url-pattern"); if (uri == null || uri.length() == 0) { uri = request.getRequestURI();/*www .j ava2s .c o m*/ } if (uri == null) { uri = "/"; } return uri; }