husted 2002/08/19 15:36:15 Modified: contrib/scaffold/src/java/org/apache/struts/scaffold Resources.properties ProcessDispatchAction.java BaseAction.java Log: + Resources.properties: Conform with latest Token class. + ProcessDispatchAction: Improve exception handling. + BaseAction: Update to better handle exceptions with null message. Revision Changes Path 1.2 +32 -2 jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/Resources.properties Index: Resources.properties =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/Resources.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Resources.properties 14 Aug 2002 18:30:08 -0000 1.1 +++ Resources.properties 19 Aug 2002 22:36:15 -0000 1.2 @@ -5,10 +5,40 @@ # --!! YOU MUST COPY THESE TO YOUR APPLICATION'S FILE !!-- # -- See also constants in lang/Tokens -- # +# +errors.header= +errors.footer= +error.cancel=Operation cancelled. +error.detail={0} +error.general=The process did not complete. Details should follow. +error.token=Request could not be completed. Operation is not in sequence. +error.dispatch=Process could not be dispatched. Path: [{0}]. Parameter: [{1}]. +error.dispatch.return=The return value of the process is not correct. Path: [{0}]. Parameter: [{1}]. +# -- validator -- +errors.required={0} is required. +errors.minlength={0} can not be less than {1} characters. +errors.maxlength={0} can not be greater than {1} characters. +errors.invalid={0} is invalid. +errors.byte={0} must be an byte. +errors.short={0} must be an short. +errors.integer={0} must be an integer. +errors.long={0} must be an long. +errors.float={0} must be an float. +errors.double={0} must be an double. +errors.date={0} is not a date. +errors.range={0} is not in the range {1} through {2}. +errors.creditcard={0} is not a valid credit card number. +errors.email={0} is an invalid e-mail address. # -- data -- data.access.denied=Access denied. data.access.error=Unable to access database. data.access.empty=Requested records were not found. data.record.inserted=Record {0} inserted. data.record.updated=Record {0} updated. -data.record.deleted=Record {0} deleted. \ No newline at end of file +data.record.deleted=Record {0} deleted. +data.record.recycled=Record {0} marked for deletion. +data.record.restored=Record {0} restored. +data.transfer.error=Unable to transfer data. +# -- process -- +process.complete=Process complete. +process.missing.parameter=A required parameter is missing. 1.3 +46 -2 jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/ProcessDispatchAction.java Index: ProcessDispatchAction.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/ProcessDispatchAction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ProcessDispatchAction.java 16 Aug 2002 22:29:24 -0000 1.2 +++ ProcessDispatchAction.java 19 Aug 2002 22:36:15 -0000 1.3 @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collection; @@ -35,6 +36,7 @@ import org.apache.commons.scaffold.lang.Tokens; import org.apache.commons.scaffold.util.ProcessBean; import org.apache.commons.scaffold.util.ProcessResult; +import org.apache.commons.scaffold.util.ProcessResultBase; import org.apache.commons.scaffold.util.ResultList; import org.apache.commons.scaffold.util.ResultListBase; @@ -58,6 +60,19 @@ private static final Class types[] = { Object.class }; + /** + * Error handler. + * Posts a message template and two parameters in a ProcessResult. + */ + public void processError(ProcessResult result, String template, + ActionMapping mapping) { + result = new ProcessResultBase(this); + result.addMessage(template); + result.addMessage(mapping.getPath()); + result.addMessage(mapping.getParameter()); + } + + // --------------------------------------------------------- Public Methods /** @@ -128,7 +143,36 @@ Method method = dataBean.getClass().getMethod(tokens[1],types); Object args[] = { properties }; - ProcessResult result = (ProcessResult) method.invoke(dataBean,args); + + ProcessResult result = null; + + try { + + result = (ProcessResult) method.invoke(dataBean,args); + + } + + catch (ClassCastException e) { + + processError(result,Tokens.ERROR_DISPATCH_RETURN,mapping); + } + + catch (IllegalAccessException e) { + + processError(result,Tokens.ERROR_DISPATCH_RETURN,mapping); + } + + catch (InvocationTargetException e) { + + // Rethrow the target exception if possible so that the + // exception handling machinery can deal with it + Throwable t = e.getTargetException(); + if (t instanceof Exception) { + throw ((Exception) t); + } else { + processError(result,Tokens.ERROR_DISPATCH,mapping); + } + } // Execute business logic, using map checkOutcome(mapping,request,result); 1.2 +33 -6 jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/BaseAction.java Index: BaseAction.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/BaseAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BaseAction.java 14 Aug 2002 18:30:09 -0000 1.1 +++ BaseAction.java 19 Aug 2002 22:36:15 -0000 1.2 @@ -29,9 +29,10 @@ import org.apache.struts.util.MessageResources; -import org.apache.commons.scaffold.lang.ChainedException; +import org.apache.commons.scaffold.lang.BaseException; import org.apache.commons.scaffold.lang.Log; import org.apache.commons.scaffold.lang.Tokens; +import org.apache.commons.scaffold.text.ConvertUtils; /** @@ -668,9 +669,22 @@ /** + * Token to print before short description + * of an exception. + */ + private static final String ERROR = " ERROR: "; + + /** + * Token to print between short and long description + * of an exception. + */ + private static final String DETAILS = " DETAILS: "; + + + /** * Process the exception handling for this Action. * - * If Exception is subclass of ChainedException, will + * If Exception is subclass of BaseException, will * report on everything in chain. * * Default behaviour should suffice for most circumstances. @@ -684,6 +698,7 @@ * @param response The response we are creating * @param errors Our ActionErrors collection * @param exception The exception we are catching + * @todo Use a StringBufferOUTPUTStream to capture trace for error queue */ protected void catchException( ActionMapping mapping, @@ -691,6 +706,7 @@ HttpServletRequest request, HttpServletResponse response) { + // Retrieve, log and print to error console Exception exception = getException(request); servlet.log(Log.ACTION_EXCEPTION, exception); @@ -705,12 +721,22 @@ // If chained, descend down chain // appending messages to StringBuffer StringBuffer sb = new StringBuffer(); - if (exception instanceof ChainedException) { - ChainedException e = (ChainedException) exception; + if (exception instanceof BaseException) { + BaseException e = (BaseException) exception; e.getMessage(sb); } else { - sb.append(exception.getMessage()); + sb.append(ConvertUtils.LINE_FEED); + sb.append(ERROR); + sb.append(exception.toString()); + String message = exception.getMessage(); + if (null!=message) { + sb.append(ConvertUtils.LINE_FEED); + sb.append(DETAILS); + sb.append(message); + sb.append(ConvertUtils.LINE_FEED); + } + // :TODO: Use a StringBufferOUTPUTStream to capture trace } errors.add(ActionErrors.GLOBAL_ERROR, @@ -875,6 +901,7 @@ if ((isStruts_1_0()) && (isMessages(request))) { saveErrors(request,getMessages(request,false)); } + return findSuccess(mapping,form,request,response); } // end execute()
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>