java JAXRS 2.0如何从响应对象获取实体
我正在使用JAX-RS2.0和Dropwizard 0.8.0-rc1,但我真的不知道如何从javax.ws.rs.core.Response
对象中提取实体response.getEntity()
给了我{
我目前的测试代码如下:
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);
}
}
# 1 楼答案
你可以使用: