Search in sources :

Example 61 with Headers

use of com.amazonaws.services.s3.Headers in project autorest.java by Azure.

the class HeaderOperationsTests method responseExistingKey.

@Test
public void responseExistingKey() throws Exception {
    lock = new CountDownLatch(1);
    client.headers().responseExistingKeyWithServiceResponseAsync().subscribe(new Action1<ServiceResponseWithHeaders<Void, HeaderResponseExistingKeyHeaders>>() {

        @Override
        public void call(ServiceResponseWithHeaders<Void, HeaderResponseExistingKeyHeaders> response) {
            Headers headers = response.response().headers();
            if (headers.get("User-Agent") != null) {
                Assert.assertEquals("overwrite", headers.get("User-Agent"));
                lock.countDown();
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            fail();
        }
    });
    Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS));
}
Also used : HeaderResponseDatetimeHeaders(fixtures.header.models.HeaderResponseDatetimeHeaders) HeaderResponseEnumHeaders(fixtures.header.models.HeaderResponseEnumHeaders) HeaderResponseLongHeaders(fixtures.header.models.HeaderResponseLongHeaders) HeaderResponseProtectedKeyHeaders(fixtures.header.models.HeaderResponseProtectedKeyHeaders) Headers(okhttp3.Headers) HeaderResponseDurationHeaders(fixtures.header.models.HeaderResponseDurationHeaders) HeaderResponseDatetimeRfc1123Headers(fixtures.header.models.HeaderResponseDatetimeRfc1123Headers) ServiceResponseWithHeaders(com.microsoft.rest.ServiceResponseWithHeaders) HeaderResponseDateHeaders(fixtures.header.models.HeaderResponseDateHeaders) HeaderResponseByteHeaders(fixtures.header.models.HeaderResponseByteHeaders) HeaderResponseDoubleHeaders(fixtures.header.models.HeaderResponseDoubleHeaders) HeaderResponseBoolHeaders(fixtures.header.models.HeaderResponseBoolHeaders) HeaderResponseStringHeaders(fixtures.header.models.HeaderResponseStringHeaders) HeaderResponseExistingKeyHeaders(fixtures.header.models.HeaderResponseExistingKeyHeaders) HeaderResponseFloatHeaders(fixtures.header.models.HeaderResponseFloatHeaders) HeaderResponseIntegerHeaders(fixtures.header.models.HeaderResponseIntegerHeaders) CountDownLatch(java.util.concurrent.CountDownLatch) ServiceResponseWithHeaders(com.microsoft.rest.ServiceResponseWithHeaders) HeaderResponseExistingKeyHeaders(fixtures.header.models.HeaderResponseExistingKeyHeaders) Test(org.junit.Test)

Example 62 with Headers

use of com.amazonaws.services.s3.Headers in project autorest.java by Azure.

the class HeaderOperationsTests method responseEnum.

