You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Henri ENEE (Jira)" <ji...@apache.org> on 2021/07/09 08:41:00 UTC
[jira] [Commented] (CXF-8554)
org.apache.cxf.jaxrs.ext.MessageContextImpl.createAttachments first
attachment input stream is null
[ https://issues.apache.org/jira/browse/CXF-8554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17377932#comment-17377932 ]
Henri ENEE commented on CXF-8554:
---------------------------------
Hi Freeman Yue Fang,
It's not exactly the scenario you describe because I am not directly packaging the attachment stream into a message passed to the AMQ queue.
Indeed, I get the attachments map in cxf server side (The issue occurs here), next I turn it into a serializable map (to respect the JMS TextMessage format), next I package the serialized map in a JMS message.
I can understand that you don't want to cache the inpustream of the request, but, in my opinion, the methods provided by your API should work.
* AttachmentUtils.populateFormMap
* AttachmentUtils.getMultipartBody
* (MultipartBody)mc.get(MultipartBody.INBOUND_MESSAGE_ATTACHMENTS
However, I found a workaround by following your advise and with the help of this page : https://stackoverflow.com/Questions/10210645/http-servlet-request-lose-params-from-post-body-after-read-it-once
I created a filter and a request wrapper in order to read the inputsream multiple times.
Next I created a ContainerRequestFilter to store the attachments map into the message in order to get this map later in my code.
It works but It was a little bit tricky to parse the body and transform it into attachments map :p (And I still have encoding issues)
Therefore, I will appreciate that this functionality is provided by CXF
> org.apache.cxf.jaxrs.ext.MessageContextImpl.createAttachments first attachment input stream is null
> ---------------------------------------------------------------------------------------------------
>
> Key: CXF-8554
> URL: https://issues.apache.org/jira/browse/CXF-8554
> Project: CXF
> Issue Type: Bug
> Components: JAX-RS
> Affects Versions: 3.3.6
> Reporter: Henri ENEE
> Priority: Blocker
>
> I need to get the attachments map, but the first attachment is still empty.
> I think the issue comes from the method org.apache.cxf.jaxrs.ext.MessageContextImpl.createAttachments line 292
> The first attachment is loaded with the following method "inMessage.getContent(InputStream.class)"
> but the InputStream is not buffered and so I think when i want to read this value later in my code, the stream is closed and I get an empty string.
>
> {code:java}
> @POST
> @Path("")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> @Description("Create a task")
> public void createTask(
> @Multipart(value = "title", type = "text/plain", required = false) final String title,
> @Multipart(value = "description", type = "text/plain", required = false) final String description,
> @javax.ws.rs.core.Context final MessageContext mc) throws MatrixException {
> /* param well filled */
> System.out.println("title: " + title);
> // >title: myTitle
> System.out.println("description: " + description);
> // >description: myDescription
> /* first attachment of attachment map is empty */
> final MultivaluedMap<String, String> attachmentMap = AttachmentUtils.populateFormMap(mc);
> System.out.println("The set is: " + attachmentMap.entrySet());
> // >The set is: [title=[], description=[myDescription]]
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)