I have written a service that uses Jersey. In the last class that returns a Response object, I have:
Stream<Revision> revisionss = dataSourceHandler.getRevisions( .... );
StreamingOutput stream = os -> objectHistoryWorker.revisionsTransfer(revisions, os);
return Response.ok(stream).build();
This gets a Stream of Revision objects, converts the stream into a StreamingOutput, and then sends it out in the Response.
I'm trying to write an integration test to test this, and I want to see what contents are actually inside of the Response. In other words, I want to know information such as
Revision objects existRevision object contain the correct informationThe issue I'm having is that it is an OutboundJaxrsResponse, and the readEntity() method is not supported for it.
It has methods that will return whether it passed or not (i.e. status code 200), but I can't seem to figure out a way to actually read the contents of the Response.
Is there a way to get that information?
(The expected response content will be in Json format)
The class org.glassfish.jersey.message.internal.OutboundJaxrsResponse does support getEntity().
How to get the response contents as a Java String. From this, I'm sure you can work out how to read it as Json or XML ....
private String entity( Response response ) throws WebApplicationException, IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamingOutput output = (StreamingOutput) response.getEntity();
output.write( baos );
return baos.toString( "UTF-8" );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With