@Test
public void responseEnum() throws Exception {
    lock = new CountDownLatch(1);
    client.headers().responseEnumWithServiceResponseAsync("valid").subscribe(new Action1<ServiceResponseWithHeaders<Void, HeaderResponseEnumHeaders>>() {

        @Override
        public void call(ServiceResponseWithHeaders<Void, HeaderResponseEnumHeaders> response) {
            Headers headers = response.response().headers();
            if (headers.get("value") != null) {
                Assert.assertEquals("GREY", headers.get("value"));
                lock.countDown();
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            fail();
        }
    });
    Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS));
    lock = new CountDownLatch(1);
    client.headers().responseEnumWithServiceResponseAsync("null").subscribe(new Action1<ServiceResponseWithHeaders<Void, HeaderResponseEnumHeaders>>() {

        @Override
        public void call(ServiceResponseWithHeaders<Void, HeaderResponseEnumHeaders> response) {
            Headers headers = response.response().headers();
            if (headers.get("value") != null) {
                Assert.assertEquals("", headers.get("value"));
                lock.countDown();
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            fail();
        }
    });
    Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS));
}
Also used : HeaderResponseEnumHeaders(fixtures.header.models.HeaderResponseEnumHeaders) HeaderResponseDatetimeHeaders(fixtures.header.models.HeaderResponseDatetimeHeaders) HeaderResponseEnumHeaders(fixtures.header.models.HeaderResponseEnumHeaders) HeaderResponseLongHeaders(fixtures.header.models.HeaderResponseLongHeaders) HeaderResponseProtectedKeyHeaders(fixtures.header.models.HeaderResponseProtectedKeyHeaders) Headers(okhttp3.Headers) HeaderResponseDurationHeaders(fixtures.header.models.HeaderResponseDurationHeaders) HeaderResponseDatetimeRfc1123Headers(fixtures.header.models.HeaderResponseDatetimeRfc1123Headers) ServiceResponseWithHeaders(com.microsoft.rest.ServiceResponseWithHeaders) HeaderResponseDateHeaders(fixtures.header.models.HeaderResponseDateHeaders) HeaderResponseByteHeaders(fixtures.header.models.HeaderResponseByteHeaders) HeaderResponseDoubleHeaders(fixtures.header.models.HeaderResponseDoubleHeaders) HeaderResponseBoolHeaders(fixtures.header.models.HeaderResponseBoolHeaders) HeaderResponseStringHeaders(fixtures.header.models.HeaderResponseStringHeaders) HeaderResponseExistingKeyHeaders(fixtures.header.models.HeaderResponseExistingKeyHeaders) HeaderResponseFloatHeaders(fixtures.header.models.HeaderResponseFloatHeaders) HeaderResponseIntegerHeaders(fixtures.header.models.HeaderResponseIntegerHeaders) CountDownLatch(java.util.concurrent.CountDownLatch) ServiceResponseWithHeaders(com.microsoft.rest.ServiceResponseWithHeaders) Test(org.junit.Test)

Example 63 with Headers

use of com.amazonaws.services.s3.Headers in project autorest.java by Azure.

the class HeaderOperationsTests method responseDuration.

@Test
public void responseDuration() throws Exception {
    lock = new CountDownLatch(1);
    client.headers().responseDurationWithServiceResponseAsync("valid").subscribe(new Action1<ServiceResponseWithHeaders<Void, HeaderResponseDurationHeaders>>() {

        @Override
        public void call(ServiceResponseWithHeaders<Void, HeaderResponseDurationHeaders> response) {
            Headers headers = response.response().headers();
            if (headers.get("value") != null) {
                Assert.assertEquals("P123DT22H14M12.011S", headers.get("value"));
                lock.countDown();
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            fail();
        }
    });
    Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS));
}
Also used : HeaderResponseDatetimeHeaders(fixtures.header.models.HeaderResponseDatetimeHeaders) HeaderResponseEnumHeaders(fixtures.header.models.HeaderResponseEnumHeaders) HeaderResponseLongHeaders(fixtures.header.models.HeaderResponseLongHeaders) HeaderResponseProtectedKeyHeaders(fixtures.header.models.HeaderResponseProtectedKeyHeaders) Headers(okhttp3.Headers) HeaderResponseDurationHeaders(fixtures.header.models.HeaderResponseDurationHeaders) HeaderResponseDatetimeRfc1123Headers(fixtures.header.models.HeaderResponseDatetimeRfc1123Headers) ServiceResponseWithHeaders(com.microsoft.rest.ServiceResponseWithHeaders) HeaderResponseDateHeaders(fixtures.header.models.HeaderResponseDateHeaders) HeaderResponseByteHeaders(fixtures.header.models.HeaderResponseByteHeaders) HeaderResponseDoubleHeaders(fixtures.header.models.HeaderResponseDoubleHeaders) HeaderResponseBoolHeaders(fixtures.header.models.HeaderResponseBoolHeaders) HeaderResponseStringHeaders(fixtures.header.models.HeaderResponseStringHeaders) HeaderResponseExistingKeyHeaders(fixtures.header.models.HeaderResponseExistingKeyHeaders) HeaderResponseFloatHeaders(fixtures.header.models.HeaderResponseFloatHeaders) HeaderResponseIntegerHeaders(fixtures.header.models.HeaderResponseIntegerHeaders) HeaderResponseDurationHeaders(fixtures.header.models.HeaderResponseDurationHeaders) CountDownLatch(java.util.concurrent.CountDownLatch) ServiceResponseWithHeaders(com.microsoft.rest.ServiceResponseWithHeaders) Test(org.junit.Test)

