Re: ActionFileUploadInterceptor Issue

Zoran Avtarovski <[email protected]> Thu, 15 May 2025 15:53:39 +1000
Newsgroups gmane.comp.jakarta.struts.user
Message-ID <[email protected]>
Hi Lukasz,

We have resolved the issue and I thought I would share our findings. I'd 
hate to see someone as frustrated as our junior here was. He was quite 
the angry young man.

The issue was the struts filters. Our app was setup using the 
struts-prepare and struts-execute filters separately as we use sitemesh 
for decoration.

Once we moved to the StrutsPrepareAndExecuteFilter as a single entry all 
worked as expected, even sitemesh seemed to have no obvious issues.

I haven't had time to look at the code for each to see the reason, but I 
will and will let you know.

Z.


On 14/5/2025 3:50 pm, Zoran Avtarovski wrote:
> Thanks Lukasz,
>
> We got the file-upload test app to work without any real issues.
>
> It's no a case of adding all the interceptors and other libraries we 
> use to see which is changing the request object.
>
> I've got one of the young guys on it. They are having so much fun 
> right now :)
>
> Z.
>
>
>
> On 14/5/2025 4:49 am, Lukasz Lenart wrote:
>> Could you check if this example works for you?
>> https://github.com/apache/struts-examples/tree/main/file-upload
>>
>> wt., 13 maj 2025 o 08:28 Zoran Avtarovski<[email protected]> 
>> napisał(a):
>>> Hi Lukasz,
>>>
>>> That's what I thought initially, but we only use the spring plugin for
>>> dependency injection and the tomcat changes seem to happen much earlier
>>> in the request cycle.
>>>
>>> I was wondering if any of the interceptors in the defaultStack might be
>>> making a change. I was being lazy and hoping someone might have noticed
>>> something similar, but we will add some extra logging at each stage of
>>> the interceptor stack to check the instance type of the request to see
>>> where it changes.
>>>
>>> Z.
>>>
>>>
>>>
>>> On 13/5/2025 3:38 pm, Lukasz Lenart wrote:
>>>> What else do you use? Spring, Tomcat? It looks like something is
>>>> changing the type of MultiPartRequestWrapper between Dispatcher and
>>>> interceptors, mayb the request is wrapped with another proxy?
>>>>
>>>> wt., 13 maj 2025 o 01:48 Zoran Avtarovski<[email protected]> 
>>>> napisał(a):
>>>>> Hi Guys,
>>>>>
>>>>> We have started migrating our apps to 6.7.4 and have run into an 
>>>>> issue
>>>>> with file uploads. We have migrated our actions to use the new
>>>>> ActionFileUploadInterceptor but we are seeing an issue where the 
>>>>> upload
>>>>> requests are being incorrectly bypassed.
>>>>>
>>>>> I have reduced it to a simple example which I will include at the end
>>>>> but the key bits are the debug logs from struts. We are seeing the
>>>>> request processed correctly, except for the last step where the 
>>>>> upload
>>>>> is bypassed:
>>>>>
>>>>> dispatcher.Dispatcher (Dispatcher.java:1054) - Support for 
>>>>> multipart request is enabled: true
>>>>> dispatcher.Dispatcher (Dispatcher.java:1072) - Validating if this 
>>>>> is a proper Multipart request. Request is POST: true and 
>>>>> ContentType matches pattern 
>>>>> (^multipart/form-data(?:\s*;\s*boundary=[0-9a-zA-Z'"()+_,\-./:=?]{1,70})?(?:\s*;\s*charset=[a-zA-Z\-0-9]{3,14})?): 
>>>>> true
>>>>> dispatcher.Dispatcher (Dispatcher.java:1030) - Wrapping multipart 
>>>>> request with: MultiPartRequestWrapper
>>>>>
>>>>> multipart.JakartaMultiPartRequest 
>>>>> (JakartaMultiPartRequest.java:105) - Found file item: [document]
>>>>> multipart.JakartaMultiPartRequest 
>>>>> (JakartaMultiPartRequest.java:116) - Item is a file upload
>>>>>
>>>>> interceptor.FileUploadInterceptor (FileUploadInterceptor.java:197) 
>>>>> - Bypassing /action/...
>>>>> interceptor.ActionFileUploadInterceptor 
>>>>> (ActionFileUploadInterceptor.java:139) - Bypassing /action/...
>>>>>
>>>>> The struts dispatcher sees the request as being a valid Multipart 
>>>>> POST
>>>>> request and and wraps it with the MultipartRequestMapper.
>>>>> The JakartaMultiPartRequest finds and recognises the uploaded file
>>>>> parameter [document]
>>>>> But then the two upload interceptors Bypass processing which means 
>>>>> the
>>>>> withUploadedFiles method on the action is not called.
>>>>>
>>>>> I had a look at the source for the ActionFileUploadInterceptor and 
>>>>> the
>>>>> request is only bypassed if it is not an instance of
>>>>> MultipartRequestMapper, which according to the logs it is. I'm very
>>>>> confused. I setup a simple test to prove we weren't going mad.
>>>>>
>>>>> Form is a simple form:
>>>>>
>>>>>        <s:form action="saveStockItem" method="POST" 
>>>>> enctype="multipart/form-data">
>>>>>            <s:hidden name="item.itemId"/>
>>>>>            <s:textfield name="item.name" 
>>>>> key="stock.name"></s:textfield>
>>>>>            <s:textarea name="item.description" 
>>>>> key="stock.description"></s:textarea>
>>>>>            <s:file name="document" key="stock.image"></s:file>
>>>>>            <s:submit >upload</s:submit>
>>>>>        </s:form>
>>>>>
>>>>> The stack is the struts standard defaultStack from the core
>>>>> struts-default.xml
>>>>>
>>>>>        <action name="saveStockItem" class="stockAction" 
>>>>> method="save">
>>>>>            <interceptor-ref name="defaultStack"/>
>>>>>            <result name="input">/WEB-INF/pages/formStock.jsp</result>
>>>>>            <result name="success" 
>>>>> type="redirectAction">stockItems</result>
>>>>>        </action>
>>>>>
>>>>> The action class implements UploadedFilesAware and has an appropriate
>>>>> withUploadedFiles method.
>>>>>
>>>>> Has anyone experienced this or is it obvious what we are missing. Any
>>>>> help would be appreciated.
>>>>>
>>>>> Zoran
>>>> ---------------------------------------------------------------------
>>>> 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]
>>