Re: RestletGWTSimpleExample - Error while handling an HTTP client call

2009-12-20 Thread Tim Peierls
Putting both the client and server in the same GWT project isn't a
requirement in general, is it? That would be a pretty big limitation.

Also, the RestletGWTSimpleExample page (
http://wiki.restlet.org/docs_2.0/13-restlet/275-restlet/144-restlet/188-restlet.html)
mentions an Ant build file, but I didn't find one in the zip archive. Does
one exist?

--tim

On Tue, Nov 24, 2009 at 8:19 AM, Thierry Boileau 
thierry.boil...@noelios.com wrote:

 Hi Josef,

 you seem to use two separate projects. Could you integrate your RESTful
 service application inside the gwt project? This should be composed of
 two parts: client and server (configured using the war/WEB=INF/web.xml
 file).

 best regards,
 Thierry Boileau


  i just saw, that internally an exception is thrown:
 
  Internal Connector Error (1002) - The URL http://localhost:1234/messagesis 
  invalid or violates the same-origin security restriction
 
  this seems to be the problem. it might not be specific to restlet,
 anyways maybe you know a way to bypass the SOP restricition using restless
 gwt?
 
  --
 
  regarding my environment: there is an apache cxf RESTful webservice
 started by a simple java application which publishes a message service at
 http://localhost:1234/messages. using firefox poster i can veryfy, that
 GET http:localhost:1234/messages would give a list of messages in xml
 format. now i am trying to build a gwt client which accesses the service. my
 platform is ubuntu 9.10 where i develop under eclipse.
 
  thanks for your help and regards, josef
 
 
  Hello josef,
 
  what is the status code of the response inside the  onReceived event
  manager?
 
 
  is a restlet gwt client intended to be used with a restlet gwt server
 implementation only?
 
  Not at all. The server part could be a simple servlet based application.
 
  could you describe your environment? and maybe send a reproductible test
  case?
 
  Best regards,
  Thierry Boileau
 
 
  hello thierry,
 
  thanks, i just tested the current example code and ... it worked!! ;)
 
  maybe it is because this time i didn't use the ant-script (it is
 missing this time), but directly imported the eclipse project file.
 
  well unfortunately i ran into troubles again.
  on the server-side i am using the JAX-RS features of the apache cxf
 framework to publish my RESTful services. say that my service runs at
 http://localhost:1234/messages
 
  i tried to run a simple get-request on that url using
  ClientResource r = new ClientResource(http://localhost:1234/messages
 );
  r.setOnReceived(new Uniform() {
  public void handle(Request request, Response
 response) {
  ...
  }
  r.get(MediaType.APPLICATION_XML);
 
  my service won't be invoked, the handler method neither, nor do i
 receive any log output...
 
  is a restlet gwt client intended to be used with a restlet gwt server
 implementation only, so accessing my cxf services doesn't work by
 definition?
 
  or is the problem that i can't access my service because of running gwt
 in hosted mode and trying to access a restful service on localhost outside
 of the gwt hosted scope?
 
  thanks for your hints.
 
  josef
 
 
 
 
 

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2423800


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

RE: Fallback routing

2009-12-20 Thread Tal Liron
So, nobody provided a better solution, but here's mine, with source code 
straight out of the Prudence project!

I call it a FallbackRouter, an extension of the standard Restlet router, and 
pretty much a drop-in replacement for it in most circumstances. Whenever you 
attach new targets to it, it makes sure to automatically bunch together 
identical routes via a Fallback restlet. The Fallback restlet goes through its 
targets in order, trying to find the first one that can handle the request. It 
thus falls back to the next target for that route.

It also supports simple caching, so that the successful target can be 
remembered per reference, and wasteful re-attempts can be avoided in the (near) 
future.

Detaching targets from the FallbackRouter is also done with sensitivity to 
un-bunching.

This have proven very useful in Prudence, where we can allow serving dynamic 
HTML, static web files, and REST resources from the same base URI.

Here is the source code from the current Prudence revision, though if you read 
this email later, always best to check for the freshest revision:

http://prudence.tigris.org/source/browse/prudence/trunk/java/com.threecrickets.prudence/src/com/threecrickets/prudence/util/FallbackRouter.java?revision=145view=markup

http://prudence.tigris.org/source/browse/prudence/trunk/java/com.threecrickets.prudence/src/com/threecrickets/prudence/util/Fallback.java?revision=145view=markup

-Tal

 Here's my requirement:
 
 I have two restlets to attach to a router, both with the same URI 
 template. What I want is that if the first restlet fails (specifically 
 setting the response status to 404), then the next restlet would be 
 tried. I'm calling this fallback routing.
 
 So far, the only thing that works well is my own custom restlet that 
 tries these two (or more) restlets in series. But this solution is 
 awkward and also circumvents the router.
 
 I've tried to create my own custom router with a custom routing mode, 
 but the best this solution can offer is selection of a route. There's no 
 simple way to fallback on the next route in line if the first one 
 fails its handle(). I even thought to use Router's built in retry 
 feature, but this would require runtime changing of the route list, 
 which also seems awkward to me.
 
 Any better ideas?
 
 -Tal

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


spring mvc like web binding for POJO

2009-12-20 Thread kiwionly
hi,

I wondering is restlet (will) support POJO binding like what in spring MVC web 
binding which convert all parameter value to java object. 

This could be useful if client is sending many parameter and server can convert 
it to object without many boilerplate code.

kiwi

happy hacking !

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


Re: Upload to Directory 2.0m6

2009-12-20 Thread TKM
Thought I'd contribute this variation on the example from M.Abdel-Aziz
(thanks so much for the inspiration).   It was written using 2.0m6.  There
are 3 code fragments:  1. the routing, 2. a file upload ServerResource, 3.
code that inserts the uploaded file and its name (as specified in the URI)
into a blob in a mysql database table.  There are a couple more notes at the
end.

// 1.  file upload routing in a Restlet Application

Router router = new Router(getContext()); 
router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
router.setRoutingMode(Router.MODE_BEST_MATCH); 

Router uploadRouter = new Router(getContext()); 

uploadRouter.attach(, FileUploadResource.class);
uploadRouter.attach(/name/{name}, FileUploadResource.class);  

final ChallengeAuthenticator uploadGuard = new
ChallengeAuthenticator(this.getContext(), ChallengeScheme.HTTP_BASIC, 
Restful Access -- Please supply your 
credentials);
uploadGuard.setVerifier(myVerifier); 
uploadGuard.setNext(uploadRouter);
router.attach(/fileuploads,uploadGuard);

/** 
 * 2.  Resource that manages uploading files. 
 * Sample curl used to test this beast:
 * 
 * curl -v -u name:password 
http://127.0.0.1/myResource/fileuploads/name/test.jar  -F
name=@/Users/ty/Desktop/test.xml  -X POST
 *
 */
public class FileUploadResource extends ServerResource {
private static Logger myLog = 
Logger.getLogger(FileUploadResource.class);
private Request request;
private String fileName = ;
private CMInfo cmi = null;

@Override  
protected void doInit() throws ResourceException {  
getVariants().add(new Variant(MediaType.MULTIPART_ALL)); 

request = getRequest();
ClientInfo cli = request.getClientInfo();
ChallengeResponse cr = request.getChallengeResponse();
cmi = new CMInfo(cr.getIdentifier(), cli.getAddress(), null);

fileName = (String) getRequest().getAttributes().get(name);

if(request.getMethod() != org.restlet.data.Method.POST) {
setStatus(Status.CLIENT_ERROR_CONFLICT);  
}
else {
setStatus(Status.SUCCESS_OK);
}
} 

@Post
public void uploadIt(Representation file) { 

try {
FileItemFactory factory = new DiskFileItemFactory(); 
RestletFileUpload fileUpload = new 
RestletFileUpload(factory); 

FileItemIterator iter = 
fileUpload.getItemIterator(file);

if (iter.hasNext()) { 
FileItemStream item = iter.next();

if (!item.isFormField()) { 

myLog.info(ContentType:+item.getContentType());
myLog.info(file:+item.getName());

Attachment.uploadAttachment(cmi, 
item.openStream(), fileName);  
} 
} 
}
catch (Exception e) {
myLog.info(uploadIt exception:+e);
}

setStatus(Status.SUCCESS_CREATED);  // assume works for now
} 
}

// 3. a function to save an uploaded file to a mySql attachments table

public static int uploadAttachment(CMInfo cmi, InputStream inStream, 
String
attachmentName) {
InputStream is = null;
int attachmentId = -1;
DataSource ds = MyUtils.getDataSource();
java.sql.Connection conn = null;
PreparedStatement ps = null;
String sqlString = null;
int fileLength = 0;

try {
fileLength = (int) inStream.available();

if(StringUtils.isNotBlank(attachmentName)) {
sqlString = INSERT INTO attachments (filename, 
contents) VALUES(?, ?)
;

conn = ds.getConnection();
ps = StatementFactory.getStatement(conn, 
sqlString, cmi);
ps.setString(1, attachmentName);
ps.setBinaryStream(2, inStream, fileLength);
ps.executeUpdate();

sqlString = SELECT LAST_INSERT_ID() as autoId 
;
ps = StatementFactory.getStatement(conn, 
sqlString, cmi);
ResultSet rs = ps.executeQuery();
if (rs.next()) {