use of javax.servlet.UnavailableException in project winstone by jenkinsci.
the class UnavailableServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!this.errorAtInit)
throw new UnavailableException("Error thrown deliberately during get");
Writer out = response.getWriter();
out.write("This should not be shown, because we've thrown unavailable exceptions");
out.close();
}
use of javax.servlet.UnavailableException in project scout.rt by eclipse.
the class ServletExceptionTranslatorTest method before.
@Before
public void before() {
m_servletException = new ServletException();
m_unavailableException = new UnavailableException("");
m_platformException = new ProcessingException();
m_processingException = new ProcessingException();
m_runtimeException = new RuntimeException();
m_illegalArgumentException = new IllegalArgumentException();
m_checkedException = new Exception();
m_interruptedException = new InterruptedException();
m_throwable = new Throwable();
m_error = new Error();
}
use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class ActionServlet method splitAndResolvePaths.
/**
* <p>Takes a comma-delimited string and splits it into paths, then
* resolves those paths using the ServletContext and appropriate
* ClassLoader. When loading from the classloader, multiple resources per
* path are supported to support, for example, multiple jars containing
* the same named config file.</p>
*
* @param paths A comma-delimited string of paths
* @return A list of resolved URL's for all found resources
* @throws ServletException if a servlet exception is thrown
*/
protected List splitAndResolvePaths(String paths) throws ServletException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = this.getClass().getClassLoader();
}
ArrayList resolvedUrls = new ArrayList();
URL resource;
String path = null;
try {
// Process each specified resource path
while (paths.length() > 0) {
resource = null;
int comma = paths.indexOf(',');
if (comma >= 0) {
path = paths.substring(0, comma).trim();
paths = paths.substring(comma + 1);
} else {
path = paths.trim();
paths = "";
}
if (path.length() < 1) {
break;
}
if (path.charAt(0) == '/') {
resource = getServletContext().getResource(path);
}
if (resource == null) {
if (log.isDebugEnabled()) {
log.debug("Unable to locate " + path + " in the servlet context, " + "trying classloader.");
}
Enumeration e = loader.getResources(path);
if (!e.hasMoreElements()) {
String msg = internal.getMessage("configMissing", path);
log.error(msg);
throw new UnavailableException(msg);
} else {
while (e.hasMoreElements()) {
resolvedUrls.add(e.nextElement());
}
}
} else {
resolvedUrls.add(resource);
}
}
} catch (MalformedURLException e) {
handleConfigException(path, e);
} catch (IOException e) {
handleConfigException(path, e);
}
return resolvedUrls;
}
use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class ActionServlet method processActionConfigClass.
/**
* <p>Checks if the current actionConfig is using the correct class based
* on the class of its ancestor ActionConfig.</p>
*
* @param actionConfig The action config to check.
* @param moduleConfig The config for the current module.
* @return The config object using the correct class as determined by the
* config's ancestor and its own overridden value.
* @throws ServletException if an instance of the action config class
* cannot be created.
*/
protected ActionConfig processActionConfigClass(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException {
String ancestor = actionConfig.getExtends();
if (ancestor == null) {
// Nothing to do, then
return actionConfig;
}
// Make sure that this config is of the right class
ActionConfig baseConfig = moduleConfig.findActionConfig(ancestor);
if (baseConfig == null) {
throw new UnavailableException("Unable to find " + "action config for '" + ancestor + "' to extend.");
}
// Was our actionConfig's class overridden already?
if (actionConfig.getClass().equals(ActionMapping.class)) {
// Ensure that our config is using the correct class
if (!baseConfig.getClass().equals(actionConfig.getClass())) {
// Replace the config with an instance of the correct class
ActionConfig newActionConfig = null;
String baseConfigClassName = baseConfig.getClass().getName();
try {
newActionConfig = (ActionConfig) RequestUtils.applicationInstance(baseConfigClassName);
// copy the values
BeanUtils.copyProperties(newActionConfig, actionConfig);
// copy the forward and exception configs, too
ForwardConfig[] forwards = actionConfig.findForwardConfigs();
for (int i = 0; i < forwards.length; i++) {
newActionConfig.addForwardConfig(forwards[i]);
}
ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
for (int i = 0; i < exceptions.length; i++) {
newActionConfig.addExceptionConfig(exceptions[i]);
}
} catch (Exception e) {
handleCreationException(baseConfigClassName, e);
}
// replace actionConfig with newActionConfig
moduleConfig.removeActionConfig(actionConfig);
moduleConfig.addActionConfig(newActionConfig);
actionConfig = newActionConfig;
}
}
return actionConfig;
}
use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class ActionServlet method parseModuleConfigFile.
/**
* <p>Parses one module config file.</p>
*
* @param digester Digester instance that does the parsing
* @param path The path to the config file to parse.
* @throws UnavailableException if file cannot be read or parsed
* @since Struts 1.2
* @deprecated use parseModuleConfigFile(Digester digester, URL url)
* instead
*/
protected void parseModuleConfigFile(Digester digester, String path) throws UnavailableException {
try {
List paths = splitAndResolvePaths(path);
if (paths.size() > 0) {
// Get first path as was the old behavior
URL url = (URL) paths.get(0);
parseModuleConfigFile(digester, url);
} else {
throw new UnavailableException("Cannot locate path " + path);
}
} catch (UnavailableException ex) {
throw ex;
} catch (ServletException ex) {
handleConfigException(path, ex);
}
}
Aggregations