assertEquals(1,result.getComplete().size());
}
public HttpServer createHttpServer() throws IOException {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(8069), 0);
// create and register our handler
httpServer.createContext("/bucketname/standard-key.txt",new HttpHandler() {
public void handle(HttpExchange exchange) throws IOException {
byte[] response = "loaded=true".getBytes("UTF-8");
// RFC 2616 says HTTP headers are case-insensitive - but the
// Amazon S3 client will crash if ETag has a different
// capitalisation. And this HttpServer normalises the names
// of headers using "ETag"->"Etag" if you use put, add or
// set. But not if you use 'putAll' so that's what I use.
Map<String, List<String>> responseHeaders = new HashMap();
responseHeaders.put("ETag", Collections.singletonList("\"TEST-ETAG\""));
responseHeaders.put("Content-Type", Collections.singletonList("text/plain"));
exchange.getResponseHeaders().putAll(responseHeaders);
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length);
exchange.getResponseBody().write(response);
exchange.close();
}
});
httpServer.createContext("/bucketname/404.txt",new HttpHandler() {
public void handle(HttpExchange exchange) throws IOException {
byte[] response = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<Error>\n" +
" <Code>NoSuchKey</Code>\n" +
" <Message>The resource you requested does not exist</Message>\n" +
" <Resource>/bucketname/404.txt</Resource> \n" +
"</Error>").getBytes("UTF-8");
exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND,response.length);
exchange.getResponseBody().write(response);
exchange.close();
}
});
httpServer.start();
return httpServer;
}