简体   繁体   中英

No MessageBodyWriter for Single

I'm trying to use resteasy-rxjava2 to provide an XML document using jaxb, within a vertx application (using a non-vertx legacy library we have). But I get:

Could not find MessageBodyWriter for response object of type:
org.jboss.resteasy.rxjava2.propagation.ContextPropagatorOnSingleAssemblyAction$ContextPropagatorSingle of media type:
application/xml;charset=UTF-8

From what I can tell, this comes down to the difference between a MessageBodyWriter and the AsyncResponseProvider that is in the resteasy-rxjava2 dependency for a Single ( SingleProvider ).

I have the following resteasy service definition

  @GET
  @Path(FdsnwsPaths.QUERY)
  @Produces(MediaType.APPLICATION_XML)
  @Stream
  // CHECKSTYLE:OFF too many parameters
  public Response getQuery(...)

How do I get resteasy to properly serve the data asynchrously, using the SingleProvider or otherwise.

The @Get method must return the Single explicitly or it doesn't work. (Can't use Response or Object ). In my case, the Single contains the jaxb xml root element.

  @GET
  @Path(FdsnwsPaths.QUERY)
  @Produces(MediaType.APPLICATION_XML)
  @Stream
  public Single<FDSNStationXML> getQuery(...)

Then, to make things more complicated, in order to handle specific exception types and map them to specific response status codes, I have to create a custom ExceptionMapper which creates the Response object I used to be able to create directly in the method. (in resteasy-vertx, I found no documentation on how to do this, but in my case, I am creating my own VertxRestEasyDeployment object so I can register the class of the ExceptionMapper(s) like this:

VertxResteasyDeployment deployment = new VertxResteasyDeployment();
deployment.getActualProviderClasses().addAll(providerClasses);

For reference, this is all being done with:

  • RestEasy 5.0.3.Final (including resteasy-rxjava2)
  • RxJava 2.2.20
  • Vertx 3.9.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM