Re: upload fail occasionally [also Re: File upload fails first time, then works after page reload]

2007-04-11 Thread Eric Rank
I ran into the same problem with inconsistent behavior when uploading  
files. Sometimes i get a RequestFacade, and sometimes I get the right  
MultiPartRequestWrapper.


I dug into the struts source code a little and I think I found the  
culprit.


in org.apache.struts2.dispatcher.FilterDispatcher there's a method  
named "prepareDispatcherAndWrapRequest" where the RequestFacade  
becomes the right kind of Request object. In the code, the wrapping  
is within a conditional block where it will only be wrapped when the  
Dispatcher instance is null. The problem when uploading a file is  
that it's not always null.


Is that the expected behavior of this method? I've never dug this deep.

The good news is that the contextCleanup filter seems to take care of  
making that Dispatcher instance null.


Finally, I hesitate suggesting a change in a class at such a  
foundational point in the framework, but what would happen if the  
request hits the wrapping part of the code outside when the  
Dispatcher instance is not null? My file upload problems are fixed,  
but what other problems would this cause?



=== Existing code for FilterDispatcher 

protected HttpServletRequest prepareDispatcherAndWrapRequest(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException {

Dispatcher du = Dispatcher.getInstance();

// Prepare and wrap the request if the cleanup filter hasn't  
already, cleanup filter should be
// configured first before struts2 dispatcher filter, hence  
when its cleanup filter's turn,

// static instance of Dispatcher should be null.
if (du == null) {

Dispatcher.setInstance(dispatcher);

// prepare the request no matter what - this ensures  
that the proper character encoding

// is used before invoking the mapper (see WW-9127)
dispatcher.prepare(request, response);

try {
// Wrap request first, just in case it is multipart/ 
form-data
// parameters might not be accessible through before  
encoding (ww-1278)
request = dispatcher.wrapRequest(request,  
getServletContext());

} catch (IOException e) {
String message = "Could not wrap servlet request  
with MultipartRequestWrapper!";

LOG.error(message, e);
throw new ServletException(message, e);
}
} // <--
//THE END OF THE LOGiC BLOCK HERE MEANS
//THAT THE Request ONLY GETS WRAPPED WHEN THE Dispatcher
//INSTANCE IS NULL. WHEN UPLOADING, IT'S SOMETIMES NOT null
else {
dispatcher = du;
}
return request;
}

=== Moving the wrapping outside of the logic block 
=== wraps the request even if the Dispatcher is not null ==


protected HttpServletRequest prepareDispatcherAndWrapRequest(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException {

Dispatcher du = Dispatcher.getInstance();

// Prepare and wrap the request if the cleanup filter hasn't  
already, cleanup filter should be
// configured first before struts2 dispatcher filter, hence  
when its cleanup filter's turn,

// static instance of Dispatcher should be null.
if (du == null) {

Dispatcher.setInstance(dispatcher);

}
else {
dispatcher = du;
}

//MOVING THE WRAPPING CODE HERE
//SO THE Request ALWAYS GETS WRAPPED

// prepare the request no matter what - this ensures  
that the proper character encoding

// is used before invoking the mapper (see WW-9127)
dispatcher.prepare(request, response);

try {
// Wrap request first, just in case it is multipart/ 
form-data
// parameters might not be accessible through before  
encoding (ww-1278)
request = dispatcher.wrapRequest(request,  
getServletContext());

} catch (IOException e) {
String message = "Could not wrap servlet request  
with MultipartRequestWrapper!";

LOG.error(message, e);
throw new ServletException(message, e);
}
return request;
}



Thanks,

Eric Rank




Dave Newton wrote:

Did either of you try specifying the context cleanup
filter?


  contextCleanup
  
org.apache.struts2.dispatcher.ActionContextCleanUp
  


and put it first in the filter mapping.

I have yet to have any issues w/ file upload since
including that and I still think I vaguely recall a
thread about this a long time ago but can no longer
find any references to it, so I could be way off-base.








-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional comm

RE: File upload fails first time, then works after page reload

2007-03-30 Thread Dave Newton
--- Dave Newton <[EMAIL PROTECTED]> wrote:
> Does using the ActionContextCleanup filter help?

Now that I sent that I think it might have had more to
do with SiteMesh than uploading, but hey... who knows.

d.



 

Get your own web address.  
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL

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



RE: File upload fails first time, then works after page reload

2007-03-30 Thread Dave Newton
--- Kelly Morrison <[EMAIL PROTECTED]> wrote:
> [file upload issues]

Does using the ActionContextCleanup filter help?

I vaguely recall some upload problems being fixed with
this, but that was a few versions ago.

If it *does* fix it, let us know and someone will
update the upload wiki docs.

d.




 

Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091

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



RE: File upload fails first time, then works after page reload

2007-03-30 Thread Kelly Morrison
Some more details: I've tracked this down to the request somehow not
being a MultiPartRequestWrapper. The problem shows up in the
FileUploadInterceptor class, specifically in the following code:

public String intercept(ActionInvocation invocation) throws
Exception {
ActionContext ac = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest)
ac.get(ServletActionContext.HTTP_REQUEST);

if (!(request instanceof MultiPartRequestWrapper)) {
 // STRUTS IS GOING HERE WITH MY REQUEST.
 // IT SAYS THE REQUEST IS A RequestFacade OBJECT.
 // WHY???
}
}

When I look at the request in the debugger, it appears to be something
called a RequestFacade. It's not a MultiPartRequestWrapper, so the
intercept() routine exits without initializing my Action.

The HTML form that posted the data looks like this:



I've specified "multipart/form-data", but that info seems to be lost
when it arrives at the FileUploadInterceptor.

Any ideas? This has me stumped. I'm thinking about writing my own file
interceptor to use until I can figure out what is going on with the
Struts version.

Thanks in advance for any suggestions,
   kell

> > >
> > > From: Kelly Morrison [mailto:[EMAIL PROTECTED]
> > > Sent: Wed 3/28/2007 12:30 AM
> > > To: Struts Users Mailing List
> > > Subject: File upload fails first time, then works after page
reload
> > >
> > >I'm a Struts newbie having problems with the file upload in
Struts
> > > 2.0.6 with Tomcat 6.0.10. When I select a file and submit it, the
> > > setXXX(), setXXXContentType(), and setXXXFileName() methods in my
> > > action aren't being called. However, if I then hit the Back button
> > > and try again, it works and my setters are called.

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



Re: File upload fails first time, then works after page reload

2007-03-29 Thread Shuai Zheng

co-ask

I face the same problem, the upload fails(the backend can't get any
parameter value -- all are nulls). Anybody know how to solve it completely?

Regards,

Zheng Shuai

On 3/29/07, Kurapica <[EMAIL PROTECTED]> wrote:


I replace the jsp file with a pure HTML file and let it works with
servlet. Now the ploblem happens occasionally, about one fail in ten
submits.

2007/3/29, Kurapica <[EMAIL PROTECTED]>:
> I met the same problem.
>
> When I use struts 2 Action to accept the form, it fails occasionally.
> Then I wrote a servlet to replace the form. With servlet, it always
> fails at first time, and success after press backspace and submit the
> form again.
>
> 2007/3/28, Kelly Morrison <[EMAIL PROTECTED]>:
> > I really don't know if I'm using NTML Authentication: how would I
check
> > that?
> >
> > I managed to work around my problem by getting the request, wrapping
it
> > in a JakartaMultiPartRequest, parsing the request, and retrieving the
> > values to initialize my class. For some reason, the very first time I
> > try to submit, the multipart request doesn't get wrapped and my bean
> > doesn't get initialized properly, but it works after that. It's very
> > puzzling.
> >
> > Thanks for the advice,
> >kell
> >
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, March 27, 2007 11:10 PM
> > To: user@struts.apache.org; user@struts.apache.org
> > Subject: RE: File upload fails first time, then works after page
reload
> >
> > Are you using the Java NTML Authentication method by any chance
(before
> > reaching this page or on this page) ?
> > NTLM makes tomcat/struts behave erratically. Form posts dont work
> > (Intermittently).
> >
> >
> > 
> >
> > From: Kelly Morrison [mailto:[EMAIL PROTECTED]
> > Sent: Wed 3/28/2007 12:30 AM
> > To: Struts Users Mailing List
> > Subject: File upload fails first time, then works after page reload
> >
> >
> >
> >I'm a Struts newbie having problems with the file upload in Struts
> > 2.0.6 with Tomcat 6.0.10. When I select a file and submit it, the
> > setXXX(), setXXXContentType(), and setXXXFileName() methods in my
action
> > aren't being called. However, if I then hit the Back button and try
> > again, it works and my setters are called.
> >
> >If I set a breakpoint in my upload action's execute() method, I can
> > see that the first time around, all the way down in the
> > CoyoteAdapter.service() method, the "file", "uploadContentType", and
> > "uploadFilename" values are all null (in the
> > request->attributes->table->...etc... data). After backing up and
> > resubmitting, the values are filled in appropriately, so it looks like
> > the problem is occurring long before my upload action is called.
> >
> >I looked through the open issues, but didn't see anything relevant.
I
> > would appreciate any suggestions that might help me debug this.
> >
> >Thanks,
> >   kell
> >
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>

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




Re: File upload fails first time, then works after page reload

2007-03-29 Thread Kurapica

I replace the jsp file with a pure HTML file and let it works with
servlet. Now the ploblem happens occasionally, about one fail in ten
submits.

2007/3/29, Kurapica <[EMAIL PROTECTED]>:

I met the same problem.

When I use struts 2 Action to accept the form, it fails occasionally.
Then I wrote a servlet to replace the form. With servlet, it always
fails at first time, and success after press backspace and submit the
form again.

2007/3/28, Kelly Morrison <[EMAIL PROTECTED]>:
> I really don't know if I'm using NTML Authentication: how would I check
> that?
>
> I managed to work around my problem by getting the request, wrapping it
> in a JakartaMultiPartRequest, parsing the request, and retrieving the
> values to initialize my class. For some reason, the very first time I
> try to submit, the multipart request doesn't get wrapped and my bean
> doesn't get initialized properly, but it works after that. It's very
> puzzling.
>
> Thanks for the advice,
>kell
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, March 27, 2007 11:10 PM
> To: user@struts.apache.org; user@struts.apache.org
> Subject: RE: File upload fails first time, then works after page reload
>
> Are you using the Java NTML Authentication method by any chance (before
> reaching this page or on this page) ?
> NTLM makes tomcat/struts behave erratically. Form posts dont work
> (Intermittently).
>
>
> 
>
> From: Kelly Morrison [mailto:[EMAIL PROTECTED]
> Sent: Wed 3/28/2007 12:30 AM
> To: Struts Users Mailing List
> Subject: File upload fails first time, then works after page reload
>
>
>
>I'm a Struts newbie having problems with the file upload in Struts
> 2.0.6 with Tomcat 6.0.10. When I select a file and submit it, the
> setXXX(), setXXXContentType(), and setXXXFileName() methods in my action
> aren't being called. However, if I then hit the Back button and try
> again, it works and my setters are called.
>
>If I set a breakpoint in my upload action's execute() method, I can
> see that the first time around, all the way down in the
> CoyoteAdapter.service() method, the "file", "uploadContentType", and
> "uploadFilename" values are all null (in the
> request->attributes->table->...etc... data). After backing up and
> resubmitting, the values are filled in appropriately, so it looks like
> the problem is occurring long before my upload action is called.
>
>I looked through the open issues, but didn't see anything relevant. I
> would appreciate any suggestions that might help me debug this.
>
>Thanks,
>   kell
>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



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



Re: File upload fails first time, then works after page reload

2007-03-29 Thread Kurapica

I met the same problem.

When I use struts 2 Action to accept the form, it fails occasionally.
Then I wrote a servlet to replace the form. With servlet, it always
fails at first time, and success after press backspace and submit the
form again.

2007/3/28, Kelly Morrison <[EMAIL PROTECTED]>:

I really don't know if I'm using NTML Authentication: how would I check
that?

I managed to work around my problem by getting the request, wrapping it
in a JakartaMultiPartRequest, parsing the request, and retrieving the
values to initialize my class. For some reason, the very first time I
try to submit, the multipart request doesn't get wrapped and my bean
doesn't get initialized properly, but it works after that. It's very
puzzling.

Thanks for the advice,
   kell

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 27, 2007 11:10 PM
To: user@struts.apache.org; user@struts.apache.org
Subject: RE: File upload fails first time, then works after page reload

Are you using the Java NTML Authentication method by any chance (before
reaching this page or on this page) ?
NTLM makes tomcat/struts behave erratically. Form posts dont work
(Intermittently).




From: Kelly Morrison [mailto:[EMAIL PROTECTED]
Sent: Wed 3/28/2007 12:30 AM
To: Struts Users Mailing List
Subject: File upload fails first time, then works after page reload



   I'm a Struts newbie having problems with the file upload in Struts
2.0.6 with Tomcat 6.0.10. When I select a file and submit it, the
setXXX(), setXXXContentType(), and setXXXFileName() methods in my action
aren't being called. However, if I then hit the Back button and try
again, it works and my setters are called.

   If I set a breakpoint in my upload action's execute() method, I can
see that the first time around, all the way down in the
CoyoteAdapter.service() method, the "file", "uploadContentType", and
"uploadFilename" values are all null (in the
request->attributes->table->...etc... data). After backing up and
resubmitting, the values are filled in appropriately, so it looks like
the problem is occurring long before my upload action is called.

   I looked through the open issues, but didn't see anything relevant. I
would appreciate any suggestions that might help me debug this.

   Thanks,
  kell



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


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


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




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



RE: File upload fails first time, then works after page reload

2007-03-28 Thread Kelly Morrison
I really don't know if I'm using NTML Authentication: how would I check
that?

I managed to work around my problem by getting the request, wrapping it
in a JakartaMultiPartRequest, parsing the request, and retrieving the
values to initialize my class. For some reason, the very first time I
try to submit, the multipart request doesn't get wrapped and my bean
doesn't get initialized properly, but it works after that. It's very
puzzling.

Thanks for the advice,
   kell

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 27, 2007 11:10 PM
To: user@struts.apache.org; user@struts.apache.org
Subject: RE: File upload fails first time, then works after page reload

Are you using the Java NTML Authentication method by any chance (before
reaching this page or on this page) ?
NTLM makes tomcat/struts behave erratically. Form posts dont work
(Intermittently).
 



From: Kelly Morrison [mailto:[EMAIL PROTECTED]
Sent: Wed 3/28/2007 12:30 AM
To: Struts Users Mailing List
Subject: File upload fails first time, then works after page reload



   I'm a Struts newbie having problems with the file upload in Struts
2.0.6 with Tomcat 6.0.10. When I select a file and submit it, the
setXXX(), setXXXContentType(), and setXXXFileName() methods in my action
aren't being called. However, if I then hit the Back button and try
again, it works and my setters are called.
  
   If I set a breakpoint in my upload action's execute() method, I can
see that the first time around, all the way down in the
CoyoteAdapter.service() method, the "file", "uploadContentType", and
"uploadFilename" values are all null (in the
request->attributes->table->...etc... data). After backing up and
resubmitting, the values are filled in appropriately, so it looks like
the problem is occurring long before my upload action is called.
  
   I looked through the open issues, but didn't see anything relevant. I
would appreciate any suggestions that might help me debug this.
  
   Thanks,
  kell
  
  

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


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


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



RE: File upload fails first time, then works after page reload

2007-03-27 Thread Amit_Wadhwa
Are you using the Java NTML Authentication method by any chance (before 
reaching this page or on this page) ?
NTLM makes tomcat/struts behave erratically. Form posts dont work 
(Intermittently).
 



From: Kelly Morrison [mailto:[EMAIL PROTECTED]
Sent: Wed 3/28/2007 12:30 AM
To: Struts Users Mailing List
Subject: File upload fails first time, then works after page reload



   I'm a Struts newbie having problems with the file upload in Struts
2.0.6 with Tomcat 6.0.10. When I select a file and submit it, the
setXXX(), setXXXContentType(), and setXXXFileName() methods in my action
aren't being called. However, if I then hit the Back button and try
again, it works and my setters are called.
  
   If I set a breakpoint in my upload action's execute() method, I can
see that the first time around, all the way down in the
CoyoteAdapter.service() method, the "file", "uploadContentType", and
"uploadFilename" values are all null (in the
request->attributes->table->...etc... data). After backing up and
resubmitting, the values are filled in appropriately, so it looks like
the problem is occurring long before my upload action is called.
  
   I looked through the open issues, but didn't see anything relevant. I
would appreciate any suggestions that might help me debug this.
  
   Thanks,
  kell
  
  

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


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