use of org.apache.struts2.StrutsException in project struts by apache.
the class AnnotationWorkflowInterceptor method beforeResult.
/**
* Invokes any @BeforeResult annotated methods
*
* @see com.opensymphony.xwork2.interceptor.PreResultListener#beforeResult(com.opensymphony.xwork2.ActionInvocation,String)
*/
public void beforeResult(ActionInvocation invocation, String resultCode) {
Object action = invocation.getAction();
List<Method> methods = new ArrayList<Method>(MethodUtils.getMethodsListWithAnnotation(action.getClass(), BeforeResult.class, true, true));
if (methods.size() > 0) {
// methods are only sorted by priority
Collections.sort(methods, new Comparator<Method>() {
public int compare(Method method1, Method method2) {
return comparePriorities(MethodUtils.getAnnotation(method1, BeforeResult.class, true, true).priority(), MethodUtils.getAnnotation(method2, BeforeResult.class, true, true).priority());
}
});
for (Method m : methods) {
try {
MethodUtils.invokeMethod(action, true, m.getName());
} catch (Exception e) {
throw new StrutsException(e);
}
}
}
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class DomHelper method parse.
/**
* Creates a W3C Document that remembers the location of each element in
* the source file. The location of element nodes can then be retrieved
* using the {@link #getLocationObject(Element)} method.
*
* @param inputSource the inputSource to read the document from
* @param dtdMappings a map of DTD names and public ids
*
* @return the W3C Document
*/
public static Document parse(InputSource inputSource, Map<String, String> dtdMappings) {
SAXParserFactory factory = null;
String parserProp = System.getProperty("xwork.saxParserFactory");
if (parserProp != null) {
try {
ObjectFactory objectFactory = ActionContext.getContext().getContainer().getInstance(ObjectFactory.class);
Class clazz = objectFactory.getClassInstance(parserProp);
factory = (SAXParserFactory) clazz.newInstance();
} catch (Exception e) {
LOG.error("Unable to load saxParserFactory set by system property 'xwork.saxParserFactory': {}", parserProp, e);
}
}
if (factory == null) {
factory = SAXParserFactory.newInstance();
}
factory.setValidating((dtdMappings != null));
factory.setNamespaceAware(true);
SAXParser parser;
try {
parser = factory.newSAXParser();
} catch (Exception ex) {
throw new StrutsException("Unable to create SAX parser", ex);
}
DOMBuilder builder = new DOMBuilder();
// Enhance the sax stream with location information
ContentHandler locationHandler = new LocationAttributes.Pipe(builder);
try {
parser.parse(inputSource, new StartHandler(locationHandler, dtdMappings));
} catch (Exception ex) {
throw new StrutsException(ex);
}
return builder.getDocument();
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class DefaultActionInvocation method createResult.
public Result createResult() throws Exception {
LOG.trace("Creating result related to resultCode [{}]", resultCode);
if (explicitResult != null) {
Result ret = explicitResult;
explicitResult = null;
return ret;
}
ActionConfig config = proxy.getConfig();
Map<String, ResultConfig> results = config.getResults();
ResultConfig resultConfig = null;
try {
resultConfig = results.get(resultCode);
} catch (NullPointerException e) {
LOG.debug("Got NPE trying to read result configuration for resultCode [{}]", resultCode);
}
if (resultConfig == null) {
// If no result is found for the given resultCode, try to get a wildcard '*' match.
resultConfig = results.get("*");
}
if (resultConfig != null) {
try {
return objectFactory.buildResult(resultConfig, invocationContext.getContextMap());
} catch (Exception e) {
LOG.error("There was an exception while instantiating the result of type {}", resultConfig.getClassName(), e);
throw new StrutsException(e, resultConfig);
}
} else if (resultCode != null && !Action.NONE.equals(resultCode) && unknownHandlerManager.hasUnknownHandlers()) {
return unknownHandlerManager.handleUnknownResult(invocationContext, proxy.getActionName(), proxy.getConfig(), resultCode);
}
return null;
}
use of org.apache.struts2.StrutsException in project entando-core by entando.
the class ApsActionParamComponent method end.
@Override
public boolean end(Writer writer, String body) {
String actionParam = ApsRequestParamsUtil.createApsActionParam(this.getAction(), this.getParams());
if (this.getVar() != null) {
this.getStack().getContext().put(this.getVar(), actionParam);
// add to the request and page scopes as well
_req.setAttribute(this.getVar(), actionParam);
} else {
try {
writer.write(actionParam);
} catch (IOException e) {
throw new StrutsException("IOError: " + e.getMessage(), e);
}
}
return true;
}
use of org.apache.struts2.StrutsException in project struts-examples by apache.
the class TilesUnknownHandler method handleUnknownResult.
public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig actionConfig, String resultCode) throws StrutsException {
ServletContext servletContext = ServletActionContext.getServletContext();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ServletApplicationContext context = new ServletApplicationContext(servletContext);
TilesContainer container = TilesAccess.getContainer(context);
String namespace = ServletActionContext.getActionMapping().getNamespace();
Set<String> definitions = buildDefinitionNames(namespace, actionName, resultCode);
for (String definition : definitions) {
LOG.debug("Looking for tiles definition: {}", definition);
if (container.isValidDefinition(definition, new ServletRequest(context, request, response))) {
return new TilesResult(definition);
}
}
LOG.warn("Couldn't find tiles definition for namespace {}, action name {} and result code {}", namespace, actionName, resultCode);
return null;
}
Aggregations