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; }
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; }
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; }
@Override public int getLength() { return delegate.getLength(); }
@Override public int getLength() { return rawResponse.getLength(); }
public int getLength() { return r.getLength(); }
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); }
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); }
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(); } }
/** * 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(); }
/** 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()); } }
if (response.getLength() < MAX_RESPONSE_BUFFER_BYTES) { isBuffered = response.bufferEntity();
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());
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()); } }
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))); }
@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)); }