List of usage examples for javax.servlet UnavailableException UnavailableException
public UnavailableException(String msg)
From source file:org.seasar.struts.hotdeploy.impl.ChainConfigLoaderImpl.java
protected List splitAndResolvePaths(String paths) throws ServletException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = this.getClass().getClassLoader(); }//from w ww. ja v a 2 s .co m 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 = getActionServlet().getInternal().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) { throw new ServletException(path, e); } catch (IOException e) { throw new ServletException(path, e); } return resolvedUrls; }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
protected void parseModuleConfigFile(Digester digester, URL url) throws UnavailableException { InputStream input = null;/* www. j a va 2 s .co m*/ try { InputSource is = new InputSource(url.toExternalForm()); URLConnection conn = url.openConnection(); conn.setUseCaches(false); conn.connect(); input = conn.getInputStream(); is.setByteStream(input); digester.parse(is); } catch (IOException e) { handleConfigException(url.toString(), e); } catch (SAXException e) { handleConfigException(url.toString(), e); } finally { if (input != null) { try { input.close(); } catch (IOException e) { throw new UnavailableException(e.getMessage()); } } } }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
/** * <p>/*from w w w .ja va2s . c om*/ * Simplifies exception handling in the parseModuleConfigFile method. * <p> * * @param path * The path to which the exception relates. * @param e * The exception to be wrapped and thrown. * @throws UnavailableException * as a wrapper around Exception */ private void handleConfigException(String path, Exception e) throws UnavailableException { String msg = getActionServlet().getInternal().getMessage("configParse", path); log.error(msg, e); throw new UnavailableException(msg); }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
/** * <p>/* w w w .j ava 2 s . c om*/ * Handle errors related to creating an instance of the specified class. * </p> * * @param className * The className that could not be instantiated. * @param e * The exception that was caught. * @throws ServletException * to communicate the error. */ private void handleCreationException(String className, Exception e) throws ServletException { String errorMessage = getActionServlet().getInternal().getMessage("configExtends.creation", className); log.error(errorMessage, e); throw new UnavailableException(errorMessage); }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
/** * <p>//w w w .j a va2s .co m * General handling for exceptions caught while inheriting config * information. * </p> * * @param configType * The type of configuration object of configName. * @param configName * The name of the config that could not be extended. * @param e * The exception that was caught. * @throws ServletException * to communicate the error. */ private void handleGeneralExtensionException(String configType, String configName, Exception e) throws ServletException { String errorMessage = getActionServlet().getInternal().getMessage("configExtends", configType, configName); log.error(errorMessage, e); throw new UnavailableException(errorMessage); }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
/** * <p>/*from www.j a v a2s . com*/ * Handle errors caused by required fields that were not specified. * </p> * * @param field * The name of the required field that was not found. * @param configType * The type of configuration object of configName. * @param configName * The name of the config that's missing the required value. * @throws ServletException * to communicate the error. */ private void handleValueRequiredException(String field, String configType, String configName) throws ServletException { String errorMessage = getActionServlet().getInternal().getMessage("configFieldRequired", field, configType, configName); log.error(errorMessage); throw new UnavailableException(errorMessage); }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
protected List splitAndResolvePaths(String paths) throws ServletException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = this.getClass().getClassLoader(); }/*from w w w .j a v a 2 s.c o m*/ 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 = getActionServlet().getInternal().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; }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
/** * <p>/*from w w w . ja v a 2 s. co m*/ * Checks if the current forwardConfig is using the correct class based on * the class of its configuration ancestor. * </p> * * @param forwardConfig * The forward to check. * @param moduleConfig * The config for the current module. * @return The forward config using the correct class as determined by the * config's ancestor and its own overridden value. * @throws UnavailableException * if an instance of the forward config class cannot be created. * @throws ServletException * on class creation error */ protected ForwardConfig processForwardConfigClass(ForwardConfig forwardConfig, ModuleConfig moduleConfig) throws ServletException { String ancestor = forwardConfig.getExtends(); if (ancestor == null) { // Nothing to do, then return forwardConfig; } // Make sure that this config is of the right class ForwardConfig baseConfig = moduleConfig.findForwardConfig(ancestor); if (baseConfig == null) { throw new UnavailableException("Unable to find " + "forward '" + ancestor + "' to extend."); } // Was our forwards's class overridden already? if (forwardConfig.getClass().equals(ActionForward.class)) { // Ensure that our forward is using the correct class if (!baseConfig.getClass().equals(forwardConfig.getClass())) { // Replace the config with an instance of the correct class ForwardConfig newForwardConfig = null; String baseConfigClassName = baseConfig.getClass().getName(); try { newForwardConfig = (ForwardConfig) RequestUtils.applicationInstance(baseConfigClassName); // copy the values BeanUtils.copyProperties(newForwardConfig, forwardConfig); } catch (Exception e) { handleCreationException(baseConfigClassName, e); } // replace forwardConfig with newForwardConfig moduleConfig.removeForwardConfig(forwardConfig); moduleConfig.addForwardConfig(newForwardConfig); forwardConfig = newForwardConfig; } } return forwardConfig; }
From source file:org.seasar.struts.hotdeploy.impl.ModuleConfigLoaderImpl.java
/** * <p>/*from w w w. ja v a 2 s .c o m*/ * Checks if the current exceptionConfig is using the correct class based on * the class of its configuration ancestor. * </p> * * @param exceptionConfig * The config to check. * @param moduleConfig * The config for the current module. * @return The exception config using the correct class as determined by the * config's ancestor and its own overridden value. * @throws ServletException * if an instance of the exception config class cannot be * created. */ protected ExceptionConfig processExceptionConfigClass(ExceptionConfig exceptionConfig, ModuleConfig moduleConfig) throws ServletException { String ancestor = exceptionConfig.getExtends(); if (ancestor == null) { // Nothing to do, then return exceptionConfig; } // Make sure that this config is of the right class ExceptionConfig baseConfig = moduleConfig.findExceptionConfig(ancestor); if (baseConfig == null) { throw new UnavailableException("Unable to find " + "exception config '" + ancestor + "' to extend."); } // Was our config's class overridden already? if (exceptionConfig.getClass().equals(ExceptionConfig.class)) { // Ensure that our config is using the correct class if (!baseConfig.getClass().equals(exceptionConfig.getClass())) { // Replace the config with an instance of the correct class ExceptionConfig newExceptionConfig = null; String baseConfigClassName = baseConfig.getClass().getName(); try { newExceptionConfig = (ExceptionConfig) RequestUtils.applicationInstance(baseConfigClassName); // copy the values BeanUtils.copyProperties(newExceptionConfig, exceptionConfig); } catch (Exception e) { handleCreationException(baseConfigClassName, e); } // replace exceptionConfig with newExceptionConfig moduleConfig.removeExceptionConfig(exceptionConfig); moduleConfig.addExceptionConfig(newExceptionConfig); exceptionConfig = newExceptionConfig; } } return exceptionConfig; }
From source file:org.vfny.geoserver.config.MultipleActionServlet.java
/** * <p>Initialize this servlet. Most of the processing has been factored into * support methods so that you can override particular functionality at a * fairly granular level.</p>//from w ww .j a v a 2s . c om * * @exception ServletException if we cannot configure ourselves correctly */ public void init() throws ServletException { // Wraps the entire initialization in a try/catch to better handle // unexpected exceptions and errors to provide better feedback // to the developer try { initInternal(); initOther(); initServlet(); getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this); initModuleConfigFactory(); // Initialize modules as needed ModuleConfig moduleConfig = initModuleConfig("", config); initModuleMessageResources(moduleConfig); initModuleDataSources(moduleConfig); initModulePlugIns(moduleConfig); moduleConfig.freeze(); Enumeration names = getServletConfig().getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (!name.startsWith("config/")) { continue; } String prefix = name.substring(6); moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name)); initModuleMessageResources(moduleConfig); initModuleDataSources(moduleConfig); initModulePlugIns(moduleConfig); moduleConfig.freeze(); } this.initModulePrefixes(this.getServletContext()); this.destroyConfigDigester(); } catch (UnavailableException ex) { throw ex; } catch (Throwable t) { // The follow error message is not retrieved from internal message // resources as they may not have been able to have been // initialized log.error("Unable to initialize Struts ActionServlet due to an " + "unexpected exception or error thrown, so marking the " + "servlet as unavailable. Most likely, this is due to an " + "incorrect or missing library dependency.", t); throw new UnavailableException(t.getMessage()); } }