本文整理汇总了Java中javax.ws.rs.core.Response.bufferEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Response.bufferEntity方法的具体用法?Java Response.bufferEntity怎么用?Java Response.bufferEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response
的用法示例。
在下文中一共展示了Response.bufferEntity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expect
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
protected Response expect(ResponseExpectation expectation, Invocation i) {
try (Timer.TimedBlock b = Timer.time("request")) {
Response response = i.invoke();
response.bufferEntity();
try {
expectation.validate(response);
} catch (AssertionError e) {
// this will show the body of the response in the error message
// if an error occurred it will show the server side error.
// response.toString() does not show the content
String body = response.readEntity(String.class);
throw new AssertionError(String.format("%s\n%s\n%s", e.getMessage(), response.toString(), body), e);
}
return response;
}
}
示例2: validate
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public static void validate(Response response, int status, String msg) {
assertNotNull("No response was produced", response);
response.bufferEntity(); //this is needed in case validate is called more than once
JSONObject jsonObject = new JSONObject(response.readEntity(String.class));
assertEquals(status, response.getStatus());
assertFalse("Response does not have the code property", jsonObject.isNull("code"));
assertFalse("Response does not have the message property", jsonObject.isNull("message"));
assertEquals("Response code is not equal", status, jsonObject.getInt("code"));
assertEquals("Response message is not equal",msg, jsonObject.getString("message"));
}
示例3: readEntity
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private static <T> T readEntity(Class<T> entityClazz, Invocation invocation) throws IOException {
Response response = invocation.invoke();
try {
response.bufferEntity();
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
if (response.hasEntity()) {
// Try to parse error message as generic error message JSON type
try {
GenericErrorMessage message = response.readEntity(GenericErrorMessage.class);
throw new IOException(format("Status %d (%s): %s (more info: %s)",
response.getStatus(),
response.getStatusInfo().getReasonPhrase(),
message.getErrorMessage(),
message.getMoreInfo()));
} catch (ProcessingException e) {
// Fallback to String if unparsing is unsuccessful
throw new IOException(format("Status %d (%s)",
response.getStatus(),
response.getStatusInfo().getReasonPhrase(),
response.readEntity(String.class)));
}
}
throw new IOException(format("Status %d (%s)",
response.getStatus(),
response.getStatusInfo().getReasonPhrase()));
}
return response.readEntity(entityClazz);
} finally {
response.close();
}
}
示例4: readEntity
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private <T> T readEntity(Response response, GenericType<T> c) {
response.bufferEntity();
try {
return response.readEntity(c);
} catch (ProcessingException e) {
String body = response.readEntity(String.class);
throw new RuntimeException("Error deserializing entity with " + c + " : " + body, e);
}
}