added tests for content-disposition, first step

This commit is contained in:
Rainbowbreeze 2010-09-17 11:03:36 +02:00
parent 3d4d1301e0
commit 5d8f3bdb37
9 changed files with 39 additions and 1 deletions

View File

@ -70,7 +70,8 @@ public interface S3Client {
* <p />
* This command allows you to specify {@link GetObjectOptions} to control delivery of content.
*
* <h2>Note</h2 If you specify any of the below options, you will receive partial content:
* <h2>Note</h2>
* If you specify any of the below options, you will receive partial content:
* <ul>
* <li>{@link GetObjectOptions#range}</li>
* <li>{@link GetObjectOptions#startAt}</li>

View File

@ -510,6 +510,9 @@ public class HttpUtils {
} else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) {
if (payload != null)
payload.setContentType(header.getValue());
} else if ("Content-Disposition".equalsIgnoreCase(header.getKey())) {
if (payload != null)
payload.setContentDisposition(header.getValue());
} else {
message.getHeaders().put(header.getKey(), header.getValue());
}

View File

@ -204,6 +204,8 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
connection.setRequestProperty("Content-MD5", CryptoStreams.base64(request.getPayload().getContentMD5()));
if (request.getPayload().getContentType() != null)
connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentType());
if (request.getPayload().getContentDisposition() != null)
connection.setRequestProperty("Content-Disposition", request.getPayload().getContentDisposition());
if (chunked) {
connection.setChunkedStreamingMode(8196);
} else {

View File

@ -227,6 +227,11 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
assertEquals(client.postJson("", "foo").trim(), "{\"key\":\"foo\"}POST");
}
public void testPostContentDisposition() throws MalformedURLException, ExecutionException, InterruptedException,
TimeoutException {
assertEquals(client.postWithContentDisposition("", "attachment; filename=photo.jpg", "foo").trim(), "content-disposition:photo.jpg");
}
@Test(invocationCount = 5, timeOut = 5000)
public void testPut() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
assertEquals(client.upload("", "foo").trim(), "fooPUT");

View File

@ -132,6 +132,15 @@ public abstract class BaseJettyTest {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("created");
}
//TODO: insert here additional header detection
} else if (request.getHeader("Content-Disposition") != null) {
//get the filename
String content = request.getHeader("Content-Disposition");
int pos = content.lastIndexOf("=");
String fileName = pos > 0 ? content.substring(pos + 1) : "";
response.setContentType("text/xml");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("content-disposition:" + fileName);
} else {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(toStringAndClose(request.getInputStream()) + "POST");

View File

@ -133,6 +133,11 @@ public interface IntegrationTestAsyncClient {
}
}
@POST
@Path("/objects/{id}")
String postWithContentDisposition(@PathParam("id") String id, @HeaderParam("Content-Disposition") String contentDisposition,
@BinderParam(BindToStringPayload.class) String toPut);
@POST
@Path("/objects/{id}")
@MapBinder(BindToJsonPayload.class)

View File

@ -53,6 +53,8 @@ public interface IntegrationTestClient {
String postWithMd5(String id, String base64MD5, File file);
String postWithContentDisposition(String id, String contentDisposition, String toPut);
String postJson(String id, String toPut);
String action(String id, String action, Map<String, String> options);

View File

@ -107,6 +107,7 @@ public abstract class BaseRestClientTest {
}
//FIXME Shouldn't be assertPayloadHeadersEqual?
protected void assertNonPayloadHeadersEqual(HttpRequest request, String toMatch) {
assertEquals(sortAndConcatHeadersIntoString(request.getHeaders()), toMatch);
}

View File

@ -1494,6 +1494,16 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
assertPayloadEquals(request, "whoops", "application/unknown", false);
}
public void testPutPayloadContentDisposition() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestTransformers.class.getMethod("put", Payload.class);
Payload payload = newStringPayload("whoops");
payload.setContentDisposition("attachment; filename=photo.jpg");
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, "Content-Disposition: attachment; filename=photo.jpg");
assertPayloadEquals(request, "whoops", "application/unknown", false);
}
public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException,
IOException {
Payload payload = newStringPayload("whoops");