RE: Re: How does one forward a POST request when the POST dataha s already been processed?

2001-05-17 Thread Azariah Jeyakumar

Hi,

My earlier message was probably not clear enough.

This email pertains to the situation when a form uses "multipart/form-data"
as the enctype because it contains a "file" type input field needed for file
upload. My comments relate to how the DiskMultipartRequestHandler class
handles the multipart data especially when the request is forwarded from one
servlet to another.

Consider that an Action's perform method returns an ActionForward to another
Action in the same servlet. The first Action's form would have got a form
populated with all the multipart form data but the second Action's form does
not have the form data to populate the form. This is because, unlike the
request parameters, the multipart formdata is 'read-once-only' (because once
the data is read off the ServletInputStream, it is gone! It cannot be read
again).

Currently, the code to populate the form does something like this:
1. RequestUtils:populate() - decides that the incoming data is multipart
data (because the request's contentType is 'multipart/form-data' and the
method is 'post')
2. identifies the MultipartRequestHandler to process the formdata and
invokes handleRequest() on it
3. the DiskMultipartRequestHandler class's handleRequest() method
instantiates a MultiPartIterator to actually read the form data and process
it
4. when the MultiPartIterator does not find the data, it throws a
ServletException with "MultipartIterator: no multipart request data sent"

In a typical 'forward()' situation, the first Action reads and processes all
the multipart form data and passes it to the second Action via an attribute.
The second Action ignores the form object and gets the required data from
the attribute.
The current Struts implementation makes this impossible because the
exception is thrown before the second Action is called.

The solution that I propose is:
The step (4) should silently ignore the error if there is no multipart form
data instead of throwing the ServletException. And a null ActionForm object
should be given to the Action's perform() method if there was any error in
reading the multipart form data.

The Action can decide whether it is really an error condition and process
accordingly.

Comments anyone?

Thanks
Azariah

>  -Original Message-
> From: Azariah Jeyakumar  
> Sent: Thursday, May 17, 2001 5:11 PM
> To:   '[EMAIL PROTECTED]'
> Cc:   Martin Cooper; '[EMAIL PROTECTED]'; Azariah Jeyakumar
> Subject:  Re: How does one forward a POST request when 
> the POST data has already been processed?
> 
> Hi,
> I am facing the exact same problem that has been described below.
> Once the first servlet has read and used up the data in the 
> request's ServletInputStream, any other JSP or servlet to 
> which the request is forwarded to will face an inconsistent 
> situtaion: The contentType, method, etc say that some POST 
> data should be expected, but there is no real POST data 
> because the upstream servlet has already read the data.
> May be the first servlet can communicate to the second 
> servlet via a special request attribute that the inputStream 
> has been read?
> In a framework environment such as struts, this is a bigger 
> problem because the second servlet (which is comprised of 
> ActionServlet, RequestUtils, DiskMultipartRequestHandler, 
> MultipartIterator classes) has no generalized way of knowing 
> that the request's input stream has been read already and 
> Struts tries to process direct requests from the browser in 
> the same way as forwarded requests.
> Thanks
> Azariah
> 
> Re: How does one forward a POST request when the POST data 
> has al read y been processed?
> 
> * From: Duane Morse 
> * Subject: Re: How does one forward a POST request when the 
>   POST data has al read y been processed? 
> * Date: Thu, 30 Nov 2000 09:20:33 -0800 
> 
> That's exactly what's happening, which is the reason for my 
> question.  If
> one
> wants to separate business processing from presentation, 
> using servlets and
> EJBs
> for the former and JSPs for the latter, then how does one 
> dispatch to the
> JSP
> when the data the JSP needs is in special request attributes? 
>  My JSP is
> making
> no calls to retrieve form variables, but apparently Tomcat 
> 3.2b8 is trying
> to set
> things up so it could -- since the servlet has already 
> processed the input,
> that's
> an error.  So is there NO way to divide the labor in this 
> fashion?  How do
> you
> EVER have servlets (and JSPs) pass work among themselves if 
> the framework is
> going
> to do this sort of thing?  The first time a servlet opens the 
> input stream
> and
> reads the POST data, all subsequent servlets and JSPs are screwed.
> 
> -Original Message-
> From: Albert Wong []
> Sent: Wednesday, November 29, 2000 5:06 PM
> To: [EMAIL PROTECTED]
> Subject: Re: How does one forward a POST request when the 
> POST data has
> al read y been processed?
> 
> 
> Typically informa

Re: How does one forward a POST request when the POST data hasal ready been processed?

2001-05-17 Thread Azariah Jeyakumar

Hi,
I am facing the exact same problem that has been described below.
Once the first servlet has read and used up the data in the request's
ServletInputStream, any other JSP or servlet to which the request is
forwarded to will face an inconsistent situtaion: The contentType, method,
etc say that some POST data should be expected, but there is no real POST
data because the upstream servlet has already read the data.
May be the first servlet can communicate to the second servlet via a special
request attribute that the inputStream has been read?
In a framework environment such as struts, this is a bigger problem because
the second servlet (which is comprised of ActionServlet, RequestUtils,
DiskMultipartRequestHandler, MultipartIterator classes) has no generalized
way of knowing that the request's input stream has been read already and
Struts tries to process direct requests from the browser in the same way as
forwarded requests.
Thanks
Azariah