Example 64 with Headers

use of com.amazonaws.services.s3.Headers in project ttdj by soonphe.

the class HttpLoggingInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Level level = this.level;
    Request request = chain.request();
    if (level == Level.NONE) {
        return chain.proceed(request);
    }
    boolean logBody = level == Level.BODY;
    boolean logHeaders = logBody || level == Level.HEADERS;
    RequestBody requestBody = request.body();
    boolean hasRequestBody = requestBody != null;
    Connection connection = chain.connection();
    Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
    String requestStartMessage = "--> " + request.method() + ' ' + request.url() + ' ' + protocol(protocol);
    if (!logHeaders && hasRequestBody) {
        requestStartMessage += " (" + requestBody.contentLength() + "-byte body)";
    }
    logger.log(requestStartMessage);
    if (logHeaders) {
        if (hasRequestBody) {
            // them to be included (when available) so there values are known.
            if (requestBody.contentType() != null) {
                logger.log("Content-Type: " + requestBody.contentType());
            }
            if (requestBody.contentLength() != -1) {
                logger.log("Content-Length: " + requestBody.contentLength());
            }
        }
        Headers headers = request.headers();
        for (int i = 0, count = headers.size(); i < count; i++) {
            String name = headers.name(i);
            // Skip headers from the request body as they are explicitly logged above.
            if (!"Content-Type".equalsIgnoreCase(name) && !"Content-Length".equalsIgnoreCase(name)) {
                logger.log(name + ": " + headers.value(i));
            }
        }
        if (!logBody || !hasRequestBody) {
            logger.log("--> END " + request.method());
        } else if (bodyEncoded(request.headers())) {
            logger.log("--> END " + request.method() + " (encoded body omitted)");
        } else {
            Buffer buffer = new Buffer();
            requestBody.writeTo(buffer);
            Charset charset = UTF8;
            MediaType contentType = requestBody.contentType();
            if (contentType != null) {
                charset = contentType.charset(UTF8);
            }
            logger.log("");
            logger.log(buffer.readString(charset));
            logger.log("--> END " + request.method() + " (" + requestBody.contentLength() + "-byte body)");
        }
    }
    long startNs = System.nanoTime();
    Response response = chain.proceed(request);
    long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
    ResponseBody responseBody = response.body();
    long contentLength = responseBody.contentLength();
    String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length";
    logger.log("<-- " + response.code() + ' ' + response.message() + ' ' + response.request().url() + " (" + tookMs + "ms" + (!logHeaders ? ", " + bodySize + " body" : "") + ')');
    if (logHeaders) {
        Headers headers = response.headers();
        for (int i = 0, count = headers.size(); i < count; i++) {
            logger.log(headers.name(i) + ": " + headers.value(i));
        }
        if (!logBody || !HttpHeaders.hasBody(response)) {
            logger.log("<-- END HTTP");
        } else if (bodyEncoded(response.headers())) {
            logger.log("<-- END HTTP (encoded body omitted)");
        } else {
            BufferedSource source = responseBody.source();
            // Buffer the entire body.
            source.request(Long.MAX_VALUE);
            Buffer buffer = source.buffer();
            Charset charset = UTF8;
            MediaType contentType = responseBody.contentType();
            if (contentType != null) {
                charset = contentType.charset(UTF8);
            }
            if (contentLength != 0) {
                logger.log("");
                logger.log(buffer.clone().readString(charset));
            }
            logger.log("<-- END HTTP (" + buffer.size() + "-byte body)");
        }
    }
    return response;
}
Also used : Buffer(okio.Buffer) HttpHeaders(okhttp3.internal.http.HttpHeaders) Headers(okhttp3.Headers) Request(okhttp3.Request) Connection(okhttp3.Connection) Charset(java.nio.charset.Charset) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) MediaType(okhttp3.MediaType) Protocol(okhttp3.Protocol) RequestBody(okhttp3.RequestBody) BufferedSource(okio.BufferedSource)

Example 65 with Headers

use of com.amazonaws.services.s3.Headers in project herd by FINRAOS.

the class SampleDataJmsMessageListener method processMessage.

/**
 * Processes a JMS message.
 *
 * @param payload the message payload
 * @param allHeaders the JMS headers
 */
