List of usage examples for org.springframework.web.util NestedServletException getCause
public synchronized Throwable getCause()
From source file:de.hska.ld.core.config.filter.CrossOriginFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String url = request.getRequestURL().toString(); if (!url.contains("push")) { String origin = request.getHeader("Origin"); HttpServletResponse response = (HttpServletResponse) res; response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Origin", origin); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Authorization"); }//ww w . j a va 2 s .c o m try { chain.doFilter(req, res); } catch (NestedServletException nse) { if (!(nse.getCause() instanceof NullPointerException && nse.getCause().getMessage() == null)) { if (!(nse.getCause() instanceof IllegalArgumentException)) { nse.printStackTrace(); } } } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:app.controller.CustomerControllerTest.java
@Test public void failToGetCustomersIfNotAllowed() throws Exception { setSecurityContext("anonymous"); try {/*w w w .j a va 2s .c o m*/ mvc.perform(get("/customer")); } catch (NestedServletException e) { Throwable nestedException = e.getCause(); Assert.assertTrue(nestedException instanceof AccessDeniedException); } }
From source file:cherry.foundation.springmvc.OperationLogHandlerInterceptorTest.java
@Test public void testException() throws Exception { try {// w w w .j a v a 2s . c o m mockMvc.perform(get("/secure/test").param("exception", "").principal(getContext().getAuthentication())) .andExpect(status().is5xxServerError()); fail("Exception must be thrown"); } catch (NestedServletException ex) { assertEquals("SecureTestController exception", ex.getCause().getMessage()); } }
From source file:com.orange.clara.cloud.servicedbdumper.controllers.admin.JobsControllerTest.java
@Test public void when_admin_wants_to_delete_a_running_job_it_should_throw_an_exception() throws Exception { try {/* w ww .ja v a 2 s . c om*/ mockMvc.perform( get(Routes.JOB_CONTROL_ROOT + Routes.JOB_CONTROL_DELETE_ROOT + "/" + jobRunning.getId())); fail("It should throw an IllegalArgumentException"); } catch (NestedServletException e) { assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } try { mockMvc.perform( get(Routes.JOB_CONTROL_ROOT + Routes.JOB_CONTROL_DELETE_ROOT + "/" + jobStarted.getId())); fail("It should throw an IllegalArgumentException"); } catch (NestedServletException e) { assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } }
From source file:com.orange.clara.cloud.servicedbdumper.controllers.admin.JobsControllerTest.java
@Test public void when_admin_wants_to_delete_or_update_an_non_existing_job_it_should_throw_an_exception() throws Exception { try {/* w ww.j av a2 s . co m*/ mockMvc.perform(get(Routes.JOB_CONTROL_ROOT + Routes.JOB_CONTROL_DELETE_ROOT + "/10000")); fail("It should throw an IllegalArgumentException"); } catch (NestedServletException e) { assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } try { mockMvc.perform(get(Routes.JOB_CONTROL_ROOT + Routes.JOB_CONTROL_UPDATE_ROOT + "/10000" + "/jobevent/" + JobEvent.ERRORED)); fail("It should throw an IllegalArgumentException"); } catch (NestedServletException e) { assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } }
From source file:org.apereo.openlrs.controllers.XAPIExceptionHandlerAdvice.java
@ExceptionHandler(org.springframework.web.util.NestedServletException.class) public void test(NestedServletException e) { Throwable t = e.getCause(); logger.debug("*************************** " + t.getClass().getName()); }
From source file:com.gradecak.alfresco.mvc.webscript.DispatcherWebscript.java
private void convertExceptionToJson(Exception ex, HttpServletResponse res) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> params = new HashMap<String, Object>(); params.put("success", false); params.put("event", "exception"); params.put("exception", ex.getClass()); params.put("message", JavaScriptUtils.javaScriptEscape(ex.getMessage())); if (ex instanceof NestedServletException) { NestedServletException nestedServletException = (NestedServletException) ex; if (nestedServletException.getCause() != null) { params.put("cause", nestedServletException.getCause().getClass()); params.put("causeMessage", nestedServletException.getCause().getMessage()); }/*from ww w . ja va 2 s . c o m*/ } objectMapper.writeValue(res.getOutputStream(), params); }
From source file:org.openmhealth.reference.filter.ExceptionFilter.java
/** * <p>//from w w w . j av a 2 s .com * If the request throws an exception, specifically a OmhException, * attempt to respond with that message from the exception. * </p> * * <p> * For example, HTTP responses have their status codes changed to * {@link HttpServletResponse#SC_BAD_REQUEST} and the body of the response * is the error message. * </p> */ @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { // Get a handler for the correct exception type. Throwable exception = null; // Always let the request continue but setup to catch exceptions. try { chain.doFilter(request, response); } // The servlet container may wrap the exception, in which case we // must first unwrap it, then delegate it. catch (NestedServletException e) { // Get the underlying cause. Throwable cause = e.getCause(); // If the underlying exception is one of ours, then store the // underlying exception. if (cause instanceof OmhException) { exception = cause; } // Otherwise, store this exception. else { exception = e; } } // Otherwise, store the exception, catch (Exception e) { exception = e; } // If an exception was thrown, attempt to handle it. if (exception != null) { // Save the exception in the request. request.setAttribute(ATTRIBUTE_KEY_EXCEPTION, exception); // Handle the exception. if (exception instanceof NoSuchSchemaException) { LOGGER.log(Level.INFO, "An unknown schema was requested.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_NOT_FOUND, exception.getMessage()); } else if (exception instanceof InvalidAuthenticationException) { LOGGER.log(Level.INFO, "A user's authentication information was invalid.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_UNAUTHORIZED, exception.getMessage()); } else if (exception instanceof InvalidAuthorizationException) { LOGGER.log(Level.INFO, "A user's authorization information was invalid.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_UNAUTHORIZED, exception.getMessage()); } else if (exception instanceof OmhException) { LOGGER.log(Level.INFO, "An invalid request was made.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_BAD_REQUEST, exception.getMessage()); } // If the exception was not one of ours, the server must have // crashed. else { LOGGER.log(Level.SEVERE, "The server threw an unexpected exception.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null); } } }
From source file:com.orange.clara.cloud.servicedbdumper.controllers.ManagerControllerTest.java
@Test public void when_user_want_to_see_or_download_or_delete_a_dump_file_which_not_exist_it_should_always_throw_an_exception() throws Exception { try {//from w w w . j av a 2s. c o m mockMvc.perform(get(Routes.MANAGE_ROOT + Routes.RAW_DUMP_FILE_ROOT + "/100")); fail("It should throw an IllegalArgumentException"); } catch (NestedServletException e) { assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } try { mockMvc.perform(get(Routes.MANAGE_ROOT + Routes.SHOW_DUMP_FILE_ROOT + "/100")); fail("It should throw an IllegalArgumentException"); } catch (NestedServletException e) { assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } try { mockMvc.perform(get(Routes.MANAGE_ROOT + Routes.DELETE_DUMP_FILE_ROOT + "/100")); fail("It should throw an IllegalArgumentException"); } catch (NestedServletException e) { assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } try { mockMvc.perform(get(Routes.MANAGE_ROOT + Routes.DOWNLOAD_DUMP_FILE_ROOT + "/100")); fail("It should throw an IllegalArgumentException"); } catch (NestedServletException e) { assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } }