List of usage examples for javax.servlet UnavailableException UnavailableException
public UnavailableException(String msg)
From source file:org.apache.struts.action.ActionServlet.java
/** * <p>Handle errors related to creating an instance of the specified * class.</p>//w w w . ja v a2s .com * * @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 = internal.getMessage("configExtends.creation", className); log.error(errorMessage, e); throw new UnavailableException(errorMessage); }
From source file:org.apache.struts.action.ActionServlet.java
/** * <p>General handling for exceptions caught while inheriting config * information.</p>//from ww w . j a v a 2 s . c o m * * @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 = internal.getMessage("configExtends", configType, configName); log.error(errorMessage, e); throw new UnavailableException(errorMessage); }
From source file:org.apache.struts.action.ActionServlet.java
/** * <p>Handle errors caused by required fields that were not * specified.</p>//from w ww . ja v a2 s.c om * * @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 = internal.getMessage("configFieldRequired", field, configType, configName); log.error(errorMessage); throw new UnavailableException(errorMessage); }
From source file:org.apache.struts.action.ActionServlet.java
/** * <p>Initialize the plug ins for the specified module.</p> * * @param config ModuleConfig information for this module * @throws ServletException if initialization cannot be performed * @since Struts 1.1/*from w ww .j av a 2 s. c om*/ */ protected void initModulePlugIns(ModuleConfig config) throws ServletException { if (log.isDebugEnabled()) { log.debug("Initializing module path '" + config.getPrefix() + "' plug ins"); } PlugInConfig[] plugInConfigs = config.findPlugInConfigs(); PlugIn[] plugIns = new PlugIn[plugInConfigs.length]; getServletContext().setAttribute(Globals.PLUG_INS_KEY + config.getPrefix(), plugIns); for (int i = 0; i < plugIns.length; i++) { try { plugIns[i] = (PlugIn) RequestUtils.applicationInstance(plugInConfigs[i].getClassName()); BeanUtils.populate(plugIns[i], plugInConfigs[i].getProperties()); // Pass the current plugIn config object to the PlugIn. // The property is set only if the plugin declares it. // This plugin config object is needed by Tiles try { PropertyUtils.setProperty(plugIns[i], "currentPlugInConfigObject", plugInConfigs[i]); } catch (Exception e) { ; // FIXME Whenever we fail silently, we must document a valid // reason for doing so. Why should we fail silently if a // property can't be set on the plugin? /** * Between version 1.138-1.140 cedric made these changes. * The exceptions are caught to deal with containers * applying strict security. This was in response to bug * #15736 * * Recommend that we make the currentPlugInConfigObject part * of the PlugIn Interface if we can, Rob */ } plugIns[i].init(this, config); } catch (ServletException e) { throw e; } catch (Exception e) { String errMsg = internal.getMessage("plugIn.init", plugInConfigs[i].getClassName()); log(errMsg, e); throw new UnavailableException(errMsg); } } }
From source file:org.apache.struts.action.ActionServlet.java
/** * <p>Checks if the current beanConfig is using the correct class based on * the class of its ancestor form bean config.</p> * * @param beanConfig The form bean to check. * @param moduleConfig The config for the current module. * @return The form bean config using the correct class as determined by * the config's ancestor and its own overridden value. * @throws UnavailableException if an instance of the form bean config * class cannot be created. * @throws ServletException on class creation error *//*from w w w . j a v a 2 s. co m*/ protected FormBeanConfig processFormBeanConfigClass(FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws ServletException { String ancestor = beanConfig.getExtends(); if (ancestor == null) { // Nothing to do, then return beanConfig; } // Make sure that this bean is of the right class FormBeanConfig baseConfig = moduleConfig.findFormBeanConfig(ancestor); if (baseConfig == null) { throw new UnavailableException("Unable to find " + "form bean '" + ancestor + "' to extend."); } // Was our bean's class overridden already? if (beanConfig.getClass().equals(FormBeanConfig.class)) { // Ensure that our bean is using the correct class if (!baseConfig.getClass().equals(beanConfig.getClass())) { // Replace the bean with an instance of the correct class FormBeanConfig newBeanConfig = null; String baseConfigClassName = baseConfig.getClass().getName(); try { newBeanConfig = (FormBeanConfig) RequestUtils.applicationInstance(baseConfigClassName); // copy the values BeanUtils.copyProperties(newBeanConfig, beanConfig); FormPropertyConfig[] fpc = beanConfig.findFormPropertyConfigs(); for (int i = 0; i < fpc.length; i++) { newBeanConfig.addFormPropertyConfig(fpc[i]); } } catch (Exception e) { handleCreationException(baseConfigClassName, e); } // replace beanConfig with newBeanConfig moduleConfig.removeFormBeanConfig(beanConfig); moduleConfig.addFormBeanConfig(newBeanConfig); beanConfig = newBeanConfig; } } return beanConfig; }
From source file:org.apache.struts.action.ActionServlet.java
/** * <p>Checks if the current forwardConfig is using the correct class based * on the class of its configuration ancestor. If actionConfig is * provided, then this method will process the forwardConfig as part * of that actionConfig. If actionConfig is null, the forwardConfig * will be processed as a global forward.</p> * * @param forwardConfig The forward to check. * @param moduleConfig The config for the current module. * @param actionConfig If applicable, the config for the current action. * @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 *//*w w w. j a v a 2s. c o m*/ protected ForwardConfig processForwardConfigClass(ForwardConfig forwardConfig, ModuleConfig moduleConfig, ActionConfig actionConfig) 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 = null; if (actionConfig != null) { // Look for this in the actionConfig baseConfig = actionConfig.findForwardConfig(ancestor); } if (baseConfig == null) { // Either this is a forwardConfig that inherits a global config, // or actionConfig is null 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 if (actionConfig != null) { actionConfig.removeForwardConfig(forwardConfig); actionConfig.addForwardConfig(newForwardConfig); } else { // this is a global forward moduleConfig.removeForwardConfig(forwardConfig); moduleConfig.addForwardConfig(newForwardConfig); } forwardConfig = newForwardConfig; } } return forwardConfig; }
From source file:org.apache.struts.action.ActionServlet.java
/** * <p>Checks if the current exceptionConfig is using the correct class * based on the class of its configuration ancestor. If actionConfig is * provided, then this method will process the exceptionConfig as part * of that actionConfig. If actionConfig is null, the exceptionConfig * will be processed as a global forward.</p> * * @param exceptionConfig The config to check. * @param moduleConfig The config for the current module. * @param actionConfig If applicable, the config for the current action. * @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. *//*from w w w . j a va2 s . c o m*/ protected ExceptionConfig processExceptionConfigClass(ExceptionConfig exceptionConfig, ModuleConfig moduleConfig, ActionConfig actionConfig) 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 = null; if (actionConfig != null) { baseConfig = actionConfig.findExceptionConfig(ancestor); } if (baseConfig == null) { // This means either there's no actionConfig anyway, or the // ancestor is not defined within the action. 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 if (actionConfig != null) { actionConfig.removeExceptionConfig(exceptionConfig); actionConfig.addExceptionConfig(newExceptionConfig); } else { moduleConfig.removeExceptionConfig(exceptionConfig); moduleConfig.addExceptionConfig(newExceptionConfig); } exceptionConfig = newExceptionConfig; } } return exceptionConfig; }
From source file:org.apache.struts.action.ActionServlet.java
/** * <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. *///from w w w .j ava 2s. c o m 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; }
From source file:org.apache.struts.action.ActionServlet.java
/** * <p>Initialize our internal MessageResources bundle.</p> * * @throws ServletException if we cannot initialize these resources * @throws UnavailableException if we cannot load resources *///from w w w . j a v a2s . co m protected void initInternal() throws ServletException { try { internal = MessageResources.getMessageResources(internalName); } catch (MissingResourceException e) { log.error("Cannot load internal resources from '" + internalName + "'", e); throw new UnavailableException("Cannot load internal resources from '" + internalName + "'"); } }
From source file:org.apache.struts.action.ActionServlet.java
/** * <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 */// ww w . ja va 2s .c o m 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; }