use of org.apache.struts2.StrutsException in project struts by apache.
the class Dispatcher method init.
/**
* Load configurations, including both XML and zero-configuration strategies,
* and update optional settings, including whether to reload configurations and resource files.
*/
public void init() {
if (configurationManager == null) {
configurationManager = createConfigurationManager(Container.DEFAULT_NAME);
}
try {
init_FileManager();
// [1]
init_DefaultProperties();
// [2]
init_TraditionalXmlConfigurations();
init_JavaConfigurations();
// [3]
init_LegacyStrutsProperties();
// [5]
init_CustomConfigurationProviders();
// [6]
init_FilterInitParameters();
// [7]
init_AliasStandardObjects();
Container container = init_PreloadConfiguration();
container.inject(this);
init_CheckWebLogicWorkaround(container);
if (!dispatcherListeners.isEmpty()) {
for (DispatcherListener l : dispatcherListeners) {
l.dispatcherInitialized(this);
}
}
errorHandler.init(servletContext);
if (servletContext.getAttribute(StrutsStatics.SERVLET_DISPATCHER) == null) {
servletContext.setAttribute(StrutsStatics.SERVLET_DISPATCHER, this);
}
} catch (Exception ex) {
LOG.error("Dispatcher initialization failed", ex);
throw new StrutsException(ex);
}
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class DefaultTheme method renderTag.
public void renderTag(String tagName, TemplateRenderingContext context) {
if (tagName.endsWith(".java")) {
tagName = tagName.substring(0, tagName.length() - ".java".length());
}
List<TagHandler> handlers = new ArrayList<TagHandler>();
List<TagHandlerFactory> factories = handlerFactories.get(tagName);
if (factories == null) {
throw new StrutsException("Unable to find handlers for tag " + tagName);
}
TagHandler prev = null;
for (int x = factories.size() - 1; x >= 0; x--) {
prev = factories.get(x).create(prev);
prev.setup(context);
handlers.add(0, prev);
}
// TagSerializer ser = (TagSerializer) handlers.get(handlers.size() - 1);
TagGenerator gen = (TagGenerator) handlers.get(0);
try {
LOG.trace("Rendering tag [{}]", tagName);
gen.generate();
} catch (IOException ex) {
throw new StrutsException("Unable to write tag: " + tagName, ex);
}
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class JavaTemplateEngine method renderTemplate.
public void renderTemplate(TemplateRenderingContext templateContext) throws Exception {
Template t = templateContext.getTemplate();
Theme theme = themes.get(t.getTheme());
if (theme == null) {
// Theme not supported, so do what struts would have done if we were not here.
LOG.debug("Theme not found [{}] trying default template engine using template type [{}]", t.getTheme(), defaultTemplateType);
final TemplateEngine engine = templateEngineManager.getTemplateEngine(templateContext.getTemplate(), defaultTemplateType);
if (engine == null) {
// May be the default template has changed?
throw new ConfigurationException("Unable to find a TemplateEngine for template type '" + defaultTemplateType + "' whilst trying to render template " + templateContext.getTemplate());
} else {
try {
// Retry render
engine.renderTemplate(templateContext);
} catch (Exception e) {
// Give up and throw a new StrutsException(e);
throw new StrutsException("Cannot render tag [" + t.getName() + "] because theme [" + t.getTheme() + "] was not found.", e);
}
}
} else {
// Render our template
theme.renderTag(t.getName(), templateContext);
}
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class XmlConfigurationProvider method loadConfigurationFiles.
private List<Document> loadConfigurationFiles(String fileName, Element includeElement) {
List<Document> docs = new ArrayList<>();
List<Document> finalDocs = new ArrayList<>();
if (!includedFileNames.contains(fileName)) {
LOG.debug("Loading action configurations from: {}", fileName);
includedFileNames.add(fileName);
Iterator<URL> urls = null;
InputStream is = null;
IOException ioException = null;
try {
urls = getConfigurationUrls(fileName);
} catch (IOException ex) {
ioException = ex;
}
if (urls == null || !urls.hasNext()) {
LOG.debug("Ignoring file that does not exist: " + fileName, ioException);
return docs;
}
URL url = null;
while (urls.hasNext()) {
try {
url = urls.next();
is = fileManager.loadFile(url);
InputSource in = new InputSource(is);
in.setSystemId(url.toString());
Document helperDoc = DomHelper.parse(in, dtdMappings);
if (helperDoc != null) {
docs.add(helperDoc);
}
loadedFileUrls.add(url.toString());
} catch (StrutsException e) {
if (includeElement != null) {
throw new ConfigurationException("Unable to load " + url, e, includeElement);
} else {
throw new ConfigurationException("Unable to load " + url, e);
}
} catch (Exception e) {
throw new ConfigurationException("Caught exception while loading file " + fileName, e, includeElement);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
LOG.error("Unable to close input stream", e);
}
}
}
}
// sort the documents, according to the "order" attribute
Collections.sort(docs, new Comparator<Document>() {
public int compare(Document doc1, Document doc2) {
return XmlHelper.getLoadOrder(doc1).compareTo(XmlHelper.getLoadOrder(doc2));
}
});
for (Document doc : docs) {
Element rootElement = doc.getDocumentElement();
NodeList children = rootElement.getChildNodes();
int childSize = children.getLength();
for (int i = 0; i < childSize; i++) {
Node childNode = children.item(i);
if (childNode instanceof Element) {
Element child = (Element) childNode;
final String nodeName = child.getNodeName();
if ("include".equals(nodeName)) {
String includeFileName = child.getAttribute("file");
if (includeFileName.indexOf('*') != -1) {
// handleWildCardIncludes(includeFileName, docs, child);
ClassPathFinder wildcardFinder = new ClassPathFinder();
wildcardFinder.setPattern(includeFileName);
Vector<String> wildcardMatches = wildcardFinder.findMatches();
for (String match : wildcardMatches) {
finalDocs.addAll(loadConfigurationFiles(match, child));
}
} else {
finalDocs.addAll(loadConfigurationFiles(includeFileName, child));
}
}
}
}
finalDocs.add(doc);
}
LOG.debug("Loaded action configuration from: {}", fileName);
}
return finalDocs;
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class CompoundRootAccessor method setProperty.
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
CompoundRoot root = (CompoundRoot) target;
OgnlContext ognlContext = (OgnlContext) context;
for (Object o : root) {
if (o == null) {
continue;
}
try {
if (OgnlRuntime.hasSetProperty(ognlContext, o, name)) {
OgnlRuntime.setProperty(ognlContext, o, name, value);
return;
} else if (o instanceof Map) {
@SuppressWarnings("unchecked") Map<Object, Object> map = (Map<Object, Object>) o;
try {
map.put(name, value);
return;
} catch (UnsupportedOperationException e) {
// This is an unmodifiable Map, so move on to the next element in the stack
}
}
// } catch (OgnlException e) {
// if (e.getReason() != null) {
// final String msg = "Caught an Ognl exception while setting property " + name;
// log.error(msg, e);
// throw new RuntimeException(msg, e.getReason());
// }
} catch (IntrospectionException e) {
// this is OK if this happens, we'll just keep trying the next
}
}
boolean reportError = toBoolean((Boolean) context.get(ValueStack.REPORT_ERRORS_ON_NO_PROP));
if (reportError || devMode) {
final String msg = format("No object in the CompoundRoot has a publicly accessible property named '%s' " + "(no setter could be found).", name);
if (reportError) {
throw new StrutsException(msg);
} else {
LOG.warn(msg);
}
}
}
Aggregations