Need help with S3App.java example, from RESTful Web Services (O'Reilly)

2009-06-30 Thread R.H.
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 = "0F9DBXKB5274JK​​TJ8DG2";​
public final static String PRIVATE_KEY = 
"GuUHQ086Wawbwv​​Vl3JPl9JIk4VO​tLcllkv​Ib0b7w​";
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 List getBuckets() {
List result = new ArrayList();

// 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 Client(P

RE: Possible GAE Client issue.

2009-06-30 Thread Matt
Thanks for your response. Bug report added.

Cheers,
Matt


jlouvel wrote:
> 
> Hi guys,
> 
> By default, we leverage the HttpURLConnection class which has been
> reimplemented on top of URLFetcher so this should work.
> 
> Thierry will finish his work on automated Restlet editions next week or so
> and we'll be able to resolve such issue more quickly and precisely.
> 
> For now, I suggest to enter a bug report.
> 
> 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 : news [mailto:n...@ger.gmane.org] De la part de Philippe Marschall
> Envoyé : vendredi 26 juin 2009 07:14
> À : discuss@restlet.tigris.org
> Objet : Re: Possible GAE Client issue.
> 
> Matt wrote:
>> Hi there,
>> 
>> I'm getting the following error whenever I attempt to use the client
>> class
>> from within the GAE.
>> 
>> Client client = new Client(Protocol.HTTP);
>> Response response = client.get("http://www.google.com";);
>> 
>> Internal Connector Error (1002) - access denied
>> (java.net.SocketPermission
>> www.google.com resolve)
>> 
>> NB: I'm not using anything other than the default provided by restlet
>> i.e.
>> I'm not using apache's HttpClient.
>> 
>> I've updated the gae jar to be the latest snapshot as of yesterday but
>> I'm
>> still getting this problem.
>> 
>> Any suggestions? Or is it a potential bug? 
> 
> You're not allowed to open sockets on GAE/J.
> 
> Cheers
> Philippe
> 
> --
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=23655
> 93
> 
> --
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2366277
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/Possible-GAE-Client-issue.-tp3151643p3185766.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2366872


Re: The best way to integrate servlets with restlets

2009-06-30 Thread Rhett Sutphin
Hi Tamer,

I think this is more of a discuss topic, so I'm moving it there.

On Jun 30, 2009, at 9:13 AM, tameremil wrote:

> Hello,
> I am currently working on an application where I have to provide a  
> rich web
> client as well as a REST API. I chose to use RESTLET for my REST  
> API. Now
> when it comes to the web interface, I have two choices:
> 1. either infest my application with countless javascript code  
> (which would
> call the REST API then render)

[Side note: don't reject JavaScript out of hand.  With an appropriate  
toolkit to patch over the inter-browser messiness (I like jQuery and  
YUI) and good unit tests, a dynamic, JS-based UI could be your best  
bet.]

> 2. use servlets and jsps.
>
> I chose to stay away from javascript as much as possible and rely on
> servlets and jsps to render web UI. However, now I am facing a  
> dilema. In
> order to call the REST API from my servlets I am using the RESTLET  
> CLIENT,
> this approach has proved to be inefficient. Every time I make a call  
> I have
> to parse the returned JSON and go through pain to extract API call  
> response.

It sounds like you have (conceptually) a single server which provides  
both an HTML-based web GUI and a JSON API.  If that's so, that's a  
common case.  You can use Restlet for both representations -- in fact,  
this sort of thing is one of the things the RESTful architecture style  
excels at.

The idea is that you implement the same Resources, with the same  
associated logic, but allow them to return different Representations  
based on what the client requests.  This concept is "Content  
Negotiation" and Restlet supports it.  I'd suggest reading the  
O'Reilly "RESTful Web Services" book for more info.

One caveat is that I don't think you can use JSP to render a Restlet  
Representation.  You can use FreeMarker, though, which is similar  
(some would say better).

> I read about the Servlet Convertor, but I am not sure how I can use  
> it here.
> I am not concerned about tight integration between Servlets and  
> Restlets as
> long as I can have my RESTLETs not depend on my servlets (but I do  
> not care
> about the opposite).

The Servlet Convertor is to allow you to serve your Restlet  
application via a Servlet container.

>
> My Questions:
> 1. What is the best way to integrate my servlet with the RESTLETs?
>
> 2. Is there a way for me to pass java objects from the restlet to the
> servlet? This way in the servlet I can extract java objects and not  
> rely on
> re-assembling the JSON or XML contained in the Response  
> Representation?

For a new application (and assuming I understand what you're trying to  
do), I'd suggest using content negotation in Restlet and not using  
Servlet/JSP at all.

If you really don't want to do that, or if you already have a large  
investment in JSP-based views, I'd extract the business logic into a  
separate layer and make it available to both your servlets and your  
restlets.

Rhett

>
> Please let me know if my question is not clear.
>
> I am in a tough bind and would appreciate any and all help.
>
> Thank you,
>
> Tamer
> -- 
> View this message in context: 
> http://n2.nabble.com/The-best-way-to-integrate-servlets-with-restlets-tp3182669p3182669.html
> Sent from the Restlet Code mailing list archive at Nabble.com.
>
> --
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2366718

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2366777


RE: bug?

2009-06-30 Thread Jerome Louvel
Hi Schley,

I've just fixed this bug in SVN trunk. Thanks for spotting it.

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 : Schley Andrew Kutz [mailto:sak...@gmail.com] 
Envoyé : jeudi 25 juin 2009 20:09
À : discuss@restlet.tigris.org
Objet : bug?

I want to prevent the use of HTTP VERB annotations in order to force  
sub-classes to respond with specific class types via abstract methods  
that I prototype in a base class. I marked the isAnnotated() method as  
@Override and final and returned false. However, when it returns false  
I get the following error:

java.lang.NullPointerException
at  
org 
.restlet 
.engine.resource.AnnotationUtils.getAnnotation(AnnotationUtils.java:106)
at  
org.restlet.resource.ServerResource.getAnnotation(ServerResource.java: 
649)
at org.restlet.resource.ServerResource.doHandle(ServerResource.java:

329)
at  
org 
.restlet 
.resource.ServerResource.doNegotiatedHandle(ServerResource.java:592)
at  
org 
.restlet 
.resource.ServerResource.doConditionalHandle(ServerResource.java:260)
at
org.restlet.resource.ServerResource.handle(ServerResource.java:921)
at  
com.h9labs.vangaea.server.rest.BaseResource.handle(BaseResource.java: 
159)
at org.restlet.resource.Finder.handle(Finder.java:510)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:201)
at org.restlet.routing.Router.handle(Router.java:490)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:201)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:201)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at  
org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java: 
153)
at org.restlet.routing.Filter.handle(Filter.java:201)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:201)
at org.restlet.engine.ChainHelper.handle(ChainHelper.java:111)
at  
org 
.restlet 
.engine.application.ApplicationHelper.handle(ApplicationHelper.java:71)
at org.restlet.Application.handle(Application.java:396)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:201)
at org.restlet.routing.Router.handle(Router.java:490)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:201)
at org.restlet.routing.Router.handle(Router.java:490)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:201)
at org.restlet.engine.ChainHelper.handle(ChainHelper.java:111)
at org.restlet.Component.handle(Component.java:397)
at org.restlet.Server.handle(Server.java:350)
at org.restlet.engine.ServerHelper.handle(ServerHelper.java:71)
at  
org.restlet.engine.http.HttpServerHelper.handle(HttpServerHelper.java: 
149)
at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:

932)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java: 
487)
at  
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at  
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java: 
216)
at  
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at  
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java: 
216)
at  
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:

405)
at  
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at  
org 
.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java: 
49)
at  
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java: 
505)
at org.mortbay.jetty.HttpConnection 
$RequestHandler.headerComplete(HttpConnection.java:829)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at  
org 
.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java: 
395)
at org.mortbay.thread.QueuedThreadPool 
$PoolThread.run(QueuedThreadPool.java:488)
-- 
-a

"Ide