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.fujitsu.dc.test.unit.core.jersey.filter.DcCoreContainerFilterTest.java
/** * filter(ContainerRequest req, ContainerResponse res) ContainerResponse?. * ??????????/*from ww w.j av a 2s.c om*/ */ @Ignore @Test public void testFilterContainerRequestContainerResponse() { // DcCoreContainerFilter containerFilter = new DcCoreContainerFilter(); // ContainerRequiest ContainerRequest mockRequest = mock(ContainerRequest.class); HttpServletRequest mockServletRequest = mock(HttpServletRequest.class); when(mockServletRequest.getAttribute("requestTime")).thenReturn(System.currentTimeMillis()); containerFilter.setHttpServletRequest(mockServletRequest); // ContainerResponse ContainerResponse mockResponse = mock(ContainerResponse.class); when(mockResponse.getStatus()).thenReturn(HttpStatus.SC_OK); // ?? ContainerResponse filteredResponse = containerFilter.filter(mockRequest, mockResponse); // ?? // ????????Null??????. assertNotNull(filteredResponse); }
From source file:io.personium.test.unit.core.jersey.filter.PersoniumCoreContainerFilterTest.java
/** * filter(ContainerRequest req, ContainerResponse res) ContainerResponse?. * ??????????/*from w w w . j av a 2s. com*/ */ @Ignore @Test public void testFilterContainerRequestContainerResponse() { // PersoniumCoreContainerFilter containerFilter = new PersoniumCoreContainerFilter(); // ContainerRequiest ContainerRequest mockRequest = mock(ContainerRequest.class); HttpServletRequest mockServletRequest = mock(HttpServletRequest.class); when(mockServletRequest.getAttribute("requestTime")).thenReturn(System.currentTimeMillis()); containerFilter.setHttpServletRequest(mockServletRequest); // ContainerResponse ContainerResponse mockResponse = mock(ContainerResponse.class); when(mockResponse.getStatus()).thenReturn(HttpStatus.SC_OK); // ?? ContainerResponse filteredResponse = containerFilter.filter(mockRequest, mockResponse); // ?? // ????????Null??????. assertNotNull(filteredResponse); }
From source file:com.thesoftwareguild.capstoneblog.controller.ErrorController.java
@RequestMapping(value = "/error") // #2 - note the use of the Spring Model object rather than a Map public String customError(HttpServletRequest request, HttpServletResponse response, Model model) { // #3 - retrieve some useful information from the request 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.servlet.error.request_uri"); if (requestUri == null) { requestUri = "Unknown"; }/* w w w .ja va2s .c o m*/ // #4 - format the message for the view String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri, exceptionMessage); // #5 - put the message in the model object model.addAttribute("errorMessage", message); return "customError"; }
From source file:nl.surfnet.coin.api.controller.AccessConfirmationController.java
@RequestMapping("/oauth/error") public ModelAndView handleError(HttpServletRequest request) { Map<String, Object> model = new HashMap<String, Object>(); model.put("error", request.getAttribute("error")); model.put("message", "There was a problem with the OAuth2 protocol"); return new ModelAndView("oauth_error", model); }
From source file:org.wallride.web.controller.guest.article.ArticleIndexController.java
private String extractPathFromPattern(final 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(); String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path); return finalPath; }
From source file:sample.contact.web.IndexController.java
/** * Error page./*from w w w .j av a2s .com*/ */ @RequestMapping("/error.html") public String error(HttpServletRequest request, Model model) { model.addAttribute("errorCode", "Error " + request.getAttribute("javax.servlet.error.status_code")); Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); StringBuilder errorMessage = new StringBuilder(); errorMessage.append("<ul>"); while (throwable != null) { errorMessage.append("<li>").append(escapeTags(throwable.getMessage())).append("</li>"); throwable = throwable.getCause(); } errorMessage.append("</ul>"); model.addAttribute("errorMessage", errorMessage.toString()); return "error.html"; }
From source file:de.tobiasbruns.content.storage.ContentController.java
private String getPath(HttpServletRequest req) { return req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString(); }
From source file:com.netease.channel.controller.BaseController.java
public String getUserName(HttpServletRequest request, HttpServletResponse respose) { String userName = (String) request.getAttribute(LoginUtil.USER_NAME); LOG.debug("UserName is " + userName); return userName; }
From source file:com.swcguild.addressbookmvc.controller.ErrorController.java
@RequestMapping(value = "/error") // #2 - note the use of the Spring Model object rather than a Map public String customError(HttpServletRequest request, HttpServletResponse response, Model model) { // #3 - retrieve some useful information from the request 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.servlet.error.request_uri"); if (requestUri == null) { requestUri = "Unknown"; }/* w w w. j av a 2 s .co m*/ // #4 - format the message for the View String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri, exceptionMessage); // #5 - put the message in the model object model.addAttribute("errorMessage", message); return "customError"; }
From source file:io.interface21.CsrfHeaderFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN"); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { // Angular is capable to handle CSRF protection and expected a token with name XSRF-TOKEN cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie);//from w w w. jav a2 s. c o m } } filterChain.doFilter(request, response); }