diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index 3c21363640..fe18a6e69e 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -203,6 +203,10 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentType()); if (request.getPayload().getContentDisposition() != null) connection.setRequestProperty("Content-Disposition", request.getPayload().getContentDisposition()); + if (request.getPayload().getContentEncoding() != null) + connection.setRequestProperty("Content-Encoding", request.getPayload().getContentEncoding()); + if (request.getPayload().getContentLanguage() != null) + connection.setRequestProperty("Content-Language", request.getPayload().getContentLanguage()); if (chunked) { connection.setChunkedStreamingMode(8196); } else { diff --git a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java index 156144bafa..3196d47490 100644 --- a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java +++ b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java @@ -241,6 +241,26 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base assertEquals(headers.get("x-Content-Disposition"), Collections.singleton("attachment; filename=photo.jpg")); payload.release(); } + + @Test(invocationCount = 5, timeOut = 5000) + public void testPostContentEncoding() throws ExecutionException, InterruptedException, TimeoutException, + IOException { + Payload payload = Payloads.newStringPayload("foo"); + payload.setContentEncoding("gzip"); + Multimap headers = client.postPayloadAndReturnHeaders("", payload); + assertEquals(headers.get("x-Content-Encoding"), Collections.singleton("gzip")); + payload.release(); + } + + @Test(invocationCount = 5, timeOut = 5000) + public void testPostContentLanguage() throws ExecutionException, InterruptedException, TimeoutException, + IOException { + Payload payload = Payloads.newStringPayload("foo"); + payload.setContentLanguage("mi, en"); + Multimap headers = client.postPayloadAndReturnHeaders("", payload); + assertEquals(headers.get("x-Content-Language"), Collections.singleton("mi, en")); + payload.release(); + } @Test(invocationCount = 5, timeOut = 5000) public void testPut() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException { diff --git a/core/src/test/java/org/jclouds/rest/BaseRestClientTest.java b/core/src/test/java/org/jclouds/rest/BaseRestClientTest.java index 5a5645aeea..6dd699464c 100644 --- a/core/src/test/java/org/jclouds/rest/BaseRestClientTest.java +++ b/core/src/test/java/org/jclouds/rest/BaseRestClientTest.java @@ -72,10 +72,13 @@ public abstract class BaseRestClientTest { bind(TransformingHttpCommandExecutorService.class).toInstance(mock); } } + protected void assertPayloadEquals(HttpRequest request, String toMatch, String contentType, boolean contentMD5) { - assertPayloadEquals(request, toMatch, contentType, null, contentMD5); + assertPayloadEquals(request, toMatch, contentType, null, null, null, contentMD5); } - protected void assertPayloadEquals(HttpRequest request, String toMatch, String contentType, String contentDispositon, boolean contentMD5) { + + protected void assertPayloadEquals(HttpRequest request, String toMatch, String contentType, + String contentDispositon, String contentEncoding, String contentLanguage, boolean contentMD5) { if (request.getPayload() == null) { assertNull(toMatch); } else { @@ -88,28 +91,31 @@ public abstract class BaseRestClientTest { assertEquals(payload, toMatch); Long length = new Long(payload.getBytes().length); try { - assertContentHeadersEqual(request, contentType, contentDispositon, length, contentMD5 ? CryptoStreams - .md5(request.getPayload()) : null); + assertContentHeadersEqual(request, contentType, contentDispositon, contentEncoding, contentLanguage, + length, contentMD5 ? CryptoStreams.md5(request.getPayload()) : null); } catch (IOException e) { propagate(e); } } } - protected void assertContentHeadersEqual(HttpRequest request, String contentType, String contentDispositon, Long length, byte[] contentMD5) { + protected void assertContentHeadersEqual(HttpRequest request, String contentType, String contentDispositon, + String contentEncoding, String contentLanguage, Long length, byte[] contentMD5) { if (request.getFirstHeaderOrNull(TRANSFER_ENCODING) == null) { assertEquals(request.getPayload().getContentLength(), length); } else { assertEquals(request.getFirstHeaderOrNull(TRANSFER_ENCODING), "chunked"); assert request.getPayload().getContentLength() == null - || request.getPayload().getContentLength().equals(length); + || request.getPayload().getContentLength().equals(length); } assertEquals(request.getPayload().getContentType(), contentType); assertEquals(request.getPayload().getContentDisposition(), contentDispositon); + assertEquals(request.getPayload().getContentEncoding(), contentEncoding); + assertEquals(request.getPayload().getContentLanguage(), contentLanguage); assertEquals(request.getPayload().getContentMD5(), contentMD5); } - //FIXME Shouldn't be assertPayloadHeadersEqual? + // FIXME Shouldn't be assertPayloadHeadersEqual? protected void assertNonPayloadHeadersEqual(HttpRequest request, String toMatch) { assertEquals(sortAndConcatHeadersIntoString(request.getHeaders()), toMatch); } @@ -121,10 +127,10 @@ public abstract class BaseRestClientTest { protected void assertExceptionParserClassEquals(Method method, @Nullable Class parserClass) { if (parserClass == null) assertEquals(RestAnnotationProcessor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(injector, - method).getClass(), MapHttp4xxCodesToExceptions.class); + method).getClass(), MapHttp4xxCodesToExceptions.class); else assertEquals(RestAnnotationProcessor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(injector, - method).getClass(), parserClass); + method).getClass(), parserClass); } protected void assertSaxResponseParserClassEquals(Method method, @Nullable Class parserClass) { @@ -133,7 +139,7 @@ public abstract class BaseRestClientTest { protected void assertResponseParserClassEquals(Method method, HttpRequest request, @Nullable Class parserClass) { assertEquals(RestAnnotationProcessor.createResponseParser(parserFactory, injector, method, request).getClass(), - parserClass); + parserClass); } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index aa7b2e1911..5b627e39b4 100755 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -1501,9 +1501,29 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { HttpRequest request = factory(TestQuery.class).createRequest(method, payload); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, "whoops", "application/unknown", "attachment; filename=photo.jpg", false); + assertPayloadEquals(request, "whoops", "application/unknown", "attachment; filename=photo.jpg", null, null, false); } + public void testPutPayloadContentEncoding() throws SecurityException, NoSuchMethodException, IOException { + Method method = TestTransformers.class.getMethod("put", Payload.class); + Payload payload = newStringPayload("whoops"); + payload.setContentEncoding("gzip"); + HttpRequest request = factory(TestQuery.class).createRequest(method, payload); + assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, "whoops", "application/unknown", null, "gzip", null, false); + } + + public void testPutPayloadContentLanguage() throws SecurityException, NoSuchMethodException, IOException { + Method method = TestTransformers.class.getMethod("put", Payload.class); + Payload payload = newStringPayload("whoops"); + payload.setContentLanguage("en"); + HttpRequest request = factory(TestQuery.class).createRequest(method, payload); + assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, "whoops", "application/unknown", null, null, "en", false); + } + public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException, IOException { Payload payload = newStringPayload("whoops");