Re: How does one forward a POST request when the POST data has al read y
been processed?

*   From: Duane Morse 
*   Subject: Re: How does one forward a POST request when the POST data
has al read y been processed? 
*   Date: Thu, 30 Nov 2000 09:20:33 -0800 

That's exactly what's happening, which is the reason for my question.  If
one
wants to separate business processing from presentation, using servlets and
EJBs
for the former and JSPs for the latter, then how does one dispatch to the
JSP
when the data the JSP needs is in special request attributes?  My JSP is
making
no calls to retrieve form variables, but apparently Tomcat 3.2b8 is trying
to set
things up so it could -- since the servlet has already processed the input,
that's
an error.  So is there NO way to divide the labor in this fashion?  How do
you
EVER have servlets (and JSPs) pass work among themselves if the framework is
going
to do this sort of thing?  The first time a servlet opens the input stream
and
reads the POST data, all subsequent servlets and JSPs are screwed.

-Original Message-
From: Albert Wong []
Sent: Wednesday, November 29, 2000 5:06 PM
To: [EMAIL PROTECTED]
Subject: Re: How does one forward a POST request when the POST data has
al read y been processed?


Typically information to be displayed by the JSP is communicated via the
ServletRequest.setAttribute and the RequestDispatcher.  For example,
ServletA performs the business logic and stores the results using
setAttribute(java.lang.String name, java.lang.Object o), and the servlet or
jsp retreives the information using getAttribute(java.lang.String name).

If your servlet performing the business logic already called
ServletResponse.getOutputStream() or ServletResponse.getWriter() before
calling RequestDispatcher.forward then that might explain the behavior your
experiencing with Tomcat (it's not allowed by the Servlet Spec).


-Original Message-
From: Duane Morse []
Sent: Wednesday, November 29, 2000 3:27 PM
To: [EMAIL PROTECTED]
Subject: How does one forward a POST request when the POST data has
alread y been processed?


I ran into a problem with the Tomcat 3.2-b8 release, and it has implications
beyond the Tomcat
implementation; hence my posting here.

I have a servlet which processes a form which uses the POST method, and it
forwards the request
to another servlet (in this case,  a JSP) after adding a data structure to
the request object which
the target servlet should use to format the response page.  This is your
classic "let JSP handle
the presentation" mode of operations.  Since the real response data is in my
own data object,
the target servlet ignores the original input.  Tomcat's problem with this
is that it apparently tries to
prepare the target for processing POST data, but the data has already been
read, so it gets a
"short data" error (i.e., CONTENT_LENGTH is n, but the number of data bytes
in the stream is 0).

I can't see any way of changing the method type or the content length in the
request object before
forwarding it.  How should I invoke a servlet in a manner that doesn't
potentially confuse the servlet container?

Duane Morse, Eldorado Computing Inc., Phoenix AZ





RE: cvs commit: jakarta-struts/src/share/org/apache/struts/util R equestUtils.java

2001-05-17 Thread Deadman, Hal

You are unwrapping the request from the MultipartRequestWrapper object
before calling processActionForward() but don't you need to unwrap it before
calling processValidate(), processForward(), and processInclude()? All of
these may forward the wrapped request object, which won't work. Am I missing
something?

protected void process(HttpServletRequest request,
   HttpServletResponse response)
throws IOException, ServletException {

String contentType = request.getContentType();
String method = request.getMethod();

//if this is a multipart request, wrap the HttpServletRequest object
//with a MultipartRequestWrapper to keep the process sub-methods
//from failing when checking for certain request parameters
//for command tokens and cancel button detection
if ((contentType != null) &&
(contentType.startsWith("multipart/form-data"))
&& (method.equals("POST"))) {
request = new MultipartRequestWrapper(request);
}

// Identify the path component we will use to select a mapping
String path = processPath(request);
if (path == null) {
if (debug >= 1)
log(" No path available for request URI " +
request.getRequestURI());
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
   internal.getMessage("processPath"));
return;
}
if (debug >= 1)
log("Processing a " + request.getMethod() + " for " + path);

// Automatically select a locale for this user if requested
processLocale(request);

// Set the content type and no-caching headers if requested
processContent(response);
processNoCache(response);

// General purpose preprocessing hook
if (!processPreprocess(request, response))
return;

// Look up the corresponding mapping
ActionMapping mapping = processMapping(path, request);
if (mapping == null) {
if (debug >= 1)
log(" No mapping available for path " + path);
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
   internal.getMessage("processInvalid", path));
return;
}

// Process any ActionForm bean related to this request
ActionForm formInstance = processActionForm(mapping, request);
processPopulate(formInstance, mapping, request);
if (!processValidate(mapping, formInstance, request, response))
return;

