Example usage for javax.servlet ServletException getRootCause

List of usage examples for javax.servlet ServletException getRootCause

Introduction

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

Prototype


public Throwable getRootCause() 

Source Link

Document

Returns the exception that caused this servlet exception.

Usage

From source file:org.opennms.netmgt.ncs.rest.AbstractSpringJerseyRestTestCase.java

@Before
public void setUp() throws Throwable {
    beforeServletStart();/*from  w w  w  .ja  v  a2s. c om*/

    setServletContext(new MockServletContext("file:src/main/webapp"));

    getServletContext().addInitParameter("contextConfigLocation",
            "file:src/main/resources/META-INF/opennms/component-service.xml");

    getServletContext().addInitParameter("parentContextKey", "testDaoContext");

    ServletContextEvent e = new ServletContextEvent(getServletContext());
    setContextListener(new ContextLoaderListener());
    getContextListener().contextInitialized(e);

    getServletContext().setContextPath(contextPath);
    setServletConfig(new MockServletConfig(getServletContext(), "dispatcher"));
    /*
    getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
    getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.netmgt.ncs.rest");
    */
    try {

        MockFilterConfig filterConfig = new MockFilterConfig(getServletContext(), "openSessionInViewFilter");
        setFilter(new OpenSessionInViewFilter());
        getFilter().init(filterConfig);

        setDispatcher(new SpringServlet());
        getDispatcher().init(getServletConfig());

    } catch (ServletException se) {
        throw se.getRootCause();
    }

    setWebAppContext(WebApplicationContextUtils.getWebApplicationContext(getServletContext()));
    afterServletStart();
    System.err.println("------------------------------------------------------------------------------");
}

From source file:com.liferay.portlet.InvokerPortletImpl.java

protected void invoke(LiferayPortletRequest portletRequest, LiferayPortletResponse portletResponse,
        String lifecycle, List<? extends PortletFilter> filters) throws IOException, PortletException {

    FilterChain filterChain = new FilterChainImpl(_portlet, filters);

    if (_portletConfigImpl.isWARFile()) {
        String invokerPortletName = _portletConfigImpl.getInitParameter(INIT_INVOKER_PORTLET_NAME);

        if (invokerPortletName == null) {
            invokerPortletName = _portletConfigImpl.getPortletName();
        }/*from   w w  w  .j  a  va 2  s  .  c o  m*/

        String path = StringPool.SLASH + invokerPortletName + "/invoke";

        RequestDispatcher requestDispatcher = _portletContextImpl.getServletContext()
                .getRequestDispatcher(path);

        HttpServletRequest request = portletRequest.getHttpServletRequest();
        HttpServletResponse response = portletResponse.getHttpServletResponse();

        request.setAttribute(JavaConstants.JAVAX_PORTLET_PORTLET, _portlet);
        request.setAttribute(PortletRequest.LIFECYCLE_PHASE, lifecycle);
        request.setAttribute(PortletServlet.PORTLET_SERVLET_FILTER_CHAIN, filterChain);

        try {

            // Resource phase must be a forward because includes do not
            // allow you to specify the content type or headers

            if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
                requestDispatcher.forward(request, response);
            } else {
                requestDispatcher.include(request, response);
            }
        } catch (ServletException se) {
            Throwable cause = se.getRootCause();

            if (cause instanceof PortletException) {
                throw (PortletException) cause;
            }

            throw new PortletException(cause);
        }
    } else {
        PortletFilterUtil.doFilter(portletRequest, portletResponse, lifecycle, filterChain);
    }

    portletResponse.transferMarkupHeadElements();

    Map<String, String[]> properties = portletResponse.getProperties();

    if ((properties != null) && (properties.size() > 0)) {
        if (_expCache != null) {
            String[] expCache = properties.get(RenderResponse.EXPIRATION_CACHE);

            if ((expCache != null) && (expCache.length > 0) && (expCache[0] != null)) {

                _expCache = new Integer(GetterUtil.getInteger(expCache[0]));
            }
        }
    }
}

From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Returns the Exception Message (Stacktrace) from the Request
 *
 * @param request/*from  ww w. j a va  2  s  . c  o m*/
 * @return
 */
