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:com.zuoxiaolong.niubi.job.console.controller.ShiroController.java
@RequestMapping(value = "/login", method = RequestMethod.POST) @ExceptionForward("/shiro/login") public String login(HttpServletRequest request) { String exception = (String) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME); if (UnknownAccountException.class.getName().equals(exception)) { failed("Unknown account."); } else if (IncorrectCredentialsException.class.getName().equals(exception)) { failed("Incorrect password."); } else {/*w w w . j a v a2 s. co m*/ LoggerHelper.error("unknown error : " + exception); failed("Unknown error."); } return "shiro_login"; }
From source file:org.bonitasoft.web.designer.controller.RequestMappingUtils.java
public String extractPathWithinPattern(HttpServletRequest request) { return new AntPathMatcher().extractPathWithinPattern( (String) request.getAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE), (String) request.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); }
From source file:org.dawnsci.marketplace.controllers.FileController.java
@RequestMapping(value = "/{solution}/**", method = { RequestMethod.GET, RequestMethod.HEAD }) @ResponseBody//from w w w . jav a 2 s . com public ResponseEntity<FileSystemResource> getFile(@PathVariable("solution") String solution, HttpServletRequest request) { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); AntPathMatcher apm = new AntPathMatcher(); path = apm.extractPathWithinPattern(bestMatchPattern, path); File file = fileService.getFile(solution, path); if (file.exists() && file.isFile()) { try { String detect = tika.detect(file); MediaType mediaType = MediaType.parseMediaType(detect); return ResponseEntity.ok().contentLength(file.length()).contentType(mediaType) .lastModified(file.lastModified()).body(new FileSystemResource(file)); } catch (IOException e) { e.printStackTrace(); } } else { throw new ResourceNotFoundException(); } return null; }
From source file:fi.helsinki.opintoni.config.locale.AngularCookieLocaleResolver.java
@Override public Locale resolveLocale(HttpServletRequest request) { parseLocaleCookieIfNecessary(request); return (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME); }
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.HTTPNotFoundException a 404 Exception that gets handled by {@link com.miserablemind.butter.apps.butterApp.controller.ControllerExceptionHandler} *//*from w ww. j a v a2 s.c o m*/ @RequestMapping(method = RequestMethod.GET, value = "/404") public String handle404(HttpServletRequest request) throws HTTPNotFoundException { String originalUrl = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI); throw new HTTPNotFoundException("URL: " + originalUrl); }
From source file:com.tsguild.videogamewebapp.controller.ErrorController.java
public String customError(HttpServletRequest request, HttpServletRequest response, Model model) { Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); HttpStatus httpStatus = HttpStatus.valueOf((statusCode)); Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); String exceptionMessage = httpStatus.getReasonPhrase(); String requestUri = (String) request.getAttribute("javax.servlet.error.request.uri"); if (requestUri == null) { requestUri = "Unknown"; }/*from www . j a v a2 s . c om*/ String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri, exceptionMessage); model.addAttribute("errorMessage", message); return "customError"; }
From source file:coral.reef.test.web.ReefControllerTest.java
@Test public void testUrl() throws IOException { final HttpServletRequest httpRequest = mock(HttpServletRequest.class); when(httpRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .thenReturn("/lineup/world.xml"); final HttpServletResponse httpResponse = mock(HttpServletResponse.class); final HttpSession httpSession = mock(HttpSession.class); final ReefHandler handler = mock(ReefHandler.class); when(reefService.handler("test")).thenReturn(handler); when(handler.startMarker()).thenReturn("test"); when(handler.refreshMarker()).thenReturn("test"); when(handler.processMarker()).thenReturn("test"); when(handler.serverMarker()).thenReturn("test"); reefController.dispatchToExpHandler("test", httpSession, httpResponse, httpRequest); }
From source file:org.shaigor.rest.retro.client.oauth.CustomOAuth2ClientContextFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { if (servletRequest instanceof HttpServletRequest) { HttpServletRequest request = ((HttpServletRequest) servletRequest); if (request.getAttribute(OAUTH2_REST_TEMPLATE) == null) { request.setAttribute(OAUTH2_REST_TEMPLATE, oauth2RestTemplate); }//from w w w . ja v a 2s .c o m } chain.doFilter(servletRequest, servletResponse); }
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.HTTPBadRequestException a 400 Exception that gets handled by {@link com.miserablemind.butter.apps.butterApp.controller.ControllerExceptionHandler} */// w w w. jav a2 s .c o m @RequestMapping(method = RequestMethod.GET, value = "/400") public String handle400(HttpServletRequest request) throws HTTPBadRequestException { String originalUrl = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI); throw new HTTPBadRequestException("URL: " + originalUrl); }
From source file:com.swcguild.capstoneproject.controller.ErrorController.java
@RequestMapping(value = "/error") public String customError(HttpServletRequest request, HttpServletResponse response, Model model) { Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); HttpStatus httpStatus = HttpStatus.valueOf(statusCode); Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); String exceptionMessage = null; exceptionMessage = httpStatus.getReasonPhrase(); String requestUri = (String) request.getAttribute("javax.serlet.error.request_uri"); if (requestUri == null) { requestUri = "Unknown"; }/*from w ww . j av a 2 s . co m*/ String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri, exceptionMessage); model.addAttribute("errorMessage", message); return "customError"; }