Need help with S3App.java example, from RESTful Web Services (O'Reilly)
I am trying to run the S3App.java (RESTful Web Services publisher O'Reilly) and getting a HTTP response code of 403 Forbidden. S3App.java extends S3Authorized.java which defines the following keys (constants), public final static String PUBLIC_KEY = 0F9DBXKB5274JKTJ8DG2; public final static String PRIVATE_KEY = GuUHQ086WawbwvVl3JPl9JIk4VOtLcllkvIb0b7w; which are not allowing me to authenticate properly. I have compiled, S3App, S3Authorized, S3Bucket, and S3Object, successfully. Please might someone shed some light on what I am doing wrong? I tried the following work around. I created an account at AWS. When doing so, I was assigned an Access Key ID and a Secret Access Key. I updated the code's original PUBLIC_KEY value by replacing it with the value of my AWS_Access_Key_ID and PRIVATE_KEY with my AWS_Secret_Access_Key value. The work around failed. I figured this was a long shot and would probably fail; because I was assuming the AWS_Secret_Access_Key is suppose to be used to create signatures for requests made to retrieve S3 content. However, I could have misunderstood the intent of an AWS_Secret_Access_Key and how to use it properly. I have attached all the java code. Cheers and thanks for reading, woodHack/* * Copyright 2005-2007 Noelios Consulting. * * The contents of this file are subject to the terms of the Common Development * and Distribution License (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the license at * http://www.opensource.org/licenses/cddl1.txt See the License for the specific * language governing permissions and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each file and * include the License file at http://www.opensource.org/licenses/cddl1.txt If * applicable, add the following below this CDDL HEADER, with the fields * enclosed by brackets [] replaced with your own identifying information: * Portions Copyright [] [name of copyright owner] */ package org.restlet.example.book.rest.ch3; import java.util.ArrayList; import java.util.List; import org.restlet.data.Response; import org.restlet.resource.DomRepresentation; import org.w3c.dom.Node; /** * Amazon S3 client application. Returns a list of buckets. * * @author Jerome Louvel (cont...@noelios.com) */ public class S3App extends S3Authorized { public static void main(String... args) { for (S3Bucket bucket : new S3App().getBuckets()) { System.out.println(bucket.getName() + : + bucket.getUri()); } } public ListS3Bucket getBuckets() { ListS3Bucket result = new ArrayListS3Bucket(); // Fetch a resource: an XML document with our list of buckets Response response = authorizedGet(HOST); DomRepresentation document = response.getEntityAsDom(); // Use XPath to find the bucket names for (Node node : document.getNodes(//Bucket/Name)) { result.add(new S3Bucket(node.getTextContent())); } return result; } } /* * Copyright 2005-2007 Noelios Consulting. * * The contents of this file are subject to the terms of the Common Development * and Distribution License (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the license at * http://www.opensource.org/licenses/cddl1.txt See the License for the specific * language governing permissions and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each file and * include the License file at http://www.opensource.org/licenses/cddl1.txt If * applicable, add the following below this CDDL HEADER, with the fields * enclosed by brackets [] replaced with your own identifying information: * Portions Copyright [] [name of copyright owner] */ package org.restlet.example.book.rest.ch3; import org.restlet.Client; import org.restlet.data.ChallengeResponse; import org.restlet.data.ChallengeScheme; import org.restlet.data.Method; import org.restlet.data.Protocol; import org.restlet.data.Request; import org.restlet.data.Response; import org.restlet.resource.Representation; /** * Amazon S3 client. Support class handling authorized requests. * * @author Jerome Louvel (cont...@noelios.com) */ public class S3Authorized { public final static String PUBLIC_KEY = 0F9DBXKB5274JKTJ8DG2; public final static String PRIVATE_KEY = GuUHQ086WawbwvVl3JPl9JIk4VOtLcllkvIb0b7w; public final static String HOST = https://s3.amazonaws.com/;; private static Response handleAuthorized(Method method, String uri, Representation entity) { // Send an authenticated request Request request = new Request(method, HOST, entity); request.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_AWS, PUBLIC_KEY, PRIVATE_KEY)); return new
Timeline for Restlet M4?
Hi Jérôme co., Do you have an idea when the remaining bugs [1] are resolved? In a project I tried to support Restlet 1.x and 2.x but recently I switched over to Restlet 2.0M3 due to API incompatibilities. Now I've got the request if it wouldn't be better to switch back to Restlet 1.x. :) I could use the 2.0 SVN snapshots, but an official release would provide a better impression. It would be great if you can provide a rough time line so I can estimate if I should switch back to 1.x or support both Restlet versions or wait for the next milestone. [1] http://restlet.tigris.org/issues/buglist.cgi?Submit+query=Submit+queryissue_status=NEWissue_status=STARTEDissue_status=REOPENEDtarget_milestone=2.0+M4 Thanks in advance, Lars -- http://www.semagia.com -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2367063
RE: Re: Multiple content types
Okay.. I had to add an XLS Representation for a resource and I wan to support a suffix of .json for JSON and .XLS for Excel , but using the code below (and rest of the code in the previous thread). no matter what extension I use (even other than XLS OR JSON). the Variant.Representation in my represent(Variant variant) method in the resource class always picks up JSON as the type.. Thanks public HelloWorldResource(Context context, Request request, Response response) { super(context, request, response); getVariants().add(new Variant(MediaType.APPLICATION_EXCEL)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); } Hi Sherif, .js is javascript .json is json :0) There is no need to add js or json to the MetadataService as it comes with a bunch of common ones already. Remove that line, and try http://localhost:8080/firstStepsServlet/Hello.json (Notice the JSON) Jon Sherif wrote: Thanks Jonathan.. 1. Here’s what I did to support lets say “.js” as an extension to indicate JSON as the content type *public* *class* FirstStepsApplication *extends* Application { /** * Creates a root Restlet that will receive all incoming calls. */ @Override *public* Restlet createRoot() { // Create a router Restlet that routes each call to a // new instance of HelloWorldResource. Router router = *new* Router(getContext()); // Defines only one route router.attachDefault(HelloWorldResource.*class*); *this*.getTunnelService().setExtensionsTunnel(*true*); *this*.getTunnelService().setEncodingParameter(output); *this*.getMetadataService().addExtension(js, *new* Metadata(MediaType./APPLICATION_JSON/.getName(), MediaType./APPLICATION_JSON/.getDescription()), *true* ); *return* router; } } *public* *class* HelloWorldResource *extends* Resource { *public* HelloWorldResource(Context context, Request request, Response response) { *super*(context, request, response); // This representation has only one type of representation. getVariants().add(*new* Variant(MediaType./TEXT_PLAIN/)); getVariants().add(*new* Variant(MediaType./APPLICATION_JSON/)); } /** * Returns a full representation for a given variant. */ @Override *public* Representation represent(Variant variant) *throws* ResourceException { Representation representation = *null*; *if*(variant.getMediaType() == MediaType./APPLICATION_JSON/){ representation = *new* JsonRepresentation(Hello World); }*else* *if* ( variant.getMediaType() == MediaType./TEXT_PLAIN/){ representation = *new* StringRepresentation( hello, world, MediaType./TEXT_PLAIN/); } *return* representation; } } However when I call the service using the following URL http://localhost:8080/firstStepsServlet/Hello.js the Variant type in the HelloWorldResource is of MediaType.TEXT_PLAIN Thanks for Your help *From:* Jonathan Hall (via Nabble) [mailto:ml-user+125526-1692215...@... http://n2.nabble.com/user/SendEmail.jtp?type=nodenode=3043073i=0] *Sent:* Friday, June 05, 2009 1:29 PM *To:* Sherif *Subject:* Re: Multiple content types Have a look at http://www.restlet.org/documentation/2.0/api/org/restlet/service/TunnelService.html getTunnelService().setExtensionsTunnel(true); Jon Sherif wrote: I realize RESTLet supports multiple encodings based on the Accept Encoding headers. Does Restlet also have a way to allow encodings based on URI patter e.g. http://mystores/items/1000.json or something like that ? -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2359775 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2359775 This email is a reply to your post @ http://n2.nabble.com/Multiple-content-types-tp3031817p3031841.html You can reply by email or by visting the link above. View this message in context: RE: Multiple content types http://n2.nabble.com/Multiple-content-types-tp3031817p3043073.html Sent from the Restlet Discuss mailing list archive http://n2.nabble.com/Restlet-Discuss-f1400322.html at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2367141
Re: Premature EOF / Broken Pipe
I tried adding a second resource to my sample application. But it doesn't fail. In my actual application I have a scheduled background thread doing a POST transaction, immediately followed by a GET transaction. The Premature EOF exception has always occurred in the POST transaction. Since order does not matter between these two message exchanges, I switched them around. After doing this and trying several different scheduled time intervals for the background thread, I have yet to see it fail using the org.restlet.Client.Client using org.restlet.data.Protocol.HTTP or Protocol.HTTPS. I can't say problem solved but this is interesting and confusing at the same time. -- Timothy Aanerud On Mon, Jun 29, 2009 at 9:18 AM, Timothy Aanerud tannerudATaticonsulting.com wrote: I haven't tried switching HTTP connectors. :-( But, I did build a sanitized/stripped down example. Unfortunately, my example does not fail like my application does. One difference between my example is I'm only exchange data with one resource, In my actual application I'm sending two messages to two resources back-to-back before pausing. -- Timothy Aanerud taanerudataticonsulting.com taane...@aticonsulting.com On Mon, Jun 29, 2009 at 2:57 AM, Jerome Louvel jerome.lou...@noelios.comwrote: Hi Timothy, Were you able to make progress on this front? Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com *De :* Timothy Aanerud [mailto:taanerudATaticonsulting.comtaane...@aticonsulting.com] *Envoyé :* vendredi 19 juin 2009 22:05 *À :* discuss@restlet.tigris.org *Objet :* Re: Premature EOF / Broken Pipe No, I haven't tried switching HTTP connectors. I get the same failures for both HTTP and HTTPS. In another experiment, I changed the client message frequency to ~1 second intervals and at this rate on both Windows XP and Fedora10/Linux show now problems with the server running on Fedora. The various frequencies and failure rates: 1 second == no problems 1.5 seconds == ~25% failure rate 5 seconds == ~25% failure rate 10 seconds == ~3% failure rate 180 seconds == 0.5%, if any failures I'll switch the HTTP connectors out one at a time and see what happens. -- Timothy Aanerud On Fri, Jun 19, 2009 at 2:02 PM, Jerome Louvel jerome.lou...@noelios.com wrote: Hi Timothy, This looks like a bug to me. Have you tried with different Restlet HTTP connectors (such as Jetty on the server-side and Apache HTTP client)? If you could send us a simple standalone test case, we could easily debug what's going bad. Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder~ http://www.noelios.com -Message d'origine- De: Timothy Aanerud [mailto:taanerudATaticonsulting.comtaane...@aticonsulting.com ] Envoy頺 vendredi 19 juin 2009 18:18 : discuss@restlet.tigris.org Objet: RE: Premature EOF / Broken Pipe As a test, I moved the client code to a Windows XP machine. With a five second update rate it fails regularly too, with the same exceptions and stack traces. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=23635 62 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2363638 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2367157
RangeFilter and redirects
I ran across a problem that was causing the Daemon threads in our WadlComponent-based server to enter a busy loop. Essentially, if a Range header was in the HTTP GET request but the server wanted to return a redirection (e.g. via response.redirectSeeOther()), the entity would be wrapped by a RangeRepresentation. Tunnel in to that, and RangeInputStream#read would loop here: // Reach the start index. while (!(position = startIndex)) { position += skip(startIndex - position); } Aside from the likelihood that there's also a bug in the handling/wrapping of a response entity that's too small for the range, my first question here had to do with the status code of the response itself. Should responses that are not successful (2xx) be subject to wrapping in a RangeRepresentation? Thanks, David -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2367149