Example usage for org.springframework.web.util NestedServletException NestedServletException

List of usage examples for org.springframework.web.util NestedServletException NestedServletException

Introduction

In this page you can find the example usage for org.springframework.web.util NestedServletException NestedServletException.

Prototype

public NestedServletException(@Nullable String msg, @Nullable Throwable cause) 

Source Link

Document

Construct a NestedServletException with the specified detail message and nested exception.

Usage

From source file:architecture.ee.web.servlet.ViewRendererServlet.java

protected final void processRequest(HttpServletRequest httpservletrequest,
        HttpServletResponse httpservletresponse) throws ServletException, IOException {
    try {//w  ww.j  a  va  2 s .c  o  m
        httpservletrequest.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
                WebApplicationContextUtils.getWebApplicationContext(getServletContext()));
        renderView(httpservletrequest, httpservletresponse);
    } catch (ServletException servletexception) {
        throw servletexception;
    } catch (IOException ioexception) {
        throw ioexception;
    } catch (Exception exception) {
        throw new NestedServletException("View rendering failed", exception);
    }
}

From source file:org.meruvian.yama.webapp.interceptor.OAuth2ClientContextInterceptor.java

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext()
            .get(ServletActionContext.HTTP_REQUEST);
    HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext()
            .get(ServletActionContext.HTTP_RESPONSE);
    request.setAttribute(CURRENT_URI, calculateCurrentUri(request));

    String result = "";

    try {/*from   w  w w. j a v a 2 s  .  c  o m*/
        result = invocation.invoke();
    } 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);
        }
    }

    return result;
}

From source file:com.jigsforjava.web.controller.MultiActionController.java

/**
 * We've encountered an exception which may be recoverable
 * (InvocationTargetException or HttpSessionRequiredException). Allow the
 * subclass a chance to handle it.//from  w w w  .java2  s. c om
 * 
 * @param request current HTTP request
 * @param response current HTTP response
 * @param ex the exception that got thrown
 * @return a ModelAndView to render the response
 */
protected ModelAndView handleException(HttpServletRequest request, HttpServletResponse response, Throwable ex)
        throws Exception {
    Method handler = getExceptionHandler(ex);
    if (handler != null) {
        return invokeExceptionHandler(handler, request, response, ex);
    }

    // If we get here, there was no custom handler
    if (ex instanceof Exception) {
        throw (Exception) ex;
    }
    if (ex instanceof Error) {
        throw (Error) ex;
    }

    // Should never happen!
    throw new NestedServletException("Unknown Throwable type encountered", ex);
}

From source file:co.paralleluniverse.springframework.web.servlet.mvc.method.annotation.FiberServletInvocableHandlerMethod.java

/**
 * Create a ServletInvocableHandlerMethod that will return the given value from an
 * async operation instead of invoking the controller method again. The async result
 * value is then either processed as if the controller method returned it or an
 * exception is raised if the async result value itself is an Exception.
 *//*from  w  ww  .j  a va2 s . co m*/
FiberServletInvocableHandlerMethod wrapConcurrentResult(final Object result) {
    return new CallableHandlerMethod(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            if (result instanceof Exception) {
                throw (Exception) result;
            } else if (result instanceof Throwable) {
                throw new NestedServletException("Async processing failed", (Throwable) result);
            }
            return result;
        }
    });
}

From source file:com.jigsforjava.web.controller.MultiActionController.java

/**
 * Invoke the selected exception handler.
 * //from   ww w.j av a 2 s.  c  o  m
 * @param handler handler method to invoke
 * @param request current HTTP request
 * @param response current HTTP response
 * @param ex the exception that got thrown
 * @return The ModelAndView instance appropriate to render to the end user.
 */
private ModelAndView invokeExceptionHandler(Method handler, HttpServletRequest request,
        HttpServletResponse response, Throwable ex) throws Exception {
    if (handler == null) {
        throw new NestedServletException("No handler for exception", ex);
    }

    try {
        ViewContext returnValue = (ViewContext) handler.invoke(this, new Object[] { request, response, ex });
        return (returnValue != null ? returnValue.asModelAndView() : null);
    } catch (InvocationTargetException ex2) {
        Throwable targetEx = ex2.getTargetException();
        if (targetEx instanceof Exception) {
            throw (Exception) targetEx;
        }
        if (targetEx instanceof Error) {
            throw (Error) targetEx;
        }
        // Should never happen!
        throw new NestedServletException("Unknown Throwable type encountered", targetEx);
    }
}

From source file:com.laxser.blitz.BlitzFilter.java

/**
 *  {@link GenericFilterBean#initFilterBean()} Blitz ?
 *//*from ww  w  . j  a  v a 2s  . co  m*/

@Override
protected final void initFilterBean() throws ServletException {
    try {
        if (logger.isInfoEnabled()) {
            logger.info("[init] call 'init/rootContext'");
        }

        if (logger.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder();
            Enumeration<String> iter = getFilterConfig().getInitParameterNames();
            while (iter.hasMoreElements()) {
                String name = (String) iter.nextElement();
                sb.append(name).append("='").append(getFilterConfig().getInitParameter(name)).append("'\n");
            }
            logger.debug("[init] parameters: " + sb);
        }

        WebApplicationContext rootContext = prepareRootApplicationContext();

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/rootContext'");
            logger.info("[init] call 'init/module'");
        }

        //  Blitz ??
        this.modules = prepareModules(rootContext);

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/module'");
            logger.info("[init] call 'init/mappingTree'");
        }

        // ???(Engine)
        this.mappingTree = prepareMappingTree(modules);

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/mappingTree'");
            logger.info("[init] exits from 'init'");
        }

        // ???
        printBlitzInfos();

        //
    } catch (final Throwable e) {
        StringBuilder sb = new StringBuilder(1024);
        sb.append("[Blitz-").append(BlitzVersion.getVersion());
        sb.append("@Spring-").append(SpringVersion.getVersion()).append("]:");
        sb.append(e.getMessage());
        logger.error(sb.toString(), e);
        throw new NestedServletException(sb.toString(), e);
    }
}

