-
Couldn't load subscription status.
- Fork 5.3k
allow users to plug in a ProgressListener via some factory. #856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow users to plug in a ProgressListener via some factory. #856
Conversation
java/org/apache/tomcat/util/http/fileupload/ProgressListenerFactory.java
Outdated
Show resolved
Hide resolved
78d3e5f to
2a649a8
Compare
|
What do you think about being able to register more than one listener? Should the application be able to register a listener for just a single request, then deregister it? Or is your concept that the application has one single listener, and then it's up to the application to figure out the details from there? |
Many thanks for your comments. I still need to experiment with this and Wicket and see what is more convenient. I just used this POC in order to plug in a very simple listener on my customer's app. My next step is try to roll a "tomcat native" way to do upload progress in Wicket. That is, Wicket just sets a listener and tomcat does the dirty job... and wicket part just reports to the UI as it does now. To be totally honest for wicket would be best if tomcat behaves as "before". From wicket's perpective this is just "a hack". Because this solution will be only for tomcat (that is what my customer's application uses). But other application server might still need to use default fileupload2 approach. Why I'm trying to do this. Now I have fixed wicket + our application to not call getParameters before our uploads take place (uploads with progress). But tomorrow we introduce a new filter in front of wicket filter and this new filter calls getParameters.... and our uploads will be broken and we will be scratching our heads wondering how. This can be as simple as a library upgrade... Here I have added a factory for listeners... Each ServletContext can define one via init parameters. For each multipart request this factory is asked if a listener is needed. My, guess is, in the wicket context, this will be something calling the upload progress updating machinery wicket has (that is page specific). Thus, factory just creates some ephemeral listener for that request in particular. I need to try. Regarding many or one. Factory is one and listener per request is one. But a Listener can be anything and also be compound (more than one listener). Hum... I'm new to tomcat code-base I don't know if coyote Requests are reusable... I need to check. If so we maybe need to do some clean up. I will prepare a wicket PR alongside this one and see how flexible is that I defined here. |
It would be nice if the specification defines some standard way to listen for uploads progress... Then Wicket or any other framework just hook into this standard |
e405d41 to
47674e2
Compare
47674e2 to
38c55b2
Compare
|
@ChristopherSchultz I have implemented A way to get Wicket's support for upload with progress using work in this PR. |
|
@ChristopherSchultz any chances to get this PR merged into Tomcat 11?
Even without having wicket PR merged this would help solve our problem as I can do the same developments I did for wicket in our application and once new changes are introduced in Wicket (if they are) revert to using what Wicket offers. |
|
Personally I am not a fan at all right now:
|
|
Let's see how the feature proposal progresses first then. |
Ok.
I'm totally new to Tomcat code-base. I tried to solve a problem. If the way I did it is not correct then I'm all ears about changing code in the right way.
What shall I do with respect to this?
I do agree about adding this to specification... But way Tomcat behaves now is not good because:
|
|
Thanks for the link. See jakartaee/servlet#66 (comment) IMHO what is described there is not what we need... because it has the same problem we have now. |
Which is what, exactly? |
The problem now is: 1) "someone" calls getParamaters 2) then tomcat parse the parts 3) when wicket calls getInputStream if is already used. What is proposed this is the way to set the listener: Ok. Assume we do this in Wicket filter... Then
What I propose here is:
The above is safe because the listener is created by tomcat itself via the factory. Thus, no matter who triggers the parsing of the parts the listener will receive the notifications. Another problem with that design is:
Thus... IMHO... this PR is also not correct. You Should maybe have some stack of factories and each factory adds a Listener and then tomcat call each of them in order. |
You suggested to avoid using multipart... but again. Your servlet is not ISOLATED. E.g. in case of Wicket many thing can happen before you arrive to parse yourself multipart... E.g. as soon as someone requests parameter value Tomcat will fail. aused by: java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided What I propose here will work (does work as I have our application working with these changes). |
|
It looks like Tomcat parsing parts for |
This is how all started ... https://bz.apache.org/bugzilla/show_bug.cgi?id=69689 I reported the above. Because it is not a backwards compatible behavior. Then it was closed as work as expected as per specification. Then I decided to do this work even when I found a work around for our application + some changes in wicket... because that was a very weak way to "fix" the problem. If this ISSUE is fixed in tomcat them this work is not needed at all and wicket will work as it is now (parsing the input stream using fileupload2). Anyways... would be nice to have because then wicket will not need this custom logic to support multipart progress |
Not quite. The provided reproducer uses the |
Not following you.
|
That looks like a Tomcat bug but I need to confirm that. Assuming it is a bug, once that bug is fixed, this becomes the solution.
That is what the provided reproducer does so the behaviour of the reproducer as as designed. |
I do agree... Many thanks for all you answers!
|
|
Fixed for 11.0.8 onwards. |
Saw the commit. Many thanks. Thus now applications can work as before. I will test our application + Latest wicket 10.x against unreleased tomcat and confirm. |
Yes. This fixes our ISSUE! Thanks again! |
We add a way for users to plug in listeners into upload processing so that custom applications can hook into multipart requests and provide custom progress reporting.
See
https://bz.apache.org/bugzilla/show_bug.cgi?id=69690
This appear in the context of
https://issues.apache.org/jira/browse/WICKET-7154
Changes on tomcat 11 make wicket support for multipart very "shaky" as any call to get POST parameters before wicket logic for multi-part processing takes place would make tomcat consume the request. With this changes I plan to introduce "native" tomcat processing into wicket as an option (with progress reporting that wicket now supports).
I have created a PR to wicket allowing to use the work in this PR in order to do uploads and report progress. This seems to work in our application. See
apache/wicket#1167