@JmsListener(id = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, containerFactory = "jmsListenerContainerFactory", destination = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE)
public void processMessage(String payload, @Headers Map<Object, Object> allHeaders) {
    LOGGER.info("Message received from the JMS queue. jmsQueueName=\"{}\" jmsMessageHeaders=\"{}\" jmsMessagePayload={}", HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, allHeaders, payload);
    try {
        // Process messages coming from S3 bucket.
        S3EventNotification s3EventNotification = S3EventNotification.parseJson(payload);
        String objectKey = URLDecoder.decode(s3EventNotification.getRecords().get(0).getS3().getObject().getKey(), CharEncoding.UTF_8);
        long fileSize = s3EventNotification.getRecords().get(0).getS3().getObject().getSizeAsLong();
        // parse the objectKey, it should be in the format of namespace/businessObjectDefinitionName/fileName
        String[] objectKeyArrays = objectKey.split("/");
        Assert.isTrue(objectKeyArrays.length == 3, String.format("S3 notification message %s is not in expected format", objectKey));
        String namespace = objectKeyArrays[0];
        String businessObjectDefinitionName = objectKeyArrays[1];
        String fileName = objectKeyArrays[2];
        String path = namespace + "/" + businessObjectDefinitionName + "/";
        BusinessObjectDefinitionSampleFileUpdateDto businessObjectDefinitionSampleFileUpdateDto = new BusinessObjectDefinitionSampleFileUpdateDto(path, fileName, fileSize);
        String convertedNamespaece = convertS3KeyFormat(namespace);
        String convertedBusinessObjectDefinitionName = convertS3KeyFormat(businessObjectDefinitionName);
        BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(convertedNamespaece, convertedBusinessObjectDefinitionName);
        try {
            businessObjectDefinitionService.updateBusinessObjectDefinitionEntitySampleFile(businessObjectDefinitionKey, businessObjectDefinitionSampleFileUpdateDto);
        } catch (ObjectNotFoundException ex) {
            LOGGER.info("Failed to find the business object definition, next try the original namespace and business oject defination name " + ex);
            // if Business object definition is not found, use the original name space and bdef name
            businessObjectDefinitionKey = new BusinessObjectDefinitionKey(namespace, businessObjectDefinitionName);
            businessObjectDefinitionService.updateBusinessObjectDefinitionEntitySampleFile(businessObjectDefinitionKey, businessObjectDefinitionSampleFileUpdateDto);
        }
    } catch (RuntimeException | IOException e) {
        LOGGER.error("Failed to process message from the JMS queue. jmsQueueName=\"{}\" jmsMessagePayload={}", HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, payload, e);
    }
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) BusinessObjectDefinitionSampleFileUpdateDto(org.finra.herd.model.dto.BusinessObjectDefinitionSampleFileUpdateDto) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) IOException(java.io.IOException) JmsListener(org.springframework.jms.annotation.JmsListener)

Aggregations

Headers (okhttp3.Headers)128 Request (okhttp3.Request)61 Response (okhttp3.Response)54 Test (org.junit.Test)40 IOException (java.io.IOException)32 Call (okhttp3.Call)30 RequestBody (okhttp3.RequestBody)25 CancelledException (com.hippo.ehviewer.client.exception.CancelledException)20 EhException (com.hippo.ehviewer.client.exception.EhException)20 NoHAtHClientException (com.hippo.ehviewer.client.exception.NoHAtHClientException)20 ParseException (com.hippo.ehviewer.client.exception.ParseException)20 StatusCodeException (com.hippo.network.StatusCodeException)20 ResponseBody (okhttp3.ResponseBody)18 HttpHeaders (okhttp3.internal.http.HttpHeaders)18 MediaType (okhttp3.MediaType)15 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)14 HeaderResponseBoolHeaders (fixtures.header.models.HeaderResponseBoolHeaders)14 HeaderResponseByteHeaders (fixtures.header.models.HeaderResponseByteHeaders)14 HeaderResponseDateHeaders (fixtures.header.models.HeaderResponseDateHeaders)14 HeaderResponseDatetimeHeaders (fixtures.header.models.HeaderResponseDatetimeHeaders)14