Example usage for org.apache.http.client.methods HttpEntityEnclosingRequestBase getClass

List of usage examples for org.apache.http.client.methods HttpEntityEnclosingRequestBase getClass

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpEntityEnclosingRequestBase getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.adobe.acs.commons.adobeio.service.impl.EndpointServiceImpl.java

private JsonObject processRequestWithBody(@NotNull final HttpEntityEnclosingRequestBase base,
        @NotNull final JsonObject payload, String[] headers) throws IOException {

    StopWatch stopWatch = new StopWatch();
    LOGGER.debug("STARTING STOPWATCH processRequestWithBody");
    stopWatch.start();/*from w  w  w .  j  a va  2  s . co  m*/

    base.setHeader(AUTHORIZATION, BEARER + integrationService.getAccessToken());
    base.setHeader(CACHE_CONTRL, NO_CACHE);
    base.setHeader(X_API_KEY, integrationService.getApiKey());
    base.setHeader(CONTENT_TYPE, CONTENT_TYPE_APPLICATION_JSON);
    if (headers == null || headers.length == 0) {
        addHeaders(base, specificServiceHeaders);
    } else {
        addHeaders(base, convertServiceSpecificHeaders(headers));
    }

    StringEntity input = new StringEntity(payload.toString());
    input.setContentType(CONTENT_TYPE_APPLICATION_JSON);

    if (!base.getClass().isInstance(HttpGet.class)) {
        base.setEntity(input);
    }

    LOGGER.debug("Process call. uri = {}. payload = {}", base.getURI().toString(), payload);

    try (CloseableHttpClient httpClient = helper.getHttpClient(integrationService.getTimeoutinMilliSeconds())) {
        CloseableHttpResponse response = httpClient.execute(base);
        final JsonObject result = responseAsJson(response);

        LOGGER.debug("STOPPING STOPWATCH processRequestWithBody");
        stopWatch.stop();
        LOGGER.debug("Stopwatch time processRequestWithBody: {}", stopWatch);
        stopWatch.reset();
        return result;
    }
}

From source file:org.fcrepo.apix.jena.impl.LdpContainerRegistry.java

@Override
public URI put(final WebResource resource, final boolean asBinary) {
    init.await();/*from   w w w  .j  a va  2 s . co  m*/
    HttpEntityEnclosingRequestBase request = null;

    if (resource.uri() == null || !resource.uri().isAbsolute()) {
        request = new HttpPost(containerId);
        final String name = slugText(resource);
        if (name != null) {
            request.addHeader("Slug", name);
        }

        if (asBinary) {
            request.addHeader("Content-Disposition",
                    String.format("attachment; filename=%s", name != null ? name : "file.bin"));
        }

    } else {
        request = new HttpPut(resource.uri());
        if (!asBinary) {
            request.addHeader("Prefer", "handling=lenient; received=\"minimal\"");
        }
    }

    if (resource.representation() != null) {
        request.setEntity(new InputStreamEntity(resource.representation()));
    }
    request.setHeader(HttpHeaders.CONTENT_TYPE, resource.contentType());

    try {
        return client.execute(request, (response -> {
            final int status = response.getStatusLine().getStatusCode();

            if (status == HttpStatus.SC_CREATED) {
                return URI.create(response.getFirstHeader(HttpHeaders.LOCATION).getValue());
            } else if (status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_OK) {
                return resource.uri();
            } else {
                throw new RuntimeException(String.format("Resource creation failed: %s; %s",
                        response.getStatusLine().toString(), EntityUtils.toString(response.getEntity())));
            }
        }));
    } catch (final Exception e) {
        throw new RuntimeException(String.format("Error executing %s request to %s",
                request.getClass().getSimpleName(), request.getURI().toString()), e);
    }

}