Discussion:
CXF 3.0.3 - org.apache.cxf.interceptor.Fault: No message body writer has been found for class org.apache.cxf.jaxrs.ext.multipart.MultipartBody, ContentType: multipart/form-data
nicolasduminil
2017-05-22 15:08:50 UTC
Permalink
Hello,

I've seen dozens of posts reporting this issue but I didn't see any
solution. In order to upload a file, I'm calling a JAX-RS CXF 3.0.3 service
as follows:

WebClient webClient = WebClient.create("...");
webClient.encoding("UTF-8");
webClient.type(MediaType.MULTIPART_FORM_DATA);
webClient.post(new MultipartBody(new Attachment("contracts", new
FileInputStream("test.pdf"), new ContentDisposition("filename=test.pdf"))));

and it works as expected.

Now, I need to call the service with a list of attachments, so I do as
follows:

WebClient webClient = WebClient.create("...");
webClient.encoding("UTF-8");
webClient.type(MediaType.MULTIPART_FORM_DATA);
List<Attachment> attachments = new ArrayList<Attachment>();
attachments.add (new Attachment ( ...);
attachments.add (new Attachment (...);
...

webClient.post(new MultipartBody(attachments);

and the I get:

156 [main] ERROR org.apache.cxf.jaxrs.utils.JAXRSUtils - No message body
writer has been found for class
org.apache.cxf.jaxrs.ext.multipart.MultipartBody, ContentType:
multipart/form-data
156 [main] WARN org.apache.cxf.phase.PhaseInterceptorChain - Interceptor
for {http://localhost:9081/qs/services/api/createTransaction}WebClient has
thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No message body writer has been found for
class org.apache.cxf.jaxrs.ext.multipart.MultipartBody, ContentType:
multipart/form-data
at
org.apache.cxf.jaxrs.client.WebClient$BodyWriter.doWriteBody(WebClient.java:1220)
at
org.apache.cxf.jaxrs.client.AbstractClient$AbstractBodyWriter.handleMessage(AbstractClient.java:1044)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at
org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:623)
at
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1084)
at
org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:883)
at
org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:854)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:320)
at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:329)
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:272)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:236)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:386)
at
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:323)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:143)
Caused by: javax.ws.rs.ProcessingException: No message body writer has been
found for class org.apache.cxf.jaxrs.ext.multipart.MultipartBody,
ContentType: multipart/form-data
at
org.apache.cxf.jaxrs.client.AbstractClient.reportMessageHandlerProblem(AbstractClient.java:740)
at
org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:469)
at
org.apache.cxf.jaxrs.client.WebClient$BodyWriter.doWriteBody(WebClient.java:1215)
... 35 more
Caused by: java.io.IOException: Stream Closed
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:233)
at javax.activation.DataHandler.writeTo(DataHandler.java:308)
at
org.apache.cxf.jaxrs.provider.MultipartProvider.writeTo(MultipartProvider.java:266)
at
org.apache.cxf.jaxrs.utils.JAXRSUtils.writeMessageBody(JAXRSUtils.java:1363)
at
org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:455)
... 36 more
[ERROR] Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed:
0.734 s <<< FAILURE! - in
be.alphacredit.services.esign.tests.QuickControllerServiceIT
[ERROR]
testUpload(be.alphacredit.services.esign.tests.QuickControllerServiceIT)
Time elapsed: 0.125 s <<< ERROR!
javax.ws.rs.ProcessingException: org.apache.cxf.interceptor.Fault: No
message body writer has been found for class
org.apache.cxf.jaxrs.ext.multipart.MultipartBody, ContentType:
multipart/form-data
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
Caused by: org.apache.cxf.interceptor.Fault: No message body writer has been
found for class org.apache.cxf.jaxrs.ext.multipart.MultipartBody,
ContentType: multipart/form-data
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
Caused by: javax.ws.rs.ProcessingException: No message body writer has been
found for class org.apache.cxf.jaxrs.ext.multipart.MultipartBody,
ContentType: multipart/form-data
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
Caused by: java.io.IOException: Stream Closed
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)

