org.springframework.web.servlet.handler.SimpleMappingExceptionResolver Java Examples
The following examples show how to use
org.springframework.web.servlet.handler.SimpleMappingExceptionResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DispatcherServletTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void existingMultipartRequest() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); MockHttpServletResponse response = new MockHttpServletResponse(); ComplexWebApplicationContext.MockMultipartResolver multipartResolver = (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext() .getBean("multipartResolver"); MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request); complexDispatcherServlet.service(multipartRequest, response); multipartResolver.cleanupMultipart(multipartRequest); assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE)); assertNotNull(request.getAttribute("cleanedUp")); }
Example #2
Source File: DispatcherServletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void multipartResolutionFailed() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); request.setAttribute("fail", Boolean.TRUE); MockHttpServletResponse response = new MockHttpServletResponse(); complexDispatcherServlet.service(request, response); assertTrue("forwarded to failed", "failed0.jsp".equals(response.getForwardedUrl())); assertEquals(200, response.getStatus()); assertTrue("correct exception", request.getAttribute( SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE) instanceof MaxUploadSizeExceededException); }
Example #3
Source File: DispatcherServletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void existingMultipartRequestButWrapped() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); MockHttpServletResponse response = new MockHttpServletResponse(); ComplexWebApplicationContext.MockMultipartResolver multipartResolver = (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext() .getBean("multipartResolver"); MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request); complexDispatcherServlet.service(new HttpServletRequestWrapper(multipartRequest), response); multipartResolver.cleanupMultipart(multipartRequest); assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE)); assertNotNull(request.getAttribute("cleanedUp")); }
Example #4
Source File: DispatcherServletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void existingMultipartRequest() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); MockHttpServletResponse response = new MockHttpServletResponse(); ComplexWebApplicationContext.MockMultipartResolver multipartResolver = (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext() .getBean("multipartResolver"); MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request); complexDispatcherServlet.service(multipartRequest, response); multipartResolver.cleanupMultipart(multipartRequest); assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE)); assertNotNull(request.getAttribute("cleanedUp")); }
Example #5
Source File: ShiroConfig.java From springBoot-study with Apache License 2.0 | 5 votes |
@Bean(name="simpleMappingExceptionResolver") public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() { SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver(); Properties mappings = new Properties(); mappings.setProperty("DatabaseException", "databaseError");//数据库异常处理 mappings.setProperty("UnauthorizedException","403"); r.setExceptionMappings(mappings); // None by default r.setDefaultErrorView("error"); // No default r.setExceptionAttribute("ex"); // Default is "exception" //r.setWarnLogCategory("example.MvcLogger"); // No default return r; }
Example #6
Source File: WebMvcConfigurationSupportExtensionTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void exceptionResolvers() throws Exception { List<HandlerExceptionResolver> resolvers = ((HandlerExceptionResolverComposite) this.config.handlerExceptionResolver()).getExceptionResolvers(); assertEquals(2, resolvers.size()); assertEquals(ResponseStatusExceptionResolver.class, resolvers.get(0).getClass()); assertEquals(SimpleMappingExceptionResolver.class, resolvers.get(1).getClass()); }
Example #7
Source File: DispatcherServletTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void multipartResolutionFailed() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); request.setAttribute("fail", Boolean.TRUE); MockHttpServletResponse response = new MockHttpServletResponse(); complexDispatcherServlet.service(request, response); assertTrue("forwarded to failed", "failed0.jsp".equals(response.getForwardedUrl())); assertEquals(200, response.getStatus()); assertTrue("correct exception", request.getAttribute( SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE) instanceof MaxUploadSizeExceededException); }
Example #8
Source File: DispatcherServletTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void existingMultipartRequestButWrapped() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); MockHttpServletResponse response = new MockHttpServletResponse(); ComplexWebApplicationContext.MockMultipartResolver multipartResolver = (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext() .getBean("multipartResolver"); MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request); complexDispatcherServlet.service(new HttpServletRequestWrapper(multipartRequest), response); multipartResolver.cleanupMultipart(multipartRequest); assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE)); assertNotNull(request.getAttribute("cleanedUp")); }
Example #9
Source File: DispatcherServletTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void existingMultipartRequest() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); MockHttpServletResponse response = new MockHttpServletResponse(); ComplexWebApplicationContext.MockMultipartResolver multipartResolver = (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext() .getBean("multipartResolver"); MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request); complexDispatcherServlet.service(multipartRequest, response); multipartResolver.cleanupMultipart(multipartRequest); assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE)); assertNotNull(request.getAttribute("cleanedUp")); }
Example #10
Source File: ShiroConfig.java From spring-boot-demo with MIT License | 5 votes |
/** * 异常处理 * * @return */ @Bean(name = "simpleMappingExceptionResolver") public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() { SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver(); Properties mappings = new Properties(); mappings.setProperty("DatabaseException", "databaseError"); mappings.setProperty("UnauthorizedException", "403"); r.setExceptionMappings(mappings); r.setDefaultErrorView("error"); r.setExceptionAttribute("ex"); return r; }
Example #11
Source File: WebMvcConfigurationSupportExtensionTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void exceptionResolvers() throws Exception { List<HandlerExceptionResolver> resolvers = ((HandlerExceptionResolverComposite) this.config.handlerExceptionResolver(null)).getExceptionResolvers(); assertEquals(2, resolvers.size()); assertEquals(ResponseStatusExceptionResolver.class, resolvers.get(0).getClass()); assertEquals(SimpleMappingExceptionResolver.class, resolvers.get(1).getClass()); }
Example #12
Source File: DispatcherServletTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void multipartResolutionFailed() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); request.setAttribute("fail", Boolean.TRUE); MockHttpServletResponse response = new MockHttpServletResponse(); complexDispatcherServlet.service(request, response); assertTrue("forwarded to failed", "failed0.jsp".equals(response.getForwardedUrl())); assertEquals(200, response.getStatus()); assertTrue("correct exception", request.getAttribute( SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE) instanceof MaxUploadSizeExceededException); }
Example #13
Source File: DispatcherServletTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void existingMultipartRequestButWrapped() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def"); request.addPreferredLocale(Locale.CANADA); request.addUserRole("role1"); MockHttpServletResponse response = new MockHttpServletResponse(); ComplexWebApplicationContext.MockMultipartResolver multipartResolver = (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext() .getBean("multipartResolver"); MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request); complexDispatcherServlet.service(new HttpServletRequestWrapper(multipartRequest), response); multipartResolver.cleanupMultipart(multipartRequest); assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE)); assertNotNull(request.getAttribute("cleanedUp")); }
Example #14
Source File: ShiroConfig.java From Spring-Boot-Book with Apache License 2.0 | 5 votes |
@Bean(name = "simpleMappingExceptionResolver") public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() { SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver(); Properties mappings = new Properties(); mappings.setProperty("DatabaseException", "databaseError");//数据库异常处理 mappings.setProperty("UnauthorizedException", "403"); r.setExceptionMappings(mappings); r.setDefaultErrorView("error"); r.setExceptionAttribute("ex"); // 缺省值"exception" return r; }
Example #15
Source File: WebMvcConfigurationSupportExtensionTests.java From spring-analysis-note with MIT License | 4 votes |
@Override public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) { exceptionResolvers.add(new SimpleMappingExceptionResolver()); }
Example #16
Source File: WebMvcConfigurationSupportExtensionTests.java From java-technology-stack with MIT License | 4 votes |
@Override public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) { exceptionResolvers.add(new SimpleMappingExceptionResolver()); }
Example #17
Source File: WebMvcConfigurationSupportExtensionTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) { exceptionResolvers.add(new SimpleMappingExceptionResolver()); }