java - JAX-RS 2.0 - How to get entity from Response object -
i'm using jax-rs 2.0 dropwizard 0.8.0-rc1 , can't figure out how pull entity javax.ws.rs.core.response
object. response.getentity()
gives me bytearrayoutputstream
. can create 2 requests - 1 gives me headers , links , other gives me response entity, seems stupid, wasteful , unclear thing do. there way getting entity response object?
my current test code follows:
public class groupsresourcetest { public static string configuration_file = "src/test/resources/test-conf.yml"; @classrule public final static dropwizardapprule<bpmconsoleconfiguration> rule = new dropwizardapprule<>(bpmconsoleapplication.class, configuration_file); static client client; @beforeclass public static void initclient(){ client = new jerseyclientbuilder(rule.getenvironment()).build("client"); client.register(httpauthenticationfeature.basic(user.admin.login, user.admin.password)); } @test public void shouldgetgroups() { //when webtarget resource = target("/groups"); list<string> groups = resource.request().get(new generictype<>(list.class)); //first request response response = resource.request().get(); //second request link self = response.getlink("self"); //then assertthat(self.geturi().getpath()).isequalto("/groups"); assertthat(groups).contains(user.admin.login); } public webtarget target(string path){ string url = string.format("http://localhost:%d%s", rule.getlocalport(), path); return client.target(url); } }
you can use:
public abstract <t> t readentity(class<t> entitytype)
- read message entity input stream instance of specified java type using messagebodyreader supports mapping message entity stream onto requested type.
Comments
Post a Comment