[ 
https://issues.apache.org/jira/browse/CXF-8356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17219630#comment-17219630
 ] 

Lars Ködderitzsch edited comment on CXF-8356 at 10/23/20, 10:44 AM:
--------------------------------------------------------------------

Changing 
[https://github.com/apache/cxf/blob/a421613ce5b5bb21bfa22c94a3b3fd42b77c9079/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java#L880|https://github.com/apache/cxf/blob/a421613ce5b5bb21bfa22c94a3b3fd42b77c9079/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java#L880)]

to `MediaType mt = toMediaType(contentType);` fixes those failing test cases 
for me. Of course I don't know about all the other tests :)

If the fix is correct however, you might wanto to also have a look here for a 
potential similar problem (which I didn't hit): 
[https://github.com/apache/cxf/blob/a421613ce5b5bb21bfa22c94a3b3fd42b77c9079/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java#L1021]


was (Author: lkoe):
Changing 
[https://github.com/apache/cxf/blob/a421613ce5b5bb21bfa22c94a3b3fd42b77c9079/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java#L880|https://github.com/apache/cxf/blob/a421613ce5b5bb21bfa22c94a3b3fd42b77c9079/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java#L880)]

to `MediaType mt = toMediaType(contentType);` fixes those failing test cases 
for me. Of course I don't know about all the other tests :)

If the fix is correct however, you might also have a look here for a potential 
similar problem (which I didn't hit): 
https://github.com/apache/cxf/blob/a421613ce5b5bb21bfa22c94a3b3fd42b77c9079/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java#L1021

> JAXRS Multipart-Handling broken for InputStream/Datasource parameters
> ---------------------------------------------------------------------
>
>                 Key: CXF-8356
>                 URL: https://issues.apache.org/jira/browse/CXF-8356
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.4.0, 3.3.7
>            Reporter: Lars Ködderitzsch
>            Priority: Major
>         Attachments: CXF-8356.zip
>
>
> Multipart attachements mapped to InputStream/Datasource parameters are 
> currently broken, due to their respective DelegatingInputStream being closed 
> too early.
> As of cxf-3.3.4 this was still working.
> As far as I can see, the early closing happens here:
> {code:java}
> Daemon System Thread [default-workqueue-1] (Suspended (breakpoint at line 46 
> in DelegatingInputStream))       
>       owns: PhaseInterceptorChain  (id=49)    
>       DelegatingInputStream.close() line: 46  
>       JAXRSUtils.copyAndGetEntityStream(Message) line: 1897   
>       JAXRSUtils.processRequestBodyParameter(Class<?>, Type, Annotation[], 
> Message, OperationResourceInfo) line: 884  
>       JAXRSUtils.processParameters(OperationResourceInfo, 
> MultivaluedMap<String,String>, Message) line: 832   
>       JAXRSInInterceptor.processRequest(Message, Exchange) line: 214  
>       JAXRSInInterceptor.handleMessage(Message) line: 78      
>       PhaseInterceptorChain.doIntercept(Message) line: 308    
>       ChainInitiationObserver.onMessage(Message) line: 121    
>       LocalConduit$LocalConduitOutputStream$1.run() line: 88  
>       AutomaticWorkQueueImpl$3.run() line: 412        
>       
> AutomaticWorkQueueImpl$1(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker)
>  line: 1128    
>       ThreadPoolExecutor$Worker.run() line: 628       
>       AutomaticWorkQueueImpl$AWQThreadFactory$1.run() line: 345       
>       Thread.run() line: 834  
> {code}
> I believe this change 
> (https://github.com/apache/cxf/commit/dc71ce1635330136e472e0b6fb5ce4a71ae0d474)
>  led to this issue, due to `contentType` and `mt` (Mediatype) variable 
> disagreeing, leading to unwanted? copy and closing of the stream.
> A few lines below the `contentType` is used again to derive the MediaType, 
> which leads me to believe the first`mt` variable is incorrect.
> A local patch for this line made it working again for me, although I am 
> uncertain this is the correct fix:
> {code:java}
> MediaType mt = toMediaType(contentType);
> {code}
> For reference, one of the annotated methods producing this issue for us:
> {code:java}
>     @POST
>     @Path("/pdf")
>     @Consumes(MediaType.MULTIPART_FORM_DATA)
>     @Operation(summary = "Rendert das übergebene TemplateModel mit Hilfe des 
> übergebenen Templates")
>     Response getPDF(
>             @Parameter(
>                     description = "Das Template, das zum Rendern der Daten 
> benutzt wird",
>                     content = @Content(schema = @Schema(implementation = 
> TemplatePart.class))) @Multipart(
>                             value = "template", type = 
> "application/octet-stream") InputStream template,
>             @Parameter(description = "Charset des Templates") 
> @QueryParam("charset") String charset,
>             @RequestBody(
>                     description = "Die Daten, die mit Hilfe des übergebenen 
> Templates gerendert werden") @Multipart(
>                             value = "data", type = "application/json") 
> TemplateModel data);
> {code}
> In this case this issue led to `template` being a `DelegatingInputStream` 
> wrapping another (closed) `DelegatingInputStream` on the server side.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to