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));
}
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));
}
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));
}
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;
}
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);
}
}
Aggregations