01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package org.restlet.example.misc;
20:
21: import org.restlet.Client;
22: import org.restlet.data.ChallengeResponse;
23: import org.restlet.data.ChallengeScheme;
24: import org.restlet.data.Form;
25: import org.restlet.data.Method;
26: import org.restlet.data.Parameter;
27: import org.restlet.data.Protocol;
28: import org.restlet.data.Request;
29: import org.restlet.data.Response;
30: import org.restlet.resource.Representation;
31: import org.restlet.util.Series;
32:
33: /**
34: * Test the Amazon Web Service authentication.
35: *
36: * @author Jerome Louvel (contact@noelios.com)
37: */
38: public class AwsTest {
39: public static void main(String[] args) throws Exception {
40: // Prepare the request
41: Request request = new Request(Method.GET,
42: "http://s3.amazonaws.com/quotes/nelson");
43: request.setChallengeResponse(new ChallengeResponse(
44: ChallengeScheme.HTTP_AWS, "44CF9590006BF252F707",
45: "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV"));
46:
47: // Add some extra headers
48: Series<Parameter> extraHeaders = new Form();
49: extraHeaders.add("X-Amz-Meta-Author", "foo@bar.com");
50: extraHeaders.add("X-Amz-Magic", "abracadabra");
51:
52: // For the test we hard coded a special date header. Normally you don't
53: // need this as the
54: // HTTP client connector will automatically provide an accurate Date
55: // header and use it
56: // for authentication.
57: // extraHeaders.add("X-Amz-Date", "Thu, 17 Nov 2005 18:49:58 GMT");
58:
59: request.getAttributes().put("org.restlet.http.headers",
60: extraHeaders);
61:
62: // Handle it using an HTTP client connector
63: Client client = new Client(Protocol.HTTP);
64: Response response = client.handle(request);
65:
66: // Write the response entity on the console
67: Representation output = response.getEntity();
68: output.write(System.out);
69: }
70:
71: }
|