/**
* @param args
*/
public static void main(String[] args) throws Exception {
AWSCredentials fakeAwsCredentials = new AWSCredentials("fake-aws-access-key", "fake-aws-secret-key");
int port = 443;
ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
ServerSocket ssocket = ssocketFactory.createServerSocket(port);
System.out.println("Accepting connections on port 443");
while (port == 443) {
// Listen for connections
Socket socket = ssocket.accept();
System.out.println("Opened connection");
// Create streams to securely send and receive data to the client
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
String receivedDataStr = new String(buffer, 0, read);
String requestActionAndHeaders =
receivedDataStr.substring(0, receivedDataStr.indexOf("\r\n\r\n") + 4);
System.out.println(requestActionAndHeaders);
if (requestActionAndHeaders.startsWith("GET")) {
String path = requestActionAndHeaders.substring(4,
requestActionAndHeaders.indexOf(' ', 4));
if (path.startsWith("/jets3t-")) {
// Return fake AWS credentials.
String headers =
"HTTP/1.1 200 OK\r\n" +
"x-amz-id-2: FakeAWSCredentials\r\n" +
"x-amz-request-id: FakeAWSCredentials\r\n" +
"Date: Thu, 24 May 2007 13:39:21 GMT\r\n" +
"Cache-Control: max-age=259200\r\n" +
"Last-Modified: Wed, 27 Dec 2006 02:37:58 GMT\r\n" +
"ETag: \"fa5d6b0ea9716cf692b286b6aa187f3d\"\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Length: 139\r\n" +
"Server: AmazonS3\r\n\r\n";
out.write(headers.getBytes("UTF-8"));
fakeAwsCredentials.save("please", out);
}
else if (path.equals("/")) {
// Return fake bucket listing.
String headers =