当前位置: 首页>>代码示例>>Java>>正文


Java Response.hasEntity方法代码示例

本文整理汇总了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;
}
 
开发者ID:adr,项目名称:eadlsync,代码行数:22,代码来源:SeRepoConector.java

示例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();
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:19,代码来源:HttpBasedBinaryService.java

示例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.");
	}
 
开发者ID:Lambda-3,项目名称:Graphene,代码行数:27,代码来源:Coreference.java

示例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;
}
 
开发者ID:prestodb,项目名称:presto-manager,代码行数:28,代码来源:JsonResponseReader.java

示例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();
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:10,代码来源:SOAPRequestError.java

示例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;
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:28,代码来源:RestBaseClient.java

示例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;
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:31,代码来源:RestBaseClient.java

示例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();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:32,代码来源:Backup.java

示例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;
        }
    }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:44,代码来源:RestBaseClient.java


注:本文中的javax.ws.rs.core.Response.hasEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。