本文整理汇总了Java中org.apache.struts.config.ExceptionConfig类的典型用法代码示例。如果您正苦于以下问题:Java ExceptionConfig类的具体用法?Java ExceptionConfig怎么用?Java ExceptionConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExceptionConfig类属于org.apache.struts.config包,在下文中一共展示了ExceptionConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
protected ForwardConfig handle(ActionContext context, Exception exception,
ExceptionConfig exceptionConfig, ActionConfig actionConfig,
ModuleConfig moduleConfig)
throws Exception {
// Look up the remaining properties needed for this handler
ServletActionContext sacontext = (ServletActionContext) context;
ActionForm actionForm = (ActionForm) sacontext.getActionForm();
HttpServletRequest request = sacontext.getRequest();
HttpServletResponse response = sacontext.getResponse();
// Handle this exception
org.apache.struts.action.ExceptionHandler handler =
(org.apache.struts.action.ExceptionHandler) ClassUtils
.getApplicationInstance(exceptionConfig.getHandler());
return (handler.execute(exception, exceptionConfig,
(ActionMapping) actionConfig, actionForm, request, response));
}
示例2: findException
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* <p>Find and return the <code>ExceptionConfig</code> instance defining
* how <code>Exceptions</code> of the specified type should be handled.
*
* <p>In original Struts usage, this was only available in
* <code>ActionConfig</code>, but there are cases when an exception could
* be thrown before an <code>ActionConfig</code> has been identified,
* where global exception handlers may still be pertinent.</p>
*
* <p>TODO: Look for a way to share this logic with
* <code>ActionConfig</code>, although there are subtle differences, and
* it certainly doesn't seem like it should be done with inheritance.</p>
*
* @param type Exception class for which to find a handler
* @since Struts 1.3.0
*/
public ExceptionConfig findException(Class type) {
// Check through the entire superclass hierarchy as needed
ExceptionConfig config = null;
while (true) {
// Check for a locally defined handler
String name = type.getName();
log.debug("findException: look locally for " + name);
config = findExceptionConfig(name);
if (config != null) {
return (config);
}
// Loop again for our superclass (if any)
type = type.getSuperclass();
if (type == null) {
break;
}
}
return (null); // No handler has been configured
}
示例3: testProcessExceptionConfigClassNoExtends
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Make sure processExceptionConfigClass() returns what it was given if
* the handler passed to it doesn't extend anything.
*/
public void testProcessExceptionConfigClassNoExtends()
throws Exception {
moduleConfig.addExceptionConfig(baseException);
ExceptionConfig result = null;
try {
result =
actionServlet.processExceptionConfigClass(baseException,
moduleConfig, null);
} catch (UnavailableException e) {
fail("An exception should not be thrown when there's nothing to do");
}
assertSame("Result should be the same as the input.", baseException,
result);
}
示例4: testProcessExceptionConfigClassSubConfigCustomClass
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Make sure processExceptionConfigClass() returns the same class instance
* if the base config isn't using a custom class.
*/
public void testProcessExceptionConfigClassSubConfigCustomClass()
throws Exception {
moduleConfig.addExceptionConfig(baseException);
ExceptionConfig customSub = new ExceptionConfig();
customSub.setType("java.lang.IllegalStateException");
customSub.setExtends("java.lang.NullPointerException");
moduleConfig.addExceptionConfig(customSub);
ExceptionConfig result =
actionServlet.processExceptionConfigClass(customSub, moduleConfig,
null);
assertSame("The instance returned should be the param given it.",
customSub, result);
}
示例5: testProcessExceptionConfigClassOverriddenSubFormClass
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Test the case where the subconfig has already specified its own config
* class. If the code still attempts to create a new instance, an error
* will be thrown.
*/
public void testProcessExceptionConfigClassOverriddenSubFormClass()
throws Exception {
moduleConfig.addExceptionConfig(baseException);
ExceptionConfig customSub =
new CustomExceptionConfigArg("java.lang.IllegalStateException");
customSub.setExtends("java.lang.NullPointerException");
moduleConfig.addExceptionConfig(customSub);
try {
actionServlet.processExceptionConfigClass(customSub, moduleConfig,
null);
} catch (Exception e) {
fail("Exception should not be thrown");
}
}
示例6: testProcessActionExtensionWithExceptionConfig
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Test that an ActionConfig's ExceptionConfig can inherit from a
* global ExceptionConfig.
*/
public void testProcessActionExtensionWithExceptionConfig()
throws ServletException {
ExceptionConfig exceptionConfig = new ExceptionConfig();
exceptionConfig.setType("SomeException");
exceptionConfig.setExtends("java.lang.NullPointerException");
baseAction.addExceptionConfig(exceptionConfig);
moduleConfig.addActionConfig(baseAction);
moduleConfig.addExceptionConfig(baseException);
actionServlet.processActionConfigExtension(baseAction, moduleConfig);
exceptionConfig = baseAction.findExceptionConfig("SomeException");
assertEquals("SomeException's inheritance was not processed.",
baseException.getKey(), exceptionConfig.getKey());
}
示例7: execute
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Logs the AuthorizationException before forwarding the user to the explanation page.
*
* @see org.apache.struts.action.ExceptionHandler#execute(
* java.lang.Exception, org.apache.struts.config.ExceptionConfig, org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward execute(Exception exception, ExceptionConfig exceptionConfig, ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
if (LOG.isTraceEnabled()) {
String message = String.format("ENTRY %s", exception.getMessage());
LOG.trace(message);
}
exception.printStackTrace();
request.setAttribute(Globals.EXCEPTION_KEY, exception);
ActionForward forward = mapping.findForward(AUTHORIZATION_EXCEPTION_HANDLER);
if (LOG.isTraceEnabled()) {
LOG.trace(String.format("EXIT %s", exception.getMessage()));
}
return forward;
}
示例8: execute
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* @see org.kuali.rice.kns.web.struts.pojo.StrutsExceptionIncidentHandler#execute(java.lang.Exception, org.apache.struts.config.ExceptionConfig,
* org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward execute(Exception exception, ExceptionConfig exceptionConfig, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
AccessSecurityRestrictionInfo restrictionInfo = (AccessSecurityRestrictionInfo) GlobalVariables.getUserSession().retrieveObject(SecConstants.OPEN_DOCUMENT_SECURITY_ACCESS_DENIED_ERROR_KEY);
if (restrictionInfo != null) {
String accessMessage = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(SecKeyConstants.MESSAGE_OPEN_DOCUMENT_RESTRICTED);
accessMessage = StringUtils.replace(accessMessage, "{0}", GlobalVariables.getUserSession().getPrincipalName());
accessMessage = StringUtils.replace(accessMessage, "{1}", restrictionInfo.getDocumentNumber());
accessMessage = StringUtils.replace(accessMessage, "{2}", restrictionInfo.getPropertyLabel());
accessMessage = StringUtils.replace(accessMessage, "{3}", restrictionInfo.getRetrictedValue());
request.setAttribute(SecConstants.ACCESS_ERROR_STRING_REQUEST_KEY, accessMessage);
GlobalVariables.getUserSession().removeObject(SecConstants.OPEN_DOCUMENT_SECURITY_ACCESS_DENIED_ERROR_KEY);
return mapping.findForward(SecConstants.ACCESS_DENIED_ERROR_FORWARD);
}
return super.execute(exception, exceptionConfig, mapping, form, request, response);
}
示例9: execute
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Custom Handler for HibernateLookupExceptions
* {@inheritDoc}
*/
public ActionForward execute(Exception ex, ExceptionConfig exConfig,
ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ServletException {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
request.setAttribute("error", ex);
TraceBackEvent evt = new TraceBackEvent();
RequestContext requestContext = new RequestContext(request);
User usr = requestContext.getCurrentUser();
evt.setUser(usr);
evt.setRequest(request);
evt.setException(ex);
MessageQueue.publish(evt);
return super.execute(ex, exConfig, mapping, form, request, response);
}
示例10: execute
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Custom Handler for HibernateLookupExceptions
* {@inheritDoc}
*/
public ActionForward execute(Exception ex, ExceptionConfig exConfig,
ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ServletException {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
request.setAttribute("error", ex);
Logger log = Logger.getLogger(PermissionExceptionHandler.class);
log.error("Permission Error", ex);
TraceBackEvent evt = new TraceBackEvent();
RequestContext requestContext = new RequestContext(request);
User usr = requestContext.getCurrentUser();
evt.setUser(usr);
evt.setRequest(request);
evt.setException(ex);
MessageQueue.publish(evt);
return super.execute(ex, exConfig, mapping, form, request, response);
}
示例11: execute
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
@Override
public ActionForward execute(Exception ex, ExceptionConfig exceptionConfig, ActionMapping mapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) throws ServletException {
ActionForward forward = mapping.getInputForward();
if (ex instanceof DomainException) {
super.execute(ex, exceptionConfig, mapping, actionForm, request, response);
DomainException domainException = (DomainException) ex;
String property = domainException.getKey();
ActionMessage error = new ActionMessage(domainException.getKey(), domainException.getArgs());
super.storeException(request, property, error, forward, exceptionConfig.getScope());
}
return forward;
}
示例12: registerExceptionHandling
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
private static void registerExceptionHandling(final ActionMapping actionMapping, Class<?> actionClass) {
for (final ExceptionHandling exception : actionClass.getAnnotationsByType(ExceptionHandling.class)) {
final ExceptionConfig exceptionConfig = new ExceptionConfig();
Class<? extends Exception> exClass = exception.type();
Class<? extends ExceptionHandler> handlerClass = exception.handler();
exceptionConfig.setKey(Strings.emptyToNull(exception.key()));
exceptionConfig.setHandler(handlerClass.getName());
exceptionConfig.setType(exClass.getName());
if (!Strings.isNullOrEmpty(exception.path())) {
exceptionConfig.setPath(exception.path());
}
if (!Strings.isNullOrEmpty(exception.scope())) {
exceptionConfig.setScope(exception.scope());
}
actionMapping.addExceptionConfig(exceptionConfig);
}
}
示例13: execute
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Called when an exception has been thrown during the
* response to a request within a Struts action.
* @param ex Exception
* @param ae Exception configuration
* @param mapping Mapping of String tags to Struts action handlers
* @param formInstance Instance of Struts form class
* @param request Servlet request object
* @param response Servlet response object
* @return Forward
* @throws ServletException If something crashes.
*/
public ActionForward execute(
final Exception ex, final ExceptionConfig ae,
final ActionMapping mapping,
final ActionForm formInstance,
final HttpServletRequest request,
final HttpServletResponse response
) throws ServletException {
// Attach exception to request
request.setAttribute(Attribute.EXCEPTION, ex);
// Log exception
LOGGER.error(ex, ex);
return super.execute(ex, ae, mapping, formInstance, request, response);
}
示例14: removeExceptionConfig
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* Remove the specified exception configuration instance.
*
* @param config ActionConfig instance to be removed
*
* @exception IllegalStateException if this module configuration
* has been frozen
*/
public void removeExceptionConfig(ExceptionConfig config) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
exceptions.remove(config.getType());
}
示例15: execute
import org.apache.struts.config.ExceptionConfig; //导入依赖的package包/类
/**
* <p>Handle the <code>Exception</code>.
* Return the <code>ActionForward</code> instance (if any) returned by
* the called <code>ExceptionHandler</code>.
*
* @param ex The exception to handle
* @param ae The ExceptionConfig corresponding to the exception
* @param mapping The ActionMapping we are processing
* @param formInstance The ActionForm we are processing
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception ServletException if a servlet exception occurs
*
* @since Struts 1.1
*/
public ActionForward execute(
Exception ex,
ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException {
ActionForward forward = null;
ActionMessage error = null;
String property = null;
// Build the forward from the exception mapping if it exists
// or from the form input
if (ae.getPath() != null) {
forward = new ActionForward(ae.getPath());
} else {
forward = mapping.getInputForward();
}
// Figure out the error
if (ex instanceof ModuleException) {
error = ((ModuleException) ex).getActionMessage();
property = ((ModuleException) ex).getProperty();
} else {
error = new ActionMessage(ae.getKey(), ex.getMessage());
property = error.getKey();
}
this.logException(ex);
// Store the exception
request.setAttribute(Globals.EXCEPTION_KEY, ex);
this.storeException(request, property, error, forward, ae.getScope());
return forward;
}