craigmcc    2002/08/03 17:33:04

  Modified:    src/share/org/apache/struts/actions DispatchAction.java
  Log:
  Equip DispatchAction with a new method -- unspecified() -- that is called
  if the request does not include a value for the request parameter used to
  select the method to be dispatched to.  Subclasses can easily override this
  method to provide appropriate default behavior.
  
  If not overridden, unspecified() does what was previously hard coded if the
  method name was null:  send an HTTP "Bad Request" response.
  
  PR: Bugzilla #11283
  Submitted by: Dylan van Iersel <dylan at van-iersel.org>
  
  Revision  Changes    Path
  1.10      +77 -59    
jakarta-struts/src/share/org/apache/struts/actions/DispatchAction.java
  
  Index: DispatchAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/actions/DispatchAction.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DispatchAction.java       3 Aug 2002 20:54:54 -0000       1.9
  +++ DispatchAction.java       4 Aug 2002 00:33:04 -0000       1.10
  @@ -176,6 +176,79 @@
   
   
   
  +    // --------------------------------------------------------- Public Methods
  +
  +
  +    /**
  +     * Process the specified HTTP request, and create the corresponding HTTP
  +     * response (or forward to another web component that will create it).
  +     * Return an <code>ActionForward</code> instance describing where and how
  +     * control should be forwarded, or <code>null</code> if the response has
  +     * already been completed.
  +     *
  +     * @param mapping The ActionMapping used to select this instance
  +     * @param actionForm The optional ActionForm bean for this request (if any)
  +     * @param request The HTTP request we are processing
  +     * @param response The HTTP response we are creating
  +     *
  +     * @exception Exception if an exception occurs
  +     */
  +    public ActionForward execute(ActionMapping mapping,
  +                                 ActionForm form,
  +                                 HttpServletRequest request,
  +                                 HttpServletResponse response)
  +        throws Exception {
  +
  +        // Identify the request parameter containing the method name
  +        String parameter = mapping.getParameter();
  +        if (parameter == null) {
  +            String message =
  +                messages.getMessage("dispatch.handler", mapping.getPath());
  +            log.error(message);
  +            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
  +                               message);
  +            return (null);
  +        }
  +
  +        // Identify the method name to be dispatched to
  +        String name = request.getParameter(parameter);
  +        if (name == null) {
  +            name = "unspecified";
  +        }
  +
  +        // Invoke the named method, and return the result
  +        return dispatchMethod(mapping,form,request,response,name);
  +
  +    }
  +
  +
  +    /**
  +     * Method which is dispatched to when there is no value for specified
  +     * request parameter included in the request.  Subclasses of
  +     * <code>DispatchAction</code> should override this method if they wish
  +     * to provide default behavior different than producing an HTTP
  +     * "Bad Request" error.
  +     *
  +     */
  +    public ActionForward unspecified(ActionMapping mapping,
  +                                     ActionForm form,
  +                                     HttpServletRequest request,
  +                                     HttpServletResponse response)
  +        throws Exception {
  +
  +        String message =
  +            messages.getMessage("dispatch.parameter", mapping.getPath(),
  +                                mapping.getParameter());
  +        log.error(message);
  +        response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
  +        return (null);
  +
  +    }
  +
  +
  +    // ----------------------------------------------------- Protected Methods
  +
  +
       /**
        * Dispatch to the specified method.
        * Added to class at Revision 1.3
  @@ -241,61 +314,6 @@
           // Return the returned ActionForward instance
           return (forward);
       }
  -
  -
  -// --------------------------------------------------------- Public Methods
  -
  -
  -    /**
  -     * Process the specified HTTP request, and create the corresponding HTTP
  -     * response (or forward to another web component that will create it).
  -     * Return an <code>ActionForward</code> instance describing where and how
  -     * control should be forwarded, or <code>null</code> if the response has
  -     * already been completed.
  -     *
  -     * @param mapping The ActionMapping used to select this instance
  -     * @param actionForm The optional ActionForm bean for this request (if any)
  -     * @param request The HTTP request we are processing
  -     * @param response The HTTP response we are creating
  -     *
  -     * @exception Exception if an exception occurs
  -     */
  -    public ActionForward execute(ActionMapping mapping,
  -                                 ActionForm form,
  -                                 HttpServletRequest request,
  -                                 HttpServletResponse response)
  -        throws Exception {
  -
  -        // Identify the request parameter containing the method name
  -        String parameter = mapping.getParameter();
  -        if (parameter == null) {
  -            String message =
  -                messages.getMessage("dispatch.handler", mapping.getPath());
  -            log.error(message);
  -            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
  -                               message);
  -            return (null);
  -        }
  -
  -        // Identify the method name to be dispatched to
  -        String name = request.getParameter(parameter);
  -        if (name == null) {
  -            String message =
  -                messages.getMessage("dispatch.parameter", mapping.getPath(),
  -                                    parameter);
  -            log.error(message);
  -            response.sendError(HttpServletResponse.SC_BAD_REQUEST,
  -                               message);
  -            return (null);
  -        }
  -
  -        // Invoke the named method, and return the result
  -        return dispatchMethod(mapping,form,request,response,name);
  -
  -    }
  -
  -
  -    // ----------------------------------------------------- Protected Methods
   
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to