From source file:net.paoding.rose.RoseFilter.java

/**
 *  {@link GenericFilterBean#initFilterBean()} Rose ?
 *//*from   ww  w. ja  v a2 s .co  m*/

@Override
protected final void initFilterBean() throws ServletException {
    try {
        if (logger.isInfoEnabled()) {
            logger.info("[init] call 'init/rootContext'");
        }

        if (logger.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder();
            @SuppressWarnings("unchecked")
            Enumeration<String> iter = getFilterConfig().getInitParameterNames();
            while (iter.hasMoreElements()) {
                String name = (String) iter.nextElement();
                sb.append(name).append("='").append(getFilterConfig().getInitParameter(name)).append("'\n");
            }
            logger.debug("[init] parameters: " + sb);
        }

        WebApplicationContext rootContext = prepareRootApplicationContext();

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/rootContext'");
            logger.info("[init] call 'init/module'");
        }

        //  Rose ??
        this.modules = prepareModules(rootContext);

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/module'");
            logger.info("[init] call 'init/mappingTree'");
        }

        // ???(Engine)
        this.mappingTree = prepareMappingTree(modules);

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/mappingTree'");
            logger.info("[init] exits from 'init'");
        }

        // ???
        printRoseInfos();

        //
    } catch (final Throwable e) {
        StringBuilder sb = new StringBuilder(1024);
        sb.append("[Rose-").append(RoseVersion.getVersion());
        sb.append("@Spring-").append(SpringVersion.getVersion()).append("]:");
        sb.append(e.getMessage());
        logger.error(sb.toString(), e);
        throw new NestedServletException(sb.toString(), e);
    }
}

From source file:com.sinosoft.one.mvc.MvcFilter.java

/**
 *  {@link GenericFilterBean#initFilterBean()} Mvc ?
 *///from   w  ww. j a  v a  2  s . com

@Override
protected final void initFilterBean() throws ServletException {
    try {

        long startTime = System.currentTimeMillis();

        if (logger.isInfoEnabled()) {
            logger.info("[init] call 'init/rootContext'");
        }

        if (logger.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder();
            @SuppressWarnings("unchecked")
            Enumeration<String> iter = getFilterConfig().getInitParameterNames();
            while (iter.hasMoreElements()) {
                String name = (String) iter.nextElement();
                sb.append(name).append("='").append(getFilterConfig().getInitParameter(name)).append("'\n");
            }
            logger.debug("[init] parameters: " + sb);
        }

        WebApplicationContext rootContext = prepareRootApplicationContext();

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/rootContext'");
            logger.info("[init] call 'init/module'");
        }

        //  Mvc ??
        this.modules = prepareModules(rootContext);

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/module'");
            logger.info("[init] call 'init/mappingTree'");
        }

        // ???(Engine)
        this.mappingTree = prepareMappingTree(modules);

        if (logger.isInfoEnabled()) {
            logger.info("[init] exits from 'init/mappingTree'");
            logger.info("[init] exits from 'init'");
        }

        long endTime = System.currentTimeMillis();

        // ???
        printMvcInfos(endTime - startTime);

        //
    } catch (final Throwable e) {
        StringBuilder sb = new StringBuilder(1024);
        sb.append("[Mvc-").append(MvcVersion.getVersion());
        sb.append("@Spring-").append(SpringVersion.getVersion()).append("]:");
        sb.append(e.getMessage());
        logger.error(sb.toString(), e);
        throw new NestedServletException(sb.toString(), e);
    }
}

From source file:org.sakaiproject.metaobj.shared.control.XsltArtifactView.java

/**
 * Perform the actual transformation, writing to the given result.
 * @param source the Source to transform
 * @param parameters a Map of parameters to be applied to the stylesheet
 * @param result the result to write to/* w ww  .ja  v  a 2s.c om*/
 * @throws Exception we let this method throw any exception; the
 * AbstractXlstView superclass will catch exceptions
 */
protected void doTransform(Source source, Map parameters, Result result, String encoding) throws Exception {

    InputStream stylesheetLocation = null;
    // Nulls gets logged by getTransformer, so don't bother logging again.
    if (parameters != null)
        stylesheetLocation = (InputStream) parameters.get(STYLESHEET_LOCATION);
    Transformer trans = getTransformer(stylesheetLocation);

    // Explicitly apply URIResolver to every created Transformer.
    if (getUriResolver() != null) {
        trans.setURIResolver(getUriResolver());
    }

    // Apply any subclass supplied parameters to the transformer.
    if (parameters != null) {
        for (Iterator it = parameters.entrySet().iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry) it.next();
            trans.setParameter(entry.getKey().toString(), entry.getValue());
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Added parameters [" + parameters + "] to transformer object");
        }
    }

    // Specify default output properties.
    //trans.setOutputProperty(OutputKeys.ENCODING, encoding);
    trans.setOutputProperty(OutputKeys.INDENT, "yes");

    // Xalan-specific, but won't do any harm in other XSLT engines.
    trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

    // Perform the actual XSLT transformation.
    try {
        trans.transform(source, result);
        if (logger.isDebugEnabled()) {
            logger.debug("XSLT transformed with stylesheet [" + stylesheetLocation + "]");
        }
    } catch (TransformerException ex) {
        throw new NestedServletException("Couldn't perform transform with stylesheet [" + stylesheetLocation
                + "] in XSLT view with name [" + getBeanName() + "]", ex);
    }
}