javax.ws.rs.core.Response.getLength()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中javax.ws.rs.core.Response.getLength方法的一些代码示例,展示了Response.getLength的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getLength方法的具体详情如下:
包路径:javax.ws.rs.core.Response
类名称:Response
方法名:getLength

Response.getLength介绍

[英]Get Content-Length value.
[中]获取内容长度值。

代码示例

代码示例来源:origin: apache/nifi

protected NodeResponse replicateRequest(final PreparedRequest request, final NodeIdentifier nodeId, final URI uri, final String requestId,
    final StandardAsyncClusterResponse clusterResponse) throws IOException {
  final Response response;
  final long startNanos = System.nanoTime();
  logger.debug("Replicating request to {} {}, request ID = {}, headers = {}", request.getMethod(), uri, requestId, request.getHeaders());
  // invoke the request
  response = httpClient.replicate(request, uri.toString());
  final long nanos = System.nanoTime() - startNanos;
  clusterResponse.addTiming("Perform HTTP Request", nodeId.toString(), nanos);
  final NodeResponse nodeResponse = new NodeResponse(nodeId, request.getMethod(), uri, response, System.nanoTime() - startNanos, requestId);
  if (nodeResponse.is2xx()) {
    final int length = nodeResponse.getClientResponse().getLength();
    if (length > 0) {
      final boolean canBufferResponse = clusterResponse.requestBuffer(length);
      if (canBufferResponse) {
        nodeResponse.bufferResponse();
      }
    }
  }
  return nodeResponse;
}

代码示例来源:origin: hugegraph/hugegraph

private Response doGetRequest(String location, String auth, String query) {
  String url = String.format("%s?%s", location, query);
  Response r = this.client.target(url)
              .request()
              .header(HttpHeaders.AUTHORIZATION, auth)
              .accept(MediaType.APPLICATION_JSON)
              .acceptEncoding(CompressInterceptor.GZIP)
              .get();
  if (r.getMediaType() != null) {
    // Append charset
    assert MediaType.APPLICATION_JSON_TYPE.equals(r.getMediaType());
    r.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE,
                 r.getMediaType().withCharset(CHARSET));
  }
  gremlinInputHistogram.update(query.length());
  gremlinOutputHistogram.update(r.getLength());
  return r;
}

代码示例来源:origin: hugegraph/hugegraph

private Response doPostRequest(String location, String auth, String req) {
  Entity<?> body = Entity.entity(req, MediaType.APPLICATION_JSON);
  Response r = this.client.target(location)
              .request()
              .header(HttpHeaders.AUTHORIZATION, auth)
              .accept(MediaType.APPLICATION_JSON)
              .acceptEncoding(CompressInterceptor.GZIP)
              .post(body);
  if (r.getMediaType() != null) {
    // Append charset
    assert MediaType.APPLICATION_JSON_TYPE.equals(r.getMediaType());
    r.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE,
                 r.getMediaType().withCharset(CHARSET));
  }
  gremlinInputHistogram.update(req.length());
  gremlinOutputHistogram.update(r.getLength());
  return r;
}

代码示例来源:origin: SAP/cloud-s4-sdk-examples

@Override
public int getLength()
{
  return delegate.getLength();
}

代码示例来源:origin: com.cerner.beadledom/beadledom-resteasy-genericresponse

