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; }
@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()); }
private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { ErrorWrapperResponse wrapped = new ErrorWrapperResponse(response); try { chain.doFilter(request, wrapped); if (wrapped.hasErrorToSend()) { handleErrorStatus(request, response, wrapped.getStatus(), wrapped.getMessage()); response.flushBuffer(); } else if (!request.isAsyncStarted() && !response.isCommitted()) { response.flushBuffer(); } } catch (Throwable ex) { Throwable exceptionToHandle = ex; if (ex instanceof NestedServletException) { exceptionToHandle = ((NestedServletException) ex).getRootCause(); } handleException(request, response, wrapped, exceptionToHandle); response.flushBuffer(); } }
@Test public void testNestedServletExceptionStringNullThrowable() { // This can happen if someone is sloppy with Throwable causes... NestedServletException exception = new NestedServletException("foo", null); assertEquals("foo", exception.getMessage()); }
/** * Return the detail message, including the message from the nested exception * if there is one. */ @Override @Nullable public String getMessage() { return NestedExceptionUtils.buildMessage(super.getMessage(), getCause()); }
/** * Return the detail message, including the message from the nested exception * if there is one. */ public String getMessage() { if (getCause() == null) { return super.getMessage(); } else { return super.getMessage() + "; nested exception is " + getRootCause().getClass().getName() + ": " + getRootCause().getMessage(); } }
@Test public void testNestedServletExceptionString() { NestedServletException exception = new NestedServletException("foo"); assertEquals("foo", exception.getMessage()); }
/** * Return the detail message, including the message from the nested exception * if there is one. */ @Override @Nullable public String getMessage() { return NestedExceptionUtils.buildMessage(super.getMessage(), getCause()); }
/** * 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); } }
private void filterAndRecordMetrics(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { TimingContext timingContext = TimingContext.get(request); if (timingContext == null) { timingContext = startAndAttachTimingContext(request); } try { filterChain.doFilter(request, response); if (!request.isAsyncStarted()) { // Only record when async processing has finished or never been started. // If async was started by something further down the chain we wait // until the second filter invocation (but we'll be using the // TimingContext that was attached to the first) Throwable exception = (Throwable) request .getAttribute(DispatcherServlet.EXCEPTION_ATTRIBUTE); record(timingContext, response, request, exception); } } catch (NestedServletException ex) { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); record(timingContext, response, request, ex.getCause()); throw ex; } }
@Override protected void doFilterInternal(HttpServletRequest request, final HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { try { if (matches(request)) { IdentityProvider idp = identityProviderProvisioning.retrieveByOrigin(OriginKeys.UAA, IdentityZoneHolder.get().getId()); boolean isDisableInternalUserManagement = false; UaaIdentityProviderDefinition config = ObjectUtils.castInstance(idp.getConfig(), UaaIdentityProviderDefinition.class); if (config != null) { isDisableInternalUserManagement = config.isDisableInternalUserManagement(); } if (isDisableInternalUserManagement) { throw new InternalUserManagementDisabledException(INTERNAL_USER_CREATION_IS_CURRENTLY_DISABLED); } } filterChain.doFilter(request, response); } catch (InternalUserManagementDisabledException x) { handleInternalUserManagementDisabledException(response, x); } catch (NestedServletException x) { if (x.getRootCause() instanceof InternalUserManagementDisabledException) { handleInternalUserManagementDisabledException(response, (InternalUserManagementDisabledException) x.getRootCause()); } else { throw x; } } }
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; }
@ExceptionHandler(NestedServletException.class) public ResponseEntity<String> HandleNested(NestedServletException ex) { Throwable cause = ex.getCause(); if (cause instanceof InternalError) { // deal with it } else if (cause instanceof OtherError) { // deal in some other way } }
/** * Return the nested cause, or <code>null</code> if none. */ public Throwable getCause() { // Even if you cannot set the cause of this exception other than through // the constructor, we check for the cause being "this" here, as the cause // could still be set to "this" via reflection: for example, by a remoting // deserializer like Hessian's. return (getRootCause() == this ? null : getRootCause()); }
/** * 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); } }
@ExceptionHandler(org.springframework.web.util.NestedServletException.class) public void test(NestedServletException e) { Throwable t = e.getCause(); logger.debug("*************************** "+t.getClass().getName()); }
cause = ((org.springframework.web.util.NestedServletException) cause).getRootCause(); if (cause == null) { cause = e;
/** * 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); } }