use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class TestActionServlet method testInitModuleExceptionConfigsNullFormType.
/**
* Test that initModuleExceptionConfigs throws an exception when a handler
* with a null key is present.
*/
public void testInitModuleExceptionConfigsNullFormType() throws ServletException {
ExceptionConfig handler = new ExceptionConfig();
handler.setType("java.lang.NullPointerException");
moduleConfig.addExceptionConfig(handler);
try {
actionServlet.initModuleExceptionConfigs(moduleConfig);
fail("An exception should've been thrown here.");
} catch (UnavailableException e) {
// success
} catch (Exception e) {
fail("Unrecognized exception thrown: " + e);
}
}
use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class TestActionServlet method testProcessExceptionConfigClassNoExtends.
/**
* Make sure processExceptionConfigClass() returns what it was given if
* the handler passed to it doesn't extend anything.
*/
public void testProcessExceptionConfigClassNoExtends() throws Exception {
moduleConfig.addExceptionConfig(baseException);
ExceptionConfig result = null;
try {
result = actionServlet.processExceptionConfigClass(baseException, moduleConfig, null);
} catch (UnavailableException e) {
fail("An exception should not be thrown when there's nothing to do");
}
assertSame("Result should be the same as the input.", baseException, result);
}
use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class ValidatorPlugIn method init.
/**
* Initialize and load our resources.
*
* @param servlet The ActionServlet for our application
* @param config The ModuleConfig for our owning module
* @throws ServletException if we cannot configure ourselves correctly
*/
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
// Remember our associated configuration and servlet
this.config = config;
this.servlet = servlet;
// Load our database from persistent storage
try {
this.initResources();
servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(), resources);
servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.' + config.getPrefix(), (this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE));
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new UnavailableException("Cannot load a validator resource from '" + pathnames + "'");
}
}
use of javax.servlet.UnavailableException in project com.revolsys.open by revolsys.
the class IafServlet method init.
/**
* Initialise the servlet. Loads the configuration from the
* /WEB-INF/nice-config.xml file.
*
* @param config The servlet configuration parameters
* @exception ServletException if there was a problem initialising the servlet
*/
@Override
public void init(final ServletConfig config) throws ServletException {
super.init(config);
try {
this.servletContext = config.getServletContext();
final URL configResource = this.servletContext.getResource("/WEB-INF/iaf-config.xml");
WebUiContext.setServletContext(this.servletContext);
final XmlConfigLoader configLoader = new XmlConfigLoader(configResource, this.servletContext);
this.applicationConfig = configLoader.loadConfig();
this.servletContext.setAttribute("rsWebUiConfig", this.applicationConfig);
} catch (final InvalidConfigException ice) {
ice.printStackTrace();
log.fatal(ice.getErrors());
throw new UnavailableException(ice.getMessage() + ":" + ice.getErrors());
} catch (final MalformedURLException mue) {
log.fatal(mue.getMessage(), mue);
throw new UnavailableException("Failed to initialise Servlet");
} catch (final Throwable t) {
t.printStackTrace();
log.error(t.getMessage(), t);
}
}
use of javax.servlet.UnavailableException in project Payara by payara.
the class StandardWrapper method initServlet.
/**
* Initializes the given servlet instance, by calling its init method.
*/
private void initServlet(Servlet servlet) throws ServletException {
if (instanceInitialized && !singleThreadModel) {
// Servlet has already been initialized
return;
}
try {
instanceSupport.fireInstanceEvent(BEFORE_INIT_EVENT, servlet);
// START SJS WS 7.0 6236329
if (executeUnderSubjectDoAs()) {
// END OF SJS WS 7.0 6236329
Object[] initType = { facade };
doAsPrivilege("init", servlet, classType, initType);
initType = null;
} else {
servlet.init(facade);
}
instanceInitialized = true;
// Invoke jspInit on JSP pages
if (loadOnStartup >= 0 && jspFile != null) {
// Invoking jspInit
DummyRequest req = new DummyRequest();
req.setServletPath(jspFile);
req.setQueryString("jsp_precompile=true");
// START PWC 4707989
String allowedMethods = parameters.get("httpMethods");
if (allowedMethods != null && allowedMethods.length() > 0) {
String[] allowedMethod = allowedMethods.split(",");
if (allowedMethod.length > 0) {
req.setMethod(allowedMethod[0].trim());
}
}
// END PWC 4707989
DummyResponse res = new DummyResponse();
// START SJS WS 7.0 6236329
if (executeUnderSubjectDoAs()) {
// END OF SJS WS 7.0 6236329
Object[] serviceType = { req, res };
doAsPrivilege("service", servlet, classTypeUsedInService, serviceType);
} else {
servlet.service(req, res);
}
}
instanceSupport.fireInstanceEvent(AFTER_INIT_EVENT, servlet);
} catch (UnavailableException f) {
instanceSupport.fireInstanceEvent(AFTER_INIT_EVENT, servlet, f);
unavailable(f);
throw f;
} catch (ServletException f) {
instanceSupport.fireInstanceEvent(AFTER_INIT_EVENT, servlet, f);
// said so, so do not call unavailable(null).
throw f;
} catch (Throwable f) {
getServletContext().log("StandardWrapper.Throwable", f);
instanceSupport.fireInstanceEvent(AFTER_INIT_EVENT, servlet, f);
// said so, so do not call unavailable(null).
throw new ServletException(format(rb.getString(SERVLET_INIT_EXCEPTION), getName()), f);
}
}
Aggregations