本文整理汇总了Java中javax.ws.rs.core.Response.hasEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Response.hasEntity方法的具体用法?Java Response.hasEntity怎么用?Java Response.hasEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response
的用法示例。
在下文中一共展示了Response.hasEntity方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commit
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public static String commit(String message, List<SeItemWithContent> items, User user, CommitMode mode, String seRepoBaseUrl, String seRepoName) {
WebTarget api = ClientBuilder.newClient()
.target(seRepoBaseUrl)
.path("/repos/" + seRepoName + "/commits");
CreateCommit createCommit = createCommit(message, mode, user);
MultipartFormDataOutput multipart = createMultipart(createCommit, items);
Response response = api.request(MediaType.TEXT_PLAIN_TYPE)
.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
String commitId;
if (response.hasEntity()) {
commitId = response.readEntity(String.class);
} else {
commitId = "";
}
response.close();
LOG.debug("Committed {} items - {}", items.size(), commitId);
items.stream().map(se -> "Item " + se.getName() + " in " + se.getFolder() + " related to " + se.getRelations().stream().map(Relation::getTarget).collect(Collectors.joining(", "))).forEach(LOG::debug);
return commitId;
}
示例2: getContent
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public Optional<InputStream> getContent(final IRI identifier, final List<Range<Integer>> ranges) {
requireNonNull(identifier, NON_NULL_IDENTIFIER);
requireNonNull(ranges, "Byte ranges may not be null");
final Response res;
if (ranges.isEmpty()) {
res = httpClient.target(identifier.getIRIString()).request().get();
} else {
final StringBuilder builder = new StringBuilder();
ranges.forEach(r -> builder.append(r.getMinimum() + "-" + r.getMaximum()));
res = httpClient.target(identifier.getIRIString()).request().header("Range", "bytes=" + builder).get();
}
LOGGER.info("HTTP GET request to {} returned status {}", identifier, res.getStatus());
if (res.hasEntity()) {
return of(res.getEntity()).map(x -> (InputStream) x);
}
return empty();
}
示例3: testGet
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testGet() throws Exception {
logger.info("Registering Client Level Filters");
Client client = newClient();
client.register(new OtherClientResponseFilter());
WebTarget target = client.target(url + "myjaxrs/simple/");
target.register(new OtherClientRequestFilter());
WebTarget resourceTarget = target.path("/valuesget");
resourceTarget = resourceTarget.queryParam("OrderID", "111").queryParam("UserName", "Luke");
resourceTarget.register(new MyClientResponseFilter());
resourceTarget.register(new MyClientRequestFilter());
logger.info("Invoking REST Service: " + resourceTarget.getUri().toString());
Invocation invocation = resourceTarget.request().buildGet();
Response response = invocation.invoke();
String respContent = "";
if (response.hasEntity())
respContent = response.readEntity(String.class);
assertEquals("Response--> ", "111-Luke", respContent);
assertEquals("Content Type after changing in ClientResponseFilter: ", TEXT_HTML,
response.getHeaderString(CONTENT_TYPE_STRING));
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:27,代码来源:ComponentTestCase.java
示例4: sendRequest
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private InternalCoreferenceResponse sendRequest(WebTarget target, InternalCoreferenceRequest request) {
log.debug("Sending coreference request to {}", target.getUri().toString());
final Response response = target
.request(MediaType.APPLICATION_JSON_TYPE)
.accept(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE));
if (response.hasEntity()) {
if (response.getStatusInfo().getStatusCode() == Response.Status.OK.getStatusCode()) {
return response.readEntity(InternalCoreferenceResponse.class);
} else {
log.error(
"A request was sent, but the response code was '{}: {}'",
response.getStatusInfo().getStatusCode(),
response.getStatusInfo().getReasonPhrase());
}
} else {
log.error("The response has no entity.");
}
throw new RuntimeException("The response contained no content.");
}
示例5: read
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
* Convert the entity of the given response into a Java object.
* <p>
* If the response's entity is an object besides an {@link InputStream}, it
* will be returned as is. If the entity is an {@link InputStream}, it will
* be converted to a Java Object as if it were in JSON.
*
* @throws JsonParseException If the input stream was not in JSON format.
*/
public Object read(Response response)
throws IOException
{
if (!response.hasEntity()) {
return null;
}
Object rawEntity = response.getEntity();
Object entity;
if (rawEntity instanceof InputStream) {
InputStream entityInput = (InputStream) rawEntity;
entity = mapper.readValue(entityInput, Object.class);
}
else {
entity = rawEntity;
}
return entity;
}
示例6: SOAPRequestError
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public SOAPRequestError(Response response, BadRequestException e) {
super(e);
status = response.getStatus();
if (response.hasEntity()) {
entity = Optional.of(response.readEntity(String.class));
} else {
entity = Optional.empty();
}
}
示例7: getResource
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public <T> T getResource(String resourcePath, final Class<T> clazz, MultivaluedMap<String, String> params,
MultivaluedMap<String, String> headers) throws Exception {
Response response = null;
try {
final Invocation.Builder requestBuilder = getRequestBuilder(resourcePath, params, headers);
response = requestBuilder.async().get(new InvocationLogCallback())
.get(REQUEST_THREAD_TIMEOUT, TimeUnit.MILLISECONDS);
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status == Response.Status.OK) {
this.lastRequestHeaders = response.getHeaders();
if (response.hasEntity()) {
return response.readEntity(clazz);
}
return null;
} else {
throw new ClientResponseNotOkException();
}
} catch (Exception ex) {
RestClientException restClientException = createRestClientException("GET", this.webTarget.getUri() + "/"
+ resourcePath, null, response, ex);
log.debug("Error invoking getResources", restClientException);
throw restClientException;
}
}
示例8: postResource
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <I, O> O postResource(String resourcePath, Class<O> resClazz, final I input,
MultivaluedMap<String, String> params, MultivaluedMap<String, String> headers) throws Exception {
Response response = null;
try {
final Invocation.Builder requestBuilder = getRequestBuilder(resourcePath, params, headers);
response = requestBuilder.async().post(Entity.entity(input, this.mediaType),new InvocationLogCallback())
.get(REQUEST_THREAD_TIMEOUT, TimeUnit.MILLISECONDS);
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status == Response.Status.OK || status == Response.Status.CREATED) {
this.lastRequestHeaders = response.getHeaders();
if (response.hasEntity()) {
return response.readEntity(resClazz);
}
return (O) response;
} else if (status == Response.Status.NO_CONTENT) {
return null;
} else {
throw new ClientResponseNotOkException();
}
} catch (Exception ex) {
RestClientException restClientException = createRestClientException("POST", this.webTarget.getUri() + "/"
+ resourcePath, input, response, ex);
log.debug("Error invoking postResource", restClientException);
throw restClientException;
}
}
示例9: 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();
}
}
示例10: getResources
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public <T> List<T> getResources(String resourcePath, final Class<T> clazz) throws Exception {
ParameterizedType genericType = new ParameterizedType() {
@Override
public Type[] getActualTypeArguments() {
return new Type[] { clazz };
}
@Override
public Type getRawType() {
return List.class;
}
@Override
public Type getOwnerType() {
return List.class;
}
};
GenericType<List<T>> listOfClazzType = new GenericType<List<T>>(genericType) {};
Response response = null;
try {
final Invocation.Builder requestBuilder = getRequestBuilder(resourcePath);
response = requestBuilder.async().get(new InvocationLogCallback())
.get(REQUEST_THREAD_TIMEOUT, TimeUnit.MILLISECONDS);
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status == Response.Status.OK) {
if (response.hasEntity()) {
return response.readEntity(listOfClazzType);
}
return null;
} else {
throw new ClientResponseNotOkException();
}
} catch (Exception ex) {
RestClientException restClientException = createRestClientException("GET", this.webTarget.getUri() + "/"
+ resourcePath, null, response, ex);
log.debug("Error invoking getResources", restClientException);
throw restClientException;
}
}