Why it works properly with one attachment by MultipartBody and, as soon as
I'm using a list of attachments in the MultipartBody, it raises this
execption ?

Many thanks in advance.

Nicolas




--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611.html
Sent from the cxf-user mailing list archive at Nabble.com.
Sergey Beryozkin
2017-05-22 20:56:07 UTC
Permalink
Hi

I can see a CXF test where a List of Attachment is posted directly
without wrapping it in MultipartBody (I expect it to work too).

Can you please try to send a List directly ? Will it work for you ?

Cheers, Sergey
Post by nicolasduminil
Hello,
I've seen dozens of posts reporting this issue but I didn't see any
solution. In order to upload a file, I'm calling a JAX-RS CXF 3.0.3 service
WebClient webClient = WebClient.create("...");
webClient.encoding("UTF-8");
webClient.type(MediaType.MULTIPART_FORM_DATA);
webClient.post(new MultipartBody(new Attachment("contracts", new
FileInputStream("test.pdf"), new ContentDisposition("filename=test.pdf"))));
and it works as expected.
Now, I need to call the service with a list of attachments, so I do as
WebClient webClient = WebClient.create("...");
webClient.encoding("UTF-8");
webClient.type(MediaType.MULTIPART_FORM_DATA);
List<Attachment> attachments = new ArrayList<Attachment>();
attachments.add (new Attachment ( ...);
attachments.add (new Attachment (...);
...
webClient.post(new MultipartBody(attachments);
156 [main] ERROR org.apache.cxf.jaxrs.utils.JAXRSUtils - No message body
writer has been found for class
multipart/form-data
156 [main] WARN org.apache.cxf.phase.PhaseInterceptorChain - Interceptor
for {http://localhost:9081/qs/services/api/createTransaction}WebClient has
thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No message body writer has been found for
multipart/form-data
at
org.apache.cxf.jaxrs.client.WebClient$BodyWriter.doWriteBody(WebClient.java:1220)
at
org.apache.cxf.jaxrs.client.AbstractClient$AbstractBodyWriter.handleMessage(AbstractClient.java:1044)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at
org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:623)
at
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1084)
at
org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:883)
at
org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:854)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:320)
at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:329)
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:272)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:236)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:386)
at
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:323)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:143)
Caused by: javax.ws.rs.ProcessingException: No message body writer has been
found for class org.apache.cxf.jaxrs.ext.multipart.MultipartBody,
ContentType: multipart/form-data
at
org.apache.cxf.jaxrs.client.AbstractClient.reportMessageHandlerProblem(AbstractClient.java:740)
at
org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:469)
at
org.apache.cxf.jaxrs.client.WebClient$BodyWriter.doWriteBody(WebClient.java:1215)
... 35 more
Caused by: java.io.IOException: Stream Closed
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:233)
at javax.activation.DataHandler.writeTo(DataHandler.java:308)
at
org.apache.cxf.jaxrs.provider.MultipartProvider.writeTo(MultipartProvider.java:266)
at
org.apache.cxf.jaxrs.utils.JAXRSUtils.writeMessageBody(JAXRSUtils.java:1363)
at
org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:455)
... 36 more
0.734 s <<< FAILURE! - in
be.alphacredit.services.esign.tests.QuickControllerServiceIT
[ERROR]
testUpload(be.alphacredit.services.esign.tests.QuickControllerServiceIT)
Time elapsed: 0.125 s <<< ERROR!
javax.ws.rs.ProcessingException: org.apache.cxf.interceptor.Fault: No
message body writer has been found for class
multipart/form-data
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
Caused by: org.apache.cxf.interceptor.Fault: No message body writer has been
found for class org.apache.cxf.jaxrs.ext.multipart.MultipartBody,
ContentType: multipart/form-data
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
Caused by: javax.ws.rs.ProcessingException: No message body writer has been
found for class org.apache.cxf.jaxrs.ext.multipart.MultipartBody,
ContentType: multipart/form-data
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
Caused by: java.io.IOException: Stream Closed
at
be.alphacredit.services.esign.tests.QuickControllerServiceIT.testUpload(QuickControllerServiceIT.java:63)
Why it works properly with one attachment by MultipartBody and, as soon as
I'm using a list of attachments in the MultipartBody, it raises this
execption ?
Many thanks in advance.
Nicolas
--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611.html
Sent from the cxf-user mailing list archive at Nabble.com.
nicolasduminil
2017-05-23 08:06:37 UTC
Permalink
Hi Serghei,

Yes, I've tried to post directly a list of attachments with the same result.
Please notice that my use case is a bit particular as the service signature
is as follows:

@POST
@Consumes("multipart/form-data")
@Path("createTransaction")
public Response createQuickSignTransaction(IMultipartBody multipartBody)
throws QuickSignException

As you may see, the multipartBody is a
com.ibm.websphere.jaxrs20.multipart.IMultipartBody type instead of
org.apache.cxf.jaxrs.ext.multipart.MultipartBody. This is due to this issue
http://cxf.547215.n5.nabble.com/WebSphere-9-0-0-3-How-to-know-what-is-the-version-of-Apache-CXF-td5780567.html#a5780603.

Do you have any suggestion of how can I deal with that ?

Kind regards,

Nicolas



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780621.html
Sent from the cxf-user mailing list archive at Nabble.com.
Dennis Kieselhorst
2017-05-23 07:06:45 UTC
Permalink
Hi Nicolas,

I was not able to reproduce this using the latest release. Can you update the CXF version?

Otherwise you can check the Multipart testcases which were running successfully for 3.0.3 and adapt your code accordingly:
https://github.com/apache/cxf/blob/cxf-3.0.3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java

Regards
Dennis
nicolasduminil
2017-05-23 08:09:58 UTC
Permalink
Hi Dennis,

No, as I explained in my initial post, it is not possible to update anything
as I have to use the CXF released with WebSphere AS 9.0.0.3, which is CXF
3.0.3.

And yes, I have checked the testcases and, as you may see, the code I posted
is equivalent, with the only difference that mine doesn't work.

And yes, there is another difference as well as replied to Serghei here
below.

Do you have any other suggestion please ?

Kind regards,

Nicolas



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780622.html
Sent from the cxf-user mailing list archive at Nabble.com.
nicolasduminil
2017-05-23 08:37:00 UTC
Permalink
Just a short note to mention that these Multipart testcases are all using
static JSON files instead of constructing payloads in JAX-RS clients by
handling MultipartBody and, as such, they are really of little help for real
usages.

Kind regards,
Nicolas



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780624.html
Sent from the cxf-user mailing list archive at Nabble.com.
Sergey Beryozkin
2017-05-23 08:45:07 UTC
Permalink
Hi Nicolas

I'm not sure how we can help given that passing a List directly or
wrapped into MultipartBody (as confirmed by Dennis) works with the
latest CXF.
The CXF test I was referring to (putting aside the fact that some tests
might use the static resources - I recall for ex I needed to try the
payload posted by a 3rd party client) works in CXF 3.0.13.

Given that you depend on 3.0.3, can you replace CXF 3.0.3 libraries with
CXF 3.0.13 ones and see if it helps ? If it won't then I can only
recommend opening an issue with the WebSphere team

Cheers, Sergey
Post by nicolasduminil
Just a short note to mention that these Multipart testcases are all using
static JSON files instead of constructing payloads in JAX-RS clients by
handling MultipartBody and, as such, they are really of little help for real
usages.
Kind regards,
Nicolas
--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780624.html
Sent from the cxf-user mailing list archive at Nabble.com.
nicolasduminil
2017-05-23 10:09:55 UTC
Permalink
Hi,

Apache CXF 3.0.3 comes bundled with WebSphere 9.0.0.3 accordingly I cannot
replace the libraries. I could deploy another release of CXF with my WAR
but, in this case, it would conflict with the classes already deployed into
the app server. I could also modify the class-loading strategy such that to
use the classes bundled into the WAR rather then the ones provide by the app
server, but then I would fall into other issues. And anyway, wether this
works or not, at the end of the day I need to work with what is provided by
WebSphere, as there is no other option.

So, replacing CXF 3.0.3 by 3.0.13 wouldn't have any benefice, wether it
works or not.

But I noticed that the the exception:

org.apache.cxf.interceptor.Fault: No message body writer has been found for
class org.apache.cxf.jaxrs.ext.multipart.MultipartBody, ContentType:
multipart/form-data

is caused by the following:

Caused by: java.io.IOException: Stream Closed
at java.io.FileInputStream.available(Native Method)
at org.apache.cxf.helpers.IOUtils.copy(IOUtils.java:148)
at org.apache.cxf.helpers.IOUtils.copy(IOUtils.java:107)
at
org.apache.cxf.helpers.IOUtils.copyAndCloseInput(IOUtils.java:113)
at
org.apache.cxf.jaxrs.provider.BinaryDataProvider.copyInputToOutput(BinaryDataProvider.java:186)
at
org.apache.cxf.jaxrs.provider.BinaryDataProvider.writeTo(BinaryDataProvider.java:146)
at
org.apache.cxf.jaxrs.provider.MultipartProvider$MessageBodyWriterDataHandler.writeTo(MultipartProvider.java:457)

So, I'm trying to construct a multipart having several PDF files and I'm
wondering if the way I'm constructing the multipart is correct. Here is the
code:

File[] files = new File(".").listFiles(new FilenameFilter()
{
@Override
public boolean accept(File dir, String name)
{
return name.endsWith(".pdf");
}
});
List<Attachment> attachments = new LinkedList<Attachment>();
for (File file : files)
try (FileInputStream stream = new FileInputStream(file);)
{
ContentDisposition cd = new ContentDisposition("filename=" +
file.getName());
attachments.add(new Attachment(file.getName(),
MediaType.APPLICATION_OCTET_STREAM, stream));

And when I do:

webClient.post(new MultipartBody(attachments));

It raises this exception saying that input streams are closed. Do you see
any reason that streams be closed here ?

Many thanks in advance.

Kind regards,

Nicolas DUMINIL



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780629.html
Sent from the cxf-user mailing list archive at Nabble.com.
Sergey Beryozkin
2017-05-23 10:22:28 UTC
Permalink
Hi

Perhaps the target server closed the connection after processing the
first attachment ? I can not see any issues with the client code.

Sergey
Post by nicolasduminil
Hi,
Apache CXF 3.0.3 comes bundled with WebSphere 9.0.0.3 accordingly I cannot
replace the libraries. I could deploy another release of CXF with my WAR
but, in this case, it would conflict with the classes already deployed into
the app server. I could also modify the class-loading strategy such that to
use the classes bundled into the WAR rather then the ones provide by the app
server, but then I would fall into other issues. And anyway, wether this
works or not, at the end of the day I need to work with what is provided by
WebSphere, as there is no other option.
So, replacing CXF 3.0.3 by 3.0.13 wouldn't have any benefice, wether it
works or not.
org.apache.cxf.interceptor.Fault: No message body writer has been found for
multipart/form-data
Caused by: java.io.IOException: Stream Closed
at java.io.FileInputStream.available(Native Method)
at org.apache.cxf.helpers.IOUtils.copy(IOUtils.java:148)
at org.apache.cxf.helpers.IOUtils.copy(IOUtils.java:107)
at
org.apache.cxf.helpers.IOUtils.copyAndCloseInput(IOUtils.java:113)
at
org.apache.cxf.jaxrs.provider.BinaryDataProvider.copyInputToOutput(BinaryDataProvider.java:186)
at
org.apache.cxf.jaxrs.provider.BinaryDataProvider.writeTo(BinaryDataProvider.java:146)
at
org.apache.cxf.jaxrs.provider.MultipartProvider$MessageBodyWriterDataHandler.writeTo(MultipartProvider.java:457)
So, I'm trying to construct a multipart having several PDF files and I'm
wondering if the way I'm constructing the multipart is correct. Here is the
File[] files = new File(".").listFiles(new FilenameFilter()
{
@Override
public boolean accept(File dir, String name)
{
return name.endsWith(".pdf");
}
});
List<Attachment> attachments = new LinkedList<Attachment>();
for (File file : files)
try (FileInputStream stream = new FileInputStream(file);)
{
ContentDisposition cd = new ContentDisposition("filename=" +
file.getName());
attachments.add(new Attachment(file.getName(),
MediaType.APPLICATION_OCTET_STREAM, stream));
webClient.post(new MultipartBody(attachments));
It raises this exception saying that input streams are closed. Do you see
any reason that streams be closed here ?
Many thanks in advance.
Kind regards,
Nicolas DUMINIL
--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780629.html
Sent from the cxf-user mailing list archive at Nabble.com.
nicolasduminil
2017-05-23 12:06:19 UTC
Permalink
It doesn't go to the server, it's on the client side during the POST
somewhere during the POST operation.
Many thanks anyway for your help.
Kind regards,
Nicolas



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780635.html
Sent from the cxf-user mailing list archive at Nabble.com.
Sergey Beryozkin
2017-05-23 12:15:36 UTC
Permalink
Try downloading a Zip-ed source from
https://github.com/apache/cxf/tree/cxf-3.0.3

and put a breakpoint, for example, in MultipartProvider.writeTo...

Cheers, Sergey
You can download a zip
Post by nicolasduminil
It doesn't go to the server, it's on the client side during the POST
somewhere during the POST operation.
Many thanks anyway for your help.
Kind regards,
Nicolas
--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780635.html
Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/
nicolasduminil
2017-05-23 12:52:28 UTC
Permalink
Sergehei,

I feel like a dork. My InputStream was instantiated in a try-with-resource
statement while the POST was done outside it, meaning that the stream, which
was the resource, was closed, this being the purpose even of
try-with-resource. Doing things correctly, for example with a try ... catch,
works as expected, of course.

I'm really sorry for all this trouble.

Many thanks again, to you and Dennis, for your help.

Kind regards,
Nicolas



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780637.html
Sent from the cxf-user mailing list archive at Nabble.com.
James Carman
2017-05-23 12:55:35 UTC
Permalink
We've all been there! Glad to hear you got it figured out. Also glad this
is on the mailing list, so it might help someone else in the future.

On Tue, May 23, 2017 at 8:52 AM nicolasduminil <
Post by nicolasduminil
Sergehei,
I feel like a dork. My InputStream was instantiated in a try-with-resource
statement while the POST was done outside it, meaning that the stream, which
was the resource, was closed, this being the purpose even of
try-with-resource. Doing things correctly, for example with a try ... catch,
works as expected, of course.
I'm really sorry for all this trouble.
Many thanks again, to you and Dennis, for your help.
Kind regards,
Nicolas
--
http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780637.html
Sent from the cxf-user mailing list archive at Nabble.com.
Sergey Beryozkin
2017-05-23 13:07:02 UTC
Permalink
And I was the one who said that code was just fine :-)

Cheers, Sergey
Post by nicolasduminil
Sergehei,
I feel like a dork. My InputStream was instantiated in a try-with-resource
statement while the POST was done outside it, meaning that the stream, which
was the resource, was closed, this being the purpose even of
try-with-resource. Doing things correctly, for example with a try ... catch,
works as expected, of course.
I'm really sorry for all this trouble.
Many thanks again, to you and Dennis, for your help.
Kind regards,
Nicolas
--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780637.html
Sent from the cxf-user mailing list archive at Nabble.com.
Dennis Kieselhorst
2017-05-23 08:50:24 UTC
Permalink
Hi Nicolas,

sorry missed the other thread. Unfortunately I have no current Websphere installation to test this. Moreover as discussed in the other thread they are using a forked codebase, so it's hard to find out without knowing it.

Regards
Dennis
nicolasduminil
2017-05-23 10:13:20 UTC
Permalink
Hi Dennis,

Yes, I understand. Many thanks for your help.

Kind regards,

Nicolas



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-3-0-3-org-apache-cxf-interceptor-Fault-No-message-body-writer-has-been-found-for-class-org-apacha-tp5780611p5780630.html
Sent from the cxf-user mailing list archive at Nabble.com.
Loading...