Example usage for javax.servlet ServletException getCause

List of usage examples for javax.servlet ServletException getCause

Introduction

In this page you can find the example usage for javax.servlet ServletException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.jasig.cas.client.util.ErrorRedirectFilter.java

public void doFilter(final ServletRequest request, final ServletResponse response,
        final FilterChain filterChain) throws IOException, ServletException {
    final HttpServletResponse httpResponse = (HttpServletResponse) response;
    try {/*www.j av  a  2  s  . c om*/
        filterChain.doFilter(request, response);
    } catch (final ServletException e) {
        final Throwable t = e.getCause();
        ErrorHolder currentMatch = null;
        for (final Iterator iter = this.errors.iterator(); iter.hasNext();) {
            final ErrorHolder errorHolder = (ErrorHolder) iter.next();
            if (errorHolder.exactMatch(t)) {
                currentMatch = errorHolder;
                break;
            } else if (errorHolder.inheritanceMatch(t)) {
                currentMatch = errorHolder;
            }
        }

        if (currentMatch != null) {
            httpResponse.sendRedirect(currentMatch.getUrl());
        } else {
            httpResponse.sendRedirect(defaultErrorRedirectPage);
        }
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.component.file.NXFileRenderer.java

@Override
public void decode(FacesContext context, UIComponent component) {

    rendererParamsNotNull(context, component);

    if (!shouldDecode(component)) {
        return;/*from   www  . j  ava2 s. co m*/
    }

    String clientId = decodeBehaviors(context, component);

    if (clientId == null) {
        clientId = component.getClientId(context);
    }

    assert (clientId != null);
    ExternalContext externalContext = context.getExternalContext();
    Map<String, String> requestMap = externalContext.getRequestParameterMap();

    if (requestMap.containsKey(clientId)) {
        setSubmittedValue(component, requestMap.get(clientId));
    }

    HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
    try {
        Collection<Part> parts = request.getParts();
        for (Part cur : parts) {
            if (clientId.equals(cur.getName())) {
                // Nuxeo patch: transform into serializable blob right away, and do not set component transient
                // component.setTransient(true);
                // setSubmittedValue(component, cur);
                setSubmittedValue(component, FileUtils.createBlob(cur));
            }
        }
    } catch (IOException ioe) {
        throw new FacesException(ioe);
    } catch (ServletException se) {
        Throwable cause = se.getCause();
        // Nuxeo specific error management
        if ((cause instanceof InvalidContentTypeException)
                || (cause != null && cause.getClass().getName().contains("InvalidContentTypeException"))) {
            setSubmittedValue(component, Blobs.createBlob(""));
        } else {
            throw new FacesException(se);
        }
    }
}

From source file:org.zilverline.core.TestIndexException.java

/**
 * This methods tests ServletException and 1.4 Throwable cause hierarchy.
 *///from ww  w. j  av a2 s  . c  o  m
public void testExceptionHierarchy() {
    try {
        try {
            throw new Exception("Error");
        } catch (Exception e) {
            try {
                throw new IndexException("Error in Index", e);
            } catch (IndexException ie) {
                throw new ServletException("Error in Servlet", ie);
            }
        }
    } catch (ServletException se) {
        Throwable rootCause = se.getRootCause();
        Throwable seCause = se.getCause();

        assertNotNull(rootCause);
        assertNull(seCause);
        assertEquals("Error in Index", rootCause.getMessage());

        Throwable cause = rootCause.getCause();

        assertNotNull(cause);
        assertEquals("Error", cause.getMessage());
        assertEquals("Error in Servlet", se.getMessage());
    }
}