@Override
public int getLength() {
 return rawResponse.getLength();
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

public int getLength() {
  return r.getLength();
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-client

protected <T> T readBody(Response r, Message outMessage, Class<T> cls,
             Type type, Annotation[] anns) {
  if (cls == Response.class) {
    return cls.cast(r);
  }
  int status = r.getStatus();
  if ((status < 200 || status == 204) && r.getLength() <= 0 || (status >= 300 && status != 304)) {
    return null;
  }
  return ((ResponseImpl)r).doReadEntity(cls, type, anns);
}

代码示例来源:origin: apache/cxf

protected <T> T readBody(Response r, Message outMessage, Class<T> cls,
             Type type, Annotation[] anns) {
  if (cls == Response.class) {
    return cls.cast(r);
  }
  int status = r.getStatus();
  if ((status < 200 || status == 204) && r.getLength() <= 0 || (status >= 300 && status != 304)) {
    return null;
  }
  return ((ResponseImpl)r).doReadEntity(cls, type, anns);
}

代码示例来源:origin: com.axway.ats.framework/ats-actionlibrary

private void checkResponseBodyStatus() {
  /* prevents java.lang.IllegalStateException: Entity input stream has already been closed. 
   * if the file size is less than MAX_RESPONSE_SIZE
  */
  if (response.getLength() < MAX_RESPONSE_SIZE) {
    response.bufferEntity();
  }
}

代码示例来源:origin: com.axway.ats.framework/ats-actionlibrary

/**
 * Returns Content-Length as integer if present. In other cases returns -1.
 * @return response's content length in bytes
 */
@PublicAtsApi
public int getContentLength() {
  return response.getLength();
}

代码示例来源:origin: de.sfuhrm/radiobrowser4j

/** Log the response.
 * @param response the response to log the status
 *                 code of.
 * */
private static void logResponseStatus(final Response response) {
  if (response.getStatus() != HttpURLConnection.HTTP_OK) {
    log.warn("Non HTTP OK/200 status: status={}, reason={}",
        response.getStatus(),
        response.getStatusInfo().getReasonPhrase()
    );
  } else {
    log.debug("HTTP response status={}, reason={}, length={}",
        response.getStatus(),
        response.getStatusInfo().getReasonPhrase(),
        response.getLength());
  }
}

代码示例来源:origin: oracle/oci-java-sdk

if (response.getLength() < MAX_RESPONSE_BUFFER_BYTES) {
  isBuffered = response.bufferEntity();

代码示例来源:origin: zero11it/acme-client

if (newCertificateResponse.getLength() > 0){
  return extractCertificate(domains, (InputStream) newCertificateResponse.getEntity());
    .get();
if (certificateResponse.getStatus() == Status.CREATED.getStatusCode()){
  if (certificateResponse.getLength() > 0){
    return extractCertificate(domains, (InputStream) certificateResponse.getEntity());

代码示例来源:origin: bouncestorage/swiftproxy

private String emulateCopyBlob(BlobStore blobStore, Response resp, BlobMetadata meta,
                String destContainer, String destObject, CopyOptions options) {
  Response.StatusType statusInfo = resp.getStatusInfo();
  if (statusInfo.equals(Response.Status.OK)) {
    ContentMetadata contentMetadata = meta.getContentMetadata();
    Map<String, String> newMetadata = new HashMap<>();
    newMetadata.putAll(meta.getUserMetadata());
    newMetadata.putAll(options.userMetadata());
    RESERVED_METADATA.forEach(s -> newMetadata.remove(s));
    Blob blob = blobStore.blobBuilder(destObject)
        .userMetadata(newMetadata)
        .payload(new InputStreamPayload((InputStream) resp.getEntity()))
        .contentLength(resp.getLength())
        .contentDisposition(contentMetadata.getContentDisposition())
        .contentEncoding(contentMetadata.getContentEncoding())
        .contentType(contentMetadata.getContentType())
        .contentLanguage(contentMetadata.getContentLanguage())
        .build();
    return blobStore.putBlob(destContainer, blob);
  } else {
    throw new ClientErrorException(statusInfo.getReasonPhrase(), statusInfo.getStatusCode());
  }
}

代码示例来源:origin: trellis-ldp/trellis

private Stream<Executable> checkBinaryDescription(final Response res) {
  return Stream.of(
      () -> assertEquals(OK, res.getStatusInfo(), "Incorrect response code!"),
      () -> assertEquals(-1, res.getLength(), "Incorrect response size!"),
      () -> assertEquals(from(time), res.getLastModified(), "Incorrect modified date!"),
      () -> assertTrue(res.getMediaType().isCompatible(TEXT_TURTLE_TYPE), "Incompatible content-type!"),
      () -> assertTrue(res.getLinks().stream()
          .anyMatch(link -> link.getRel().equals("describes") &&
            !link.getUri().toString().endsWith("?ext=description")), "MIssing rel=describes header!"),
      () -> assertTrue(res.getLinks().stream()
          .anyMatch(link -> link.getRel().equals("canonical") &&
            link.getUri().toString().endsWith("?ext=description")), "Missing rel=canonical header!"),
      () -> assertAll("Check LDP type link headers", checkLdpType(res, LDP.RDFSource)));
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetBinary() throws IOException {
  when(mockResource.getBinaryMetadata()).thenReturn(of(testBinary));
  when(mockResource.getInteractionModel()).thenReturn(LDP.NonRDFSource);
  when(mockTrellisRequest.getAcceptableMediaTypes()).thenReturn(singletonList(WILDCARD_TYPE));
  final GetHandler handler = new GetHandler(mockTrellisRequest, mockBundler, false, true, true, null, baseUrl);
  final Response res = handler.getRepresentation(handler.standardHeaders(handler.initialize(mockResource)))
    .toCompletableFuture().join().build();
  assertEquals(OK, res.getStatusInfo(), "Incorrect response code!");
  assertEquals(-1, res.getLength(), "Incorrect response length!");
  assertEquals(from(time), res.getLastModified(), "Incorrect content-type header!");
  assertTrue(res.getMediaType().isCompatible(TEXT_PLAIN_TYPE), "Incorrect content-type header!");
  assertTrue(res.getLinks().stream()
      .anyMatch(link -> link.getRel().equals("describedby") &&
        link.getUri().toString().endsWith("?ext=description")), "Missing rel=describedby header!");
  assertTrue(res.getLinks().stream()
      .anyMatch(link -> link.getRel().equals("canonical") &&
        !link.getUri().toString().endsWith("?ext=description")), "Missing rel=canonical header!");
  assertAll("Check LDP type link headers", checkLdpType(res, LDP.NonRDFSource));
}

相关文章