@Override
public String getException(SlingHttpServletRequest request) {
    StringWriter stringWriter = new StringWriter();
    if (request.getAttribute(SlingConstants.ERROR_EXCEPTION) instanceof Throwable) {
        Throwable throwable = (Throwable) request.getAttribute(SlingConstants.ERROR_EXCEPTION);

        if (throwable == null) {
            return "";
        }

        if (throwable instanceof ServletException) {
            ServletException se = (ServletException) throwable;
            while (se.getRootCause() != null) {
                throwable = se.getRootCause();
                if (throwable instanceof ServletException) {
                    se = (ServletException) throwable;
                } else {
                    break;
                }
            }
        }

        throwable.printStackTrace(new PrintWriter(stringWriter, true));
    }

    return stringWriter.toString();
}

From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java

/**
 * testInitResources10()// ww w . j a va 2  s .c o  m
 * <br><br>
 * 
 * (?n)
 * <br>
 * _?FG
 * <br><br>
 * l?F(?) servlet:not null<br>
 *         (?) config:W?[(?)=""<br>
 *         (?) this.resourcePath:"ResetterPlugInTest-reset.xml","ResetterPlugInTest-reset2.xml","ResetterPlugInTest-reset3.xml"<br>
 *         (?) digesterRules:"ResetterPlugInTest-reset-rules.xml"<br>
 *         (?) ServletContext#getResource():?|<br>
 *         
 * <br>
 * l?F(?) RESETTER_RESOURCES:?|<br>
 *         (?) digesterRules:?|<br>
 *         (?) O:ServletException<br>
 *                    bvO?FIOException<br>
 *         (?) ?O:??O?<br>
 *                    G?[?O?F""<br>
 *                    O?FIOException<br>
 *         
 * <br>
 * getPublicIdentifier()?AURLIuWFNg????
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testInitResources10() throws Exception {
    // W?[??
    ModuleConfig conf = new ModuleConfigImpl("");

    plugin = new ResetterPlugIn() {
        @Override
        public String getPublicIdentifier() {
            return "";
        }
    };

    // reset.xmlpX?
    UTUtil.setPrivateField(plugin, "resourcesPath",
            RESET_FILE_NAME + "," + RESET_FILE_NAME2 + "," + RESET_FILE_NAME3);
    // reset-rules.xmlpX?
    UTUtil.setPrivateField(plugin, "digesterRules", RESET_RULES_FILE_NAME);

    // ANVT?[ubg??
    ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01();

    // eXg?s
    try {
        plugin.initResources(servlet, conf);
        fail("eXgs");
    } catch (ServletException e) {
        assertTrue(e.getRootCause() instanceof IOException);
        assertTrue(LogUTUtil.checkError("", e.getRootCause()));
    }

}

From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java

/**
 * testInitResources03()/*from   w  w w .java  2  s.c o m*/
 * <br><br>
 * 
 * (?n)
 * <br>
 * _?FG
 * <br><br>
 * l?F(?) servlet:not null<br>
 *         (?) config:W?[(?)=""<br>
 *         (?) this.resourcePath:"ResetterPlugInTest-reset.xml"<br>
 *         (?) digesterRules:null<br>
 *         (?) ServletContext#getResource():?|<br>
 *         
 * <br>
 * l?F(?) RESETTER_RESOURCES:?|<br>
 *         (?) digesterRules:"/WEB-INF/reset-rules.xml"<br>
 *         (?) O:ServletException<br>
 *                    bvO?FXmlLoadException<br>
 *         (?) ?O:??O?<br>
 *                    G?[?O?F""<br>
 *                    O?FXmlLoadException<br>
 *         
 * <br>
 * digesterRulesw???AftHgt@Ci[mF?B?AdigesterRulest@C?t@CServletException?mF?B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testInitResources03() throws Exception {
    // W?[??
    ModuleConfig conf = new ModuleConfigImpl("");

    // reset.xmlpX?
    UTUtil.setPrivateField(plugin, "resourcesPath", RESET_FILE_NAME);

    // ANVT?[ubg??
    ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01();

    try {
        // eXg?s
        plugin.initResources(servlet, conf);
        fail();
    } catch (ServletException e) {
        assertEquals(XmlLoadException.class.getName(), e.getRootCause().getClass().getName());
        assertTrue(LogUTUtil.checkError("", e.getRootCause()));
        assertEquals("/WEB-INF/reset-rules.xml", UTUtil.getPrivateField(plugin, "digesterRules"));
    }
}

From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java

/**
 * testInitResources04()// w  w w  .ja v  a2  s.  co  m
 * <br><br>
 * 
 * (?n)
 * <br>
 * _?FG
 * <br><br>
 * l?F(?) servlet:not null<br>
 *         (?) config:W?[(?)=""<br>
 *         (?) this.resourcePath:"ResetterPlugInTest-reset.xml"<br>
 *         (?) digesterRules:"ResetterPlugInTest-reset-rules.xml"<br>
 *         (?) ServletContext#getResource():MalformedURLException?<br>
 *         
 * <br>
 * l?F(?) RESETTER_RESOURCES:?|<br>
 *         (?) digesterRules:"ResetterPlugInTest-reset-rules.xml"<br>
 *         (?) O:ServletException<br>
 *                    bvO?FMalformedURLException<br>
 *         (?) ?O:??O?<br>
 *                    G?[?O?F""<br>
 *                    O?FMalformedURLException<br>
 *         
 * <br>
 * ServletContext#getResource()MalformedURLException??AServletExceptionbvmF?B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testInitResources04() throws Exception {
    // W?[??
    ModuleConfig conf = new ModuleConfigImpl("");

    // reset.xmlpX?
    UTUtil.setPrivateField(plugin, "resourcesPath", RESET_FILE_NAME);
    // reset-rules.xmlpX?
    UTUtil.setPrivateField(plugin, "digesterRules", RESET_RULES_FILE_NAME);

    // ANVT?[ubg??
    ResetterPlugIn_ActionServletStub02 servlet = new ResetterPlugIn_ActionServletStub02();

    try {
        // eXg?s
        plugin.initResources(servlet, conf);
        fail();
    } catch (ServletException e) {
        assertEquals(MalformedURLException.class.getName(), e.getRootCause().getClass().getName());
        assertTrue(LogUTUtil.checkError("", e.getRootCause()));
        assertEquals(RESET_RULES_FILE_NAME, UTUtil.getPrivateField(plugin, "digesterRules"));
    }
}

From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java

/**
 * testInitResetter03()/*from   w  w  w . j  a  v  a  2  s .co m*/
 * <br><br>
 * 
 * (?n)
 * <br>
 * _?FG
 * <br><br>
 * l?F(?) servlet:not null<br>
 *         (?) config:W?[(?)=""<br>
 *         (?) this.resetter:Nothing?i?NX?j<br>
 *         
 * <br>
 * l?F(?) RESETTER:?|<br>
 *         (?) O:ServletException<br>
 *                    bvO?FClassLoadException(ClassNotFoundException)<br>
 *         (?) ?O:??O?<br>
 *                    G?[?O?F""<br>
 *                    O?FClassLoadException<br>
 *         
 * <br>
 * this.resetter?NX?AServletException?mF?B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testInitResetter03() throws Exception {
    // W?[??
    ModuleConfig conf = new ModuleConfigImpl("");

    // Zb^?[NXS?C?NX?
    UTUtil.setPrivateField(plugin, "resetter", "Nothing");

    // ANVT?[ubg??
    ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01();

    try {
        // eXg?s
        plugin.initResetter(servlet, conf);
        fail();
    } catch (ServletException e) {
        // mF
        assertEquals(ClassLoadException.class.getName(), e.getRootCause().getClass().getName());
        assertEquals(ClassNotFoundException.class.getName(), e.getRootCause().getCause().getClass().getName());
        assertTrue(LogUTUtil.checkError("", e.getRootCause()));
    }
}

From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java

/**
 * testInitResources08()//from   w w  w.  jav  a2  s  . c  o  m
 * <br><br>
 * 
 * (?n)
 * <br>
 * _?FG
 * <br><br>
 * l?F(?) servlet:not null<br>
 *         (?) config:W?[(?)=""<br>
 *         (?) this.resourcePath:"ResetterPlugInTest-error-reset.xml"(p?[XG?[?t@C)<br>
 *         (?) digesterRules:"ResetterPlugInTest-reset-rules.xml"<br>
 *         (?) ServletContext#getResource():?|<br>
 *         
 * <br>
 * l?F(?) RESETTER_RESOURCES:?|<br>
 *         (?) digesterRules:?|<br>
 *         (?) O:ServletException<br>
 *                    bvO?FSAXException<br>
 *         (?) ?O:??O?<br>
 *                    G?[?O?F""<br>
 *                    O?FSAXException<br>
 *         
 * <br>
 * this.resourcesPathp?[XG?[?t@Cw?AServletException?mF?B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testInitResources08() throws Exception {
    // W?[??
    ModuleConfig conf = new ModuleConfigImpl("");

    // reset.xmlpX?
    UTUtil.setPrivateField(plugin, "resourcesPath",
            ResetterPlugInTest.class.getResource("ResetterPlugInTest-error-reset.xml").getPath());

    // reset-rules.xmlpX?
    UTUtil.setPrivateField(plugin, "digesterRules", RESET_RULES_FILE_NAME);

    // ANVT?[ubg??
    ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01();

    // eXg?s
    try {
        plugin.init(servlet, conf);
        fail();
    } catch (ServletException e) {
        // mF
        // ????ASAXParseException??AcatchSAXExceptioninstanceof`FbN
        assertTrue(e.getRootCause() instanceof SAXException);
        assertTrue(LogUTUtil.checkError("", e.getRootCause()));
    }
}

From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java

/**
 * testInitResources07()//from   w  w  w  . j a va 2 s  . c o  m
 * <br><br>
 * 
 * (?n)
 * <br>
 * _?FG
 * <br><br>
 * l?F(?) servlet:not null<br>
 *         (?) config:W?[(?)=""<br>
 *         (?) this.resourcePath:"nothing.xml"?i?t@C?j<br>
 *         (?) digesterRules:"ResetterPlugInTest-reset-rules.xml"<br>
 *         (?) ServletContext#getResource():?|<br>
 *         
 * <br>
 * l?F(?) RESETTER_RESOURCES:?|<br>
 *         (?) digesterRules:?|<br>
 *         (?) O:ServletException<br>
 *                    bvO?FIOException<br>
 *         (?) ?O:??O?<br>
 *                    G?[?O?F""<br>
 *                    O?FIOException<br>
 *         
 * <br>
 * this.resourcePath?t@Cw???AServletException?mF?B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testInitResources07() throws Exception {
    // W?[??
    ModuleConfig conf = new ModuleConfigImpl("");

    // reset.xmlpX?
    UTUtil.setPrivateField(plugin, "resourcesPath", "nothing.xml");

    // reset-rules.xmlpX?
    UTUtil.setPrivateField(plugin, "digesterRules", RESET_RULES_FILE_NAME);

    // ANVT?[ubg??
    ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01();

    // eXg?s
    try {
        plugin.initResources(servlet, conf);
        fail();
    } catch (ServletException e) {
        // mF
        // ????AMalformedURLException??AcatchIOExceptioninstanceof`FbN
        assertTrue(e.getRootCause() instanceof IOException);
        assertTrue(LogUTUtil.checkError("", e.getRootCause()));
    }
}

From source file:jp.terasoluna.fw.web.struts.plugins.BLogicIOPlugInTest.java

/**
 * testInit18()//from w w w . j  a v  a 2 s  . c o  m
 * <br><br>
 *
 * (?n)
 * <br>
 * _?FG
 * <br><br>
 * l?F(?) servlet:not null<br>
 *         (?) config:W?[(?)=""<br>
 *         (?) rules?iDigester?[t@C?j:"BLogicIOPlugInTest-blogic-io-rules.xml"<br>
 *         (?) blogic-io?i?WbN?o?}bsO`t@C?j:"BLogicIOPlugInTest-blogic-io4.xml"<br>
 *                bean-namew?B
 *         (?) mapperStr?i?WbN?o?fNX?j:null<br>
 *         (?) digester:null<br>
 *
 * <br>
 * l?F(?) O:ServletException<br>
 *                    bvO?F<br>
 *                    IOException<br>
 *         (?) ?O:??O?<br>
 *                    G?[?O?F""<br>
 *                    O?FIOException<br>
 *
 * <br>
 * getPublicIdentifier()?AURLIuWFNg????
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testInit18() throws Exception {
    // eXgf?[^?
    // W?[??
    ModuleConfig config = new ModuleConfigImpl("");

    plugin = new BLogicIOPlugIn() {
        @Override
        public String getPublicIdentifier() {
            return "";
        }
    };

    // BLogic`?[t@C
    UTUtil.setPrivateField(plugin, "digesterRules",
            BLogicIOPlugInTest.class.getResource("BLogicIOPlugInTest-blogic-io-rules.xml").getPath());
    // BLogic`t@C
    UTUtil.setPrivateField(plugin, "resources",
            BLogicIOPlugInTest.class.getResource("BLogicIOPlugInTest-blogic-io4.xml").getPath());
    // }bp?[NX
    UTUtil.setPrivateField(plugin, "mapperStr", null);

    // ANVT?[ubg??
    BLogicIOPlugIn_ActionServletStub01 servlet = new BLogicIOPlugIn_ActionServletStub01();

    // eXg?s
    try {
        plugin.init(servlet, config);
        fail("eXgs");
    } catch (ServletException e) {
        assertTrue(e.getRootCause() instanceof IOException);
        assertTrue(LogUTUtil.checkError("", e.getRootCause()));
    }

}