// Execute a forward if specified by this mapping
if (!processForward(mapping, request, response))
return;

// Execute an include if specified by this mapping
if (!processInclude(mapping, request, response))
return;

// Acquire the Action instance to process this request
Action actionInstance = processActionCreate(mapping, request);
if (actionInstance == null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
   internal.getMessage("actionCreate",
   mapping.getPath()));
return;
}

// Call the Action instance itself
ActionForward forward =
processActionPerform(actionInstance, mapping, formInstance,
 request, response);
//set the request back to it's normal state if it's currently
wrapped,
//to avoid ClassCastExceptions from ServletContainers if forwarding
if (request instanceof MultipartRequestWrapper) {
request = ((MultipartRequestWrapper) request).getRequest();
}

// Process the returned ActionForward (if any)
processActionForward(forward, mapping, formInstance,
 request, response);

}

> -Original Message-
> From: SCHACHTER,MICHAEL (HP-NewJersey,ex2) [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 16, 2001 1:46 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: cvs commit:
> jakarta-struts/src/share/org/apache/struts/util
> R equestUtils.java
>
>
> Hal,
>
> I'm a little confused, being as I've never seen the components code.
> First,
> the request is only wrapped for multipart forms.  Second, by the time
> processForward() is called, it is passed the original request, and not
> the
> wrapped one.  What am I missing?
>
> -Original Message-
> From: Deadman, Hal [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 15, 2001 5:21 PM
> To: [EMAIL PROTECTED]
> Cc: 'Cedric Dumoulin'
> Subject: RE: cvs commit:
> jakarta-struts/src/share/org/apache/struts/util
> RequestUtils.java
>
>
> What's the plan regarding forwarding the orignal request
> instead of the
> wrapped request? Form submissions don't work in the current Struts
> build, at
> least not on Weblogic 6.0. If Acti

Displaying exception messages.

2001-05-17 Thread Marcia Mendonca Cardador

Hello,

 We are developing applications using Struts framework and EJBs. We
run into a problem regarding displaying exception messages and solved it
as follow.

Any comments, suggestions or solutions :-) are highly welcome.

Thanks and cheers,

Márcia Cardador

Summa Technologies Inc.
www.summa-tech.com

--
Scenario:

The middleware is Weblogic 5.1. We have two developmente teams: one
for JavaBeans and the other for JSP using Struts.

Problem:

Let's say that a JSP developer mispelled a JavaBean property in the
Struts tag. Instead of having an exception with a nice message saying
so, Weblogic wraps the exception and send its own exception with a
generic message (for example: "Root cause of ServletException
javax.servlet.ServletException: runtime failure in custom tag 'form'").
The JSP developer usually gets no message in the page and she can not
figure out what is wrong from the message given at the Weblogic log. The
JavaBean developer also has to try to figure out what is wrong, because
it could be something in her program logic.

Partial Solution:

We've changed the saveException method from ResquestUtils class to:

public static void saveException(PageContext pageContext,
Throwable exception) {

   // added code to write exception to response
try {

  ResponseUtils.write(pageContext, exception.getMessage()) ;

} catch (Exception ex) {

  System.out.println("Exception in trying to write in
saveException() : " + ex.getMessage());

}
   // end added code

pageContext.setAttribute(Action.EXCEPTION_KEY, exception,
PageContext.REQUEST_SCOPE);
   }


This change writes the nice exception messages to the generated HTML
page, so that the JSP developer can see it without any help from the
JavaBean developer.


Comments:

This is not a complete solution because not all tags call
RequestUtils.saveException when an exception occurs. We still get the
generic message for some basic errors. But we could speed up our
development time a little bit.

Futhermore, this solution was targeted to development phase and may
not be desirable when the application is in production.








UN-subscribe me please!

2001-05-17 Thread Katarina Nelson



UN-subscribe me please!
 


Re: Struts Overview Diagram

2001-05-17 Thread Krishna murthy

Hi
Can somebody point me where i can get the struts flow details ? i am
intending to adopt the struts framework and would like to understand the
framework better. are there any performance analysis performed for the
application incorporting the framework ?

Thanks
Regards
Krishna murthy


- Original Message -
From: Ted Husted <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, April 15, 2001 12:52 AM
Subject: Re: Struts Overview Diagram


> Damien,
>
> Just to be picky,
>
> Tomcat loads the ActionServlet. The ActionServlet in turn parses the
> struts-config file into an ActionMappings database and stores it in
> memory. Later in the process, the ActionServlet, Actions, and many of
> the tags all refer back to the ActionsMappings database in memory, but
> the config file is not read again.
>
> Damien Joldersma wrote:
> >
> > Hello,
> >
> > I recently made a diagram explaining the Struts flow for my fellow
> > co-workers so that they could understand what was going on.  It helped
> > us to understand the process and where the many components function.  We
> > offer it up for any publication or for anyone who feels it's useful.