use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class TestActionServlet method notestProcessActionConfigClassError.
/**
* Make sure the code throws the correct exception when it can't create an
* instance of the base config's custom class.
*/
public void notestProcessActionConfigClassError() throws Exception {
ActionConfig customBase = new CustomActionConfigArg("/index");
moduleConfig.addActionConfig(customBase);
ActionConfig customSub = new ActionMapping();
customSub.setPath("/sub");
customSub.setExtends("/index");
moduleConfig.addActionConfig(customSub);
try {
actionServlet.processActionConfigClass(customSub, moduleConfig);
fail("Exception should be thrown");
} catch (UnavailableException e) {
// success
} catch (Exception e) {
fail("Unexpected exception thrown.");
}
}
use of javax.servlet.UnavailableException in project i2p.i2p by i2p.
the class I2PDefaultServlet method init.
/**
* Overridden to save local copies of dirAllowed, locale, resourceBase, and stylesheet.
* Calls super.
*/
@Override
public void init() throws UnavailableException {
super.init();
_dirAllowed = getInitBoolean("dirAllowed", _dirAllowed);
String rb = getInitParameter("resourceBase");
if (rb != null) {
try {
_resourceBase = _contextHandler.newResource(rb);
} catch (Exception e) {
throw new UnavailableException(e.toString());
}
}
String css = getInitParameter("stylesheet");
try {
if (css != null) {
_stylesheet = Resource.newResource(css);
if (!_stylesheet.exists()) {
_stylesheet = null;
}
}
if (_stylesheet == null) {
_stylesheet = Resource.newResource(this.getClass().getResource("/jetty-dir.css"));
}
} catch (Exception e) {
}
}
use of javax.servlet.UnavailableException in project com.revolsys.open by revolsys.
the class IafServletFilter method init.
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
String config = filterConfig.getInitParameter("config");
if (config == null) {
config = "/WEB-INF/iaf-config.xml";
}
final ServletContext servletContext = filterConfig.getServletContext();
WebUiContext.setServletContext(servletContext);
final WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
try {
final URL configResource = servletContext.getResource(config);
final XmlConfigLoader configLoader = new XmlConfigLoader(configResource, servletContext);
this.rsWebUiConfig = configLoader.loadConfig();
servletContext.setAttribute("rsWebUiConfig", this.rsWebUiConfig);
} catch (final InvalidConfigException e) {
log.error(e.getErrors(), e);
throw new UnavailableException("Cannot load a rsWebUiConfig resource from '" + config + "' due to " + e.getErrors());
} catch (final Exception e) {
log.error(e.getMessage(), e);
throw new UnavailableException("Cannot load a rsWebUiConfig resource from '" + config + "' due to " + e.getMessage());
}
}
use of javax.servlet.UnavailableException in project com.revolsys.open by revolsys.
the class WebUiFilter method loadIafConfig.
private void loadIafConfig(final String config, final FilterConfig filterConfig) throws UnavailableException {
final ServletContext servletContext = filterConfig.getServletContext();
WebUiContext.setServletContext(servletContext);
this.applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
try {
final URL configResource = servletContext.getResource(config);
final XmlConfigLoader configLoader = new XmlConfigLoader(configResource, servletContext);
this.rsWebUiConfig = configLoader.loadConfig();
servletContext.setAttribute("rsWebUiConfig", this.rsWebUiConfig);
} catch (final InvalidConfigException e) {
LOG.error(e.getErrors(), e);
throw new UnavailableException("Cannot load a rsWebUiConfig resource from '" + config + "' due to " + e.getErrors());
} catch (final Exception e) {
LOG.error(e.getMessage(), e);
throw new UnavailableException("Cannot load a rsWebUiConfig resource from '" + config + "' due to " + e.getMessage());
}
}
use of javax.servlet.UnavailableException in project tomcat70 by apache.
the class SecurityUtil method execute.
/**
* Perform work as a particular </code>Subject</code>. Here the work
* will be granted to a <code>null</code> subject.
*
* @param method the method to apply the security restriction
* @param targetObject the <code>Servlet</code> on which the method will
* be called.
* @param targetArguments <code>Object</code> array contains the
* runtime parameters instance.
* @param principal the <code>Principal</code> to which the security
* privilege applies
*/
private static void execute(final Method method, final Object targetObject, final Object[] targetArguments, Principal principal) throws java.lang.Exception {
try {
Subject subject = null;
PrivilegedExceptionAction<Void> pea = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
method.invoke(targetObject, targetArguments);
return null;
}
};
// The first argument is always the request object
if (targetArguments != null && targetArguments[0] instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) targetArguments[0];
boolean hasSubject = false;
HttpSession session = request.getSession(false);
if (session != null) {
subject = (Subject) session.getAttribute(Globals.SUBJECT_ATTR);
hasSubject = (subject != null);
}
if (subject == null) {
subject = new Subject();
if (principal != null) {
subject.getPrincipals().add(principal);
}
}
if (session != null && !hasSubject) {
session.setAttribute(Globals.SUBJECT_ATTR, subject);
}
}
Subject.doAsPrivileged(subject, pea, null);
} catch (PrivilegedActionException pe) {
Throwable e;
if (pe.getException() instanceof InvocationTargetException) {
e = pe.getException().getCause();
ExceptionUtils.handleThrowable(e);
} else {
e = pe;
}
if (log.isDebugEnabled()) {
log.debug(sm.getString("SecurityUtil.doAsPrivilege"), e);
}
if (e instanceof UnavailableException)
throw (UnavailableException) e;
else if (e instanceof ServletException)
throw (ServletException) e;
else if (e instanceof IOException)
throw (IOException) e;
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new ServletException(e.getMessage(), e);
}
}
Aggregations