public ConcurrentResultHandlerMethod(final Object result, ConcurrentResultMethodParameter returnType) { super((Callable<Object>) () -> { if (result instanceof Exception) { throw (Exception) result; } else if (result instanceof Throwable) { throw new NestedServletException("Async processing failed", (Throwable) result); } return result; }, CALLABLE_METHOD); if (ServletInvocableHandlerMethod.this.returnValueHandlers != null) { setHandlerMethodReturnValueHandlers(ServletInvocableHandlerMethod.this.returnValueHandlers); } this.returnType = returnType; }
/** * Processes the incoming Hessian request and creates a Hessian response. */ @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!"POST".equals(request.getMethod())) { throw new HttpRequestMethodNotSupportedException(request.getMethod(), new String[] {"POST"}, "HessianServiceExporter only supports POST requests"); } response.setContentType(CONTENT_TYPE_HESSIAN); try { invoke(request.getInputStream(), response.getOutputStream()); } catch (Throwable ex) { throw new NestedServletException("Hessian skeleton invocation failed", ex); } }
public ConcurrentResultHandlerMethod(final Object result, ConcurrentResultMethodParameter returnType) { super((Callable<Object>) () -> { if (result instanceof Exception) { throw (Exception) result; } else if (result instanceof Throwable) { throw new NestedServletException("Async processing failed", (Throwable) result); } return result; }, CALLABLE_METHOD); if (ServletInvocableHandlerMethod.this.returnValueHandlers != null) { setHandlerMethodReturnValueHandlers(ServletInvocableHandlerMethod.this.returnValueHandlers); } this.returnType = returnType; }
/** * Processes the incoming Hessian request and creates a Hessian response. */ @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!"POST".equals(request.getMethod())) { throw new HttpRequestMethodNotSupportedException(request.getMethod(), new String[] {"POST"}, "HessianServiceExporter only supports POST requests"); } response.setContentType(CONTENT_TYPE_HESSIAN); try { invoke(request.getInputStream(), response.getOutputStream()); } catch (Throwable ex) { throw new NestedServletException("Hessian skeleton invocation failed", ex); } }
/** * Return a template compiled by the configured Groovy Markup template engine * for the given view URL. */ protected Template getTemplate(String viewUrl) throws Exception { Assert.state(this.engine != null, "No MarkupTemplateEngine set"); try { return this.engine.createTemplateByPath(viewUrl); } catch (ClassNotFoundException ex) { Throwable cause = (ex.getCause() != null ? ex.getCause() : ex); throw new NestedServletException( "Could not find class while rendering Groovy Markup view with name '" + getUrl() + "': " + ex.getMessage() + "'", cause); } }
/** * Return a template compiled by the configured Groovy Markup template engine * for the given view URL. */ protected Template getTemplate(String viewUrl) throws Exception { Assert.state(this.engine != null, "No MarkupTemplateEngine set"); try { return this.engine.createTemplateByPath(viewUrl); } catch (ClassNotFoundException ex) { Throwable cause = (ex.getCause() != null ? ex.getCause() : ex); throw new NestedServletException( "Could not find class while rendering Groovy Markup view with name '" + getUrl() + "': " + ex.getMessage() + "'", cause); } }
/** * Reads a remote invocation from the request, executes it, * and writes the remote invocation result to the response. * @see #readRemoteInvocation(HttpServletRequest) * @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object) * @see #writeRemoteInvocationResult(HttpServletRequest, HttpServletResponse, RemoteInvocationResult) */ @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { RemoteInvocation invocation = readRemoteInvocation(request); RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy()); writeRemoteInvocationResult(request, response, result); } catch (ClassNotFoundException ex) { throw new NestedServletException("Class not found during deserialization", ex); } }
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; request.setAttribute(CURRENT_URI, calculateCurrentUri(request)); try { chain.doFilter(servletRequest, servletResponse); } catch (IOException ex) { throw ex; } catch (Exception ex) { // Try to extract a SpringSecurityException from the stacktrace Throwable[] causeChain = throwableAnalyzer.determineCauseChain(ex); UserRedirectRequiredException redirect = (UserRedirectRequiredException) throwableAnalyzer .getFirstThrowableOfType( UserRedirectRequiredException.class, causeChain); if (redirect != null) { redirectUser(redirect, request, response); } else { if (ex instanceof ServletException) { throw (ServletException) ex; } if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } throw new NestedServletException("Unhandled exception", ex); } } }
@Test public void testNestedServletExceptionStringNullThrowable() { // This can happen if someone is sloppy with Throwable causes... NestedServletException exception = new NestedServletException("foo", null); assertEquals("foo", exception.getMessage()); }
@Test public void testNestedServletExceptionString() { NestedServletException exception = new NestedServletException("foo"); assertEquals("foo", exception.getMessage()); }
filterConfig.getFilterName() + "': " + ex.getMessage(); logger.error(msg, ex); throw new NestedServletException(msg, ex);
/** * Reads a remote invocation from the request, executes it, * and writes the remote invocation result to the response. * @see #readRemoteInvocation(HttpServletRequest) * @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object) * @see #writeRemoteInvocationResult(HttpServletRequest, HttpServletResponse, RemoteInvocationResult) */ @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { RemoteInvocation invocation = readRemoteInvocation(request); RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy()); writeRemoteInvocationResult(request, response, result); } catch (ClassNotFoundException ex) { throw new NestedServletException("Class not found during deserialization", ex); } }
throw new NestedServletException("Request processing failed", ex);
@Test public void testNestedServletExceptionStringThrowable() { Throwable cause = new RuntimeException(); NestedServletException exception = new NestedServletException("foo", cause); assertEquals(NestedExceptionUtils.buildMessage("foo", cause), exception.getMessage()); assertEquals(cause, exception.getCause()); }
filterConfig.getFilterName() + "': " + ex.getMessage(); logger.error(msg, ex); throw new NestedServletException(msg, ex);
@Test public void testUnnestNestedServletException() throws Exception { final TracingPlugin tracingPlugin = new TracingPlugin(); final Span span = mock(Span.class); SpanUtils.setException(span, new NestedServletException("Eat this!", new RuntimeException("bazinga!")), tracingPlugin.getIgnoreExceptions(), tracingPlugin.getUnnestExceptions()); verify(span).setTag("exception.class", "java.lang.RuntimeException"); verify(span).setTag("exception.message", "bazinga!"); }
throw new NestedServletException("Request processing failed", ex);
dispatchException = new NestedServletException("Handler dispatch failed", err); new NestedServletException("Handler processing failed", err));
@Test public void resolveExceptionWithAssertionError() throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class); this.resolver.setApplicationContext(ctx); this.resolver.afterPropertiesSet(); AssertionError err = new AssertionError("argh"); HandlerMethod handlerMethod = new HandlerMethod(new ResponseBodyController(), "handle"); ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, new NestedServletException("Handler dispatch failed", err)); assertNotNull("Exception was not handled", mav); assertTrue(mav.isEmpty()); assertEquals(err.toString(), this.response.getContentAsString()); }
dispatchException = new NestedServletException("Handler dispatch failed", err); new NestedServletException("Handler processing failed", err));