title: Processing exception while streaming http response object using Data Buffer
body: <p>Getting error &quot;Unable to find a MessageBodyReader&quot; while writing the response to a file using DataBufferUtils.</p>
  <p>My code</p>
  <pre><code>
  public class Downloader {
      public static void main(String[] args) {
          Client targetClient = ClientBuilder.newClient();
  
          WebTarget target = targetClient.target(&quot;https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-zip-file.zip&quot;);
  
          Flux&lt;DataBuffer&gt; dataBufferFlux = (Flux&lt;DataBuffer&gt;) target
                  .request()
                  .rx(FluxRxInvoker.class).get(DataBuffer.class);
  
          Path path = Paths.get(&quot;file.txt&quot;);
  
          DataBufferUtils.write(dataBufferFlux, path, StandardOpenOption.CREATE).block();
      }
  }
  </code></pre>
  <p>Error stack trace</p>
  <pre><code>
  javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/zip and type class org.jboss.resteasy.plugins.providers.sse.SseEventInputImpl
          at org.jboss.resteasy.core.interception.jaxrs.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:47)
          at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:133)
          at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:75)
          at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:217)
          at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:90)
          at org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:262)
          at org.jboss.resteasy.plugins.providers.sse.client.SseEventSourceImpl$EventHandler.run(SseEventSourceImpl.java:338)
          at org.jboss.resteasy.plugins.providers.sse.client.SseEventSourceScheduler$1.run(SseEventSourceScheduler.java:92)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
          at java.lang.Thread.run(Thread.java:748)
  Exception in thread &quot;main&quot; javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/zip and type class org.jboss.resteasy.plugins.providers.sse.SseEventInputImpl
          at org.jboss.resteasy.core.interception.jaxrs.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:47)
          at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:133)
          at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:75)
          at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:217)
          at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:90)
          at org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:262)
          at org.jboss.resteasy.plugins.providers.sse.client.SseEventSourceImpl$EventHandler.run(SseEventSourceImpl.java:338)
          at org.jboss.resteasy.plugins.providers.sse.client.SseEventSourceScheduler$1.run(SseEventSourceScheduler.java:92)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
          at java.lang.Thread.run(Thread.java:748)
          Suppressed: java.lang.Exception: #block terminated with an error
                  at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:93)
                  at reactor.core.publisher.Mono.block(Mono.java:1663)
                  at Downloader.main(Downloader.java:32)
  
  
  </code></pre>
  <p>Dependencies</p>
  <pre><code>
  implementation(&quot;org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_2.1_spec:1.0.3.Final&quot;) 
  
  implementation(&quot;org.jboss.resteasy:resteasy-reactor:4.6.0.Final&quot;) 
  
  implementation(&quot;org.jboss.resteasy:resteasy-jackson2-provider:3.6.2.Final&quot;) 
  
  implementation(&quot;org.springframework.boot:spring-boot-starter-webflux:2.7.1&quot;)
  
  </code></pre>
  <p>Thins I have already tried :</p>
  <pre><code>I have added jackson2 provider as suggested but that didn't work for me.
  
  I also tried registering jackson provider explicitly but that too didn't work for me.
  
   ResteasyProviderFactory instance= ResteasyProviderFactory.getInstance();
   RegisterBuiltin.register(instance);
   instance.registerProvider(ResteasyJackson2Provider.class);
  
  </code></pre>
  <p>I have referred <a href="https://docs.spring.io/spring-framework/docs/5.2.4.RELEASE/spring-framework-reference/web-reactive.html#webflux-codecs-streaming" rel="nofollow noreferrer">Spring Streaming doc</a> for the understanding the concept. I am very new to this.</p>
  <p>Any ideas what is causing this issue of unable to find <strong>MessageBodyReader</strong> and how can we fix it?</p>
  <p>Edit:</p>
  <p>Used custom MessageBodyReader. But now that returns me below error. Not sure how to fix this as I am downloading a file.</p>
  <pre><code>@Consumes(&quot;application/zip&quot;)
  public class CustomMessageBodyReader
          implements MessageBodyReader&lt;SseEventInputImpl&gt; {
  
      @Override
      public boolean isReadable(Class&lt;?&gt; type, Type genericType,
                                Annotation[] annotations, MediaType mediaType) {
          return type == SseEventInputImpl.class;
      }
  
      @Override
      public SseEventInputImpl readFrom(Class&lt;SseEventInputImpl&gt; type,
                                 Type genericType,
                                 Annotation[] annotations, MediaType mediaType,
                                 MultivaluedMap&lt;String, String&gt; httpHeaders,
                                 InputStream entityStream)
              throws IOException, WebApplicationException {
  
          try {
              JAXBContext jaxbContext = JAXBContext.newInstance(SseEventInputImpl.class);
              SseEventInputImpl myBean = (SseEventInputImpl) jaxbContext.createUnmarshaller()
                      .unmarshal(entityStream);
              return myBean;
          } catch (JAXBException jaxbException) {
              throw new ProcessingException(&quot;Error deserializing a SseEventInputImpl.&quot;,
                      jaxbException);
          }
      }
  }
  </code></pre>
  <p>Error with custom MessageBodyReader</p>
  <pre><code>javax.ws.rs.ProcessingException: Error deserializing a SseEventInputImpl.
          at CustomMessageBodyReader.readFrom(CustomMessageBodyReader.java:41)
          at CustomMessageBodyReader.readFrom(CustomMessageBodyReader.java:17)
          at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:101)
          at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:80)
          at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:217)
          at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:90)
          at org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:262)
          at org.jboss.resteasy.plugins.providers.sse.client.SseEventSourceImpl$EventHandler.run(SseEventSourceImpl.java:338)
          at org.jboss.resteasy.plugins.providers.sse.client.SseEventSourceScheduler$1.run(SseEventSourceScheduler.java:92)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
          at java.lang.Thread.run(Thread.java:748)
  Caused by: javax.xml.bind.UnmarshalException: null
          at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:335)
          at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:563)
          at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:249)
          at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:214)
          at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
          at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:204)
          at CustomMessageBodyReader.readFrom(CustomMessageBodyReader.java:38)
          ... 15 common frames omitted
  Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
          at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
          at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
          at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
          at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
          at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)
          at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:994)
          at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
          at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
          at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
          at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
          at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
          at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
          at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
          at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
          at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:243)
          ... 19 common frames omitted
  
  </code></pre>
  <p>You can try it out using <a href="https://github.com/sunny-shaw/WebClient-API-Playground/blob/download-file/src/main/java/Downloader.java" rel="nofollow noreferrer">Project GitHub link</a> for understanding the issue better if interested.</p>