public static Map<String, String> createParameterMap(String[] params) { Map<String, String> map = new HashMap<>(); int subtract = params.length % 2; if (subtract != 0) { throw new ConfigurationException( "'params' is a string array " + "and they must be in a key value pair configuration. It looks like you" + " have specified an odd number of parameters and there should only be an even number." + " (e.g. params = {\"key\", \"value\"})"); } for (int i = 0; i < params.length; i = i + 2) { String key = params[i]; String value = params[i + 1]; map.put(key, value); } return map; } }
throw new ConfigurationException("Unable to find interceptor class referenced by ref-name " + refName, location); } else { if (referencedConfig instanceof InterceptorConfig) { if (LOG.isWarnEnabled()) { LOG.warn("Unable to load config class #0 at #1 probably due to a missing jar, which might be fine if you never plan to use the #2 interceptor", config.getClassName(), ex.getLocation().toString(), config.getName());
private void loadDocuments(String configFileName) { try { loadedFileUrls.clear(); documents = loadConfigurationFiles(configFileName, null); } catch (ConfigurationException e) { throw e; } catch (Exception e) { throw new ConfigurationException("Error loading configuration file " + configFileName, e); } }
private Set<Class<?>> parseExcludedClasses(String commaDelimitedClasses) { Set<String> classNames = TextParseUtil.commaDelimitedStringToSet(commaDelimitedClasses); Set<Class<?>> classes = new HashSet<Class<?>>(); for (String className : classNames) { try { classes.add(Class.forName(className)); } catch (ClassNotFoundException e) { throw new ConfigurationException("Cannot load excluded class: " + className, e); } } return classes; }
public StrutsWildcardServletApplicationContext(ServletContext context) { super(context); Set<URL> urls = new HashSet<>(); for (Object path : context.getResourcePaths("/")) { try { String realPath = context.getRealPath(String.valueOf(path)); if (realPath != null) { URL url = new File(realPath).toURI().toURL(); urls.add(url); } } catch (MalformedURLException e) { throw new ConfigurationException(e); } } try { Enumeration<URL> resources = getClass().getClassLoader().getResources("/"); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); urls.add(resource); } } catch (IOException e) { throw new ConfigurationException(e); } finder = new ResourceFinder(urls.toArray(new URL[urls.size()])); }
/** * Depending how Tiles definition was defined, request can an instance of JspRequest (for JSPs) * or a ServletRequest (FreeMarker) */ protected ActionContext readActionContext(Request request) { LOG.debug("Obtaining HttpServletRequest based on [{}]", request.getClass().getName()); HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest(); ActionContext ctx = ServletActionContext.getActionContext(httpRequest); if (ctx == null) { LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName()); throw new ConfigurationException("There is no ActionContext for current request!"); } return ctx; }
String determineType(String location, PackageConfig packageConfig, Map<String, ResultTypeConfig> resultsByExtension) { int indexOfDot = location.lastIndexOf("."); if (indexOfDot > 0) { String extension = location.substring(indexOfDot + 1); ResultTypeConfig resultTypeConfig = resultsByExtension.get(extension); if (resultTypeConfig != null) { return resultTypeConfig.getName(); } else throw new ConfigurationException("Unable to find a result type for extension [" + extension + "] " + "in location attribute [" + location + "]."); } else { return packageConfig.getFullDefaultResultType(); } } }
@Inject public void setContainer(Container container) { this.container = container; try { build(); } catch (Exception e) { throw new ConfigurationException(e); } }
public void parseValidatorDefinitions(Map<String, String> validators, InputStream is, String resourceName) { InputSource in = new InputSource(is); in.setSystemId(resourceName); Map<String, String> dtdMappings = new HashMap<String, String>(); dtdMappings.put("-//Apache Struts//XWork Validator Config 1.0//EN", "xwork-validator-config-1.0.dtd"); dtdMappings.put("-//Apache Struts//XWork Validator Definition 1.0//EN", "xwork-validator-definition-1.0.dtd"); Document doc = DomHelper.parse(in, dtdMappings); if (doc != null) { NodeList nodes = doc.getElementsByTagName("validator"); for (int i = 0; i < nodes.getLength(); i++) { Element validatorElement = (Element) nodes.item(i); String name = validatorElement.getAttribute("name"); String className = validatorElement.getAttribute("class"); try { // catch any problems here objectFactory.buildValidator(className, new HashMap<String, Object>(), ActionContext.getContext().getContextMap()); validators.put(name, className); } catch (Exception e) { throw new ConfigurationException("Unable to load validator class " + className, e, validatorElement); } } } }
/** * Builds a list of actions from an @Actions annotation, and check that they are not all empty * @param actionsAnnotation Actions annotation * @return a list of Actions */ protected List<Action> checkActionsAnnotation(Actions actionsAnnotation) { Action[] actionArray = actionsAnnotation.value(); boolean valuelessSeen = false; List<Action> actions = new ArrayList<>(); for (Action ann : actionArray) { if (ann.value().equals(Action.DEFAULT_VALUE) && !valuelessSeen) { valuelessSeen = true; } else if (ann.value().equals(Action.DEFAULT_VALUE)) { throw new ConfigurationException("You may only add a single Action annotation that has no value parameter."); } actions.add(ann); } return actions; }
@Override public Locale resolveLocale(Request request) { HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest(); ActionContext ctx = ServletActionContext.getActionContext(httpRequest); if (ctx == null) { LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName()); throw new ConfigurationException("There is no ActionContext for current request!"); } LocaleProviderFactory localeProviderFactory = ctx.getInstance(LocaleProviderFactory.class); return localeProviderFactory.createLocaleProvider().getLocale(); }
/** * {@inheritDoc} */ public String determineResultPath(Class<?> actionClass) { String localResultPath = resultPath; ResultPath resultPathAnnotation = AnnotationUtils.findAnnotation(actionClass, ResultPath.class); if (resultPathAnnotation != null) { if (resultPathAnnotation.value().equals("") && resultPathAnnotation.property().equals("")) { throw new ConfigurationException("The ResultPath annotation must have either" + " a value or property specified."); } String property = resultPathAnnotation.property(); if (property.equals("")) { localResultPath = resultPathAnnotation.value(); } else { try { ResourceBundle strutsBundle = ResourceBundle.getBundle("struts"); localResultPath = strutsBundle.getString(property); } catch (Exception e) { throw new ConfigurationException("The action class [" + actionClass + "] defines" + " a @ResultPath annotation and a property definition however the" + " struts.properties could not be found in the classpath using ResourceBundle" + " OR the bundle exists but the property [" + property + "] is not defined" + " in the file.", e); } } } return localResultPath; }
/** * Save the result to be used later. * @param actionConfig current ActionConfig * @param methodResult the result of the action. * @return the result code to process. * * @throws ConfigurationException If it is an incorrect result. */ @Override protected String saveResult(ActionConfig actionConfig, Object methodResult) { if (methodResult instanceof Result) { explicitResult = (Result) methodResult; // Wire the result automatically container.inject(explicitResult); } else if (methodResult instanceof HttpHeaders) { httpHeaders = (HttpHeaders) methodResult; resultCode = httpHeaders.getResultCode(); } else if (methodResult instanceof String) { resultCode = (String) methodResult; } else if (methodResult != null) { throw new ConfigurationException("The result type " + methodResult.getClass() + " is not allowed. Use the type String, HttpHeaders or Result."); } return resultCode; }
builder.append(packageName); throw new ConfigurationException(builder.toString());
throw new ConfigurationException(message, cause);
throw new ConfigurationException("At least a list of action packages or action package locators " + "must be given using one of the properties [struts.convention.action.packages] or " + "[struts.convention.package.locators]");
throw new ConfigurationException("No result type specified for result named '" + resultName + "', perhaps the parent package does not specify the result type?", resultElement); throw new ConfigurationException("There is no result type defined for type '" + resultType + "' mapped with name '" + resultName + "'." + " Did you mean '" + guessResultType(resultType) + "'?", resultElement); throw new ConfigurationException("Result type '" + resultType + "' is invalid");
factory.lookupRegisteredValidatorType(validatorType); } catch (IllegalArgumentException ex) { throw new ConfigurationException("Invalid validation type: " + validatorType, validatorElement);
throw new ConfigurationException("The 'externalReferenceResolver' attribute has been removed. Please use " + "a custom ObjectFactory or Interceptor.", packageElement); throw new ConfigurationException("Parent package is not defined: " + parentPackageName);
throw new ConfigurationException("Unable to parse validators", e);