Help with a basic Application and Resources (on JBOSS)

2009-06-05 Thread Andrew Moore
Hi, I'm new to RESTful services and Restlets.

I'm trying to create a "hello world" application that is integrated with my
company's J2EE app (we're running on JBOSS).

>From what I can tell from the tutorials and example source code, it seems
pretty simple to add an Application and Resources. I'm definitely missing
something though.

We have a hierarchy of information which I would like to have resources for.
For example, I want to have URI's like these:

/myapp/zipcodes/{zip}/
/myapp/zipcodes/{zip}/locations/{location}
/myapp/zipcodes/{zip}/locations/{location}/users/{user}

This way I'll be able to return information depending on what level of the
hierarchy I'm interested in.

I first tried creating an application in which I used the equivalent of
"router.attachDefault(DefaultResource.class)" to just return "Hello" to my
browser. This worked just fine. My next step though, was to create resources
for the other URI's and simply echo back the various values ({zip},
{location}, {user}) found by my Resource to the browser.

This is where I'm not having success, and I am wondering what I'm doing
wrong, or what concept I'm not catching onto. Since I can't publish the code
for work on here, I've re-worded the packages and code... the application
class I'm using:

package com.myapp.applications;

import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.routing.Router;

import com.myapp.resources.ZipsResource;
import com.myapp.resources.ZipsLocsResource;
import com.myapp.resources.ZipsLocsUsersResource;

public class MyApplication extends Application {

  public MyApplication() {
// TODO Auto-generated constructor stub
  }

  public MyApplication(Context context) {
super(context);
// TODO Auto-generated constructor stub
  }

  @Override
  public Restlet createRoot() {

// Create a router Restlet that routes each call to a
Router router = new Router(getContext());

router.attach("/myapp/zipcodes/{zip}/", ZipsResource.class);
router.attach("/myapp/zipcodes/{zip}/locations/{location}",
ZipsLocsResource.class);
router.attach("/myapp/zipcodes/{zip}/locations/{location}/users/{user}",
ZipsLocsUsersResource.class);

return router;
  }
}


And the code for my resources are all basically the same as this one:

package com.myapp.resources;

import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class Resource extends ServerResource {
 
  private String zip;
  private String location;
  private String user;
 
  @Get
  public Representation represent() {
System.out.println("ZipLocsUsersResource.represent()");
   
this.zip = (String) getRequest().getAttributes().get("zip");
this.location = (String) getRequest().getAttributes().get("location");
this.user = (String) getRequest().getAttributes().get("user");
   
Representation result = new StringRepresentation("ZipsLocsUsersResource
zip[" + this.zip + "] location[" + this.location + "] user[" + this.user +
"]");
return result;
  }
}



Again... in my application class, if I use the ".attachDefault()" I can hit
the URI with my browser and get my "Hello World" response just fine. The
second I remove ".attachDefault()" and start attaching specific URI's, I get
404 responses with the restlet page that says "The server has not found
anything matching the request URI".

I really appreciate any help on what I'm doing wrong or not understanding...
I have read the first steps, read the first resource page, read through the
tutorial, and I have been looking at the example code that came with the
restlets package (2.0M3). I'm assuming my web.xml is properly configured or
I wouldn't have been successful with the "attachDefault()" first attempt I
made.

Thanks in advance and regards,

Andrew

-- 
View this message in context: 
http://n2.nabble.com/Help-with-a-basic-Application-and-Resources-%28on-JBOSS%29-tp3032757p3032757.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Help with a basic Application and Resources (on JBOSS)

2009-06-05 Thread Andrew Moore
Well... I figured it out. And I am an idiot. 

I had setup my web.xml to associate my Application class with "/myapp".

I was then attaching my resources to a URI that started with "/myapp/...".

So therefore, in my browser the URI which properly returned me my resource
was: /myapp/myapp/zipcodes/{zip}/...

I had been trying this instead: /myapp/zipcodes/{zip}/...

Yes, I do feel extremely cool now... (and yes that was some self deprecating
sarcasm...)

~ Andrew

-- 
View this message in context: 
http://n2.nabble.com/Help-with-a-basic-Application-and-Resources-%28on-JBOSS%29-tp3032757p3033033.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Basic Application and Resources (JBOSS)

2009-06-07 Thread Andrew Moore
Hi, I'm new to RESTful services and Restlets.

I'm trying to create a "hello world" application that is integrated in with
my company's J2EE app (we're running on JBOSS).

>From what I can tell from the tutorials and example source code, this seems
pretty simple, but I'm definitely missing something.

There is a hierarchy of information I'm wanting to have resources for, so
I'm wanting to have URI's along the lines of:

/myapp/zipcodes/{zip}/
/myapp/zipcodes/{zip}/locations/{location}
/myapp/zipcodes/{zip}/locations/{location}/users/{user}

This way I'll be able to return information depending on what level of the
hierarchy I'm interested in.

I first tried creating an application in which I used the equivalent of
"router.attachDefault(DefaultResource.class)" to just return "Hello" to my
browser. This worked just fine. My next step though, was to create resources
for the other URI's and simply echo back the various values ({zip},
{location}, {user}) found by my Resource to the browser.

This is where I'm not having success, and I am wondering what I'm doing
wrong, or what concept I'm not catching onto. Since I can't publish the code
for work on here, I've re-worded the packages and code... the application
class I'm using:

package com.myapp.applications;

import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.routing.Router;

import com.myapp.resources.ZipsResource;
import com.myapp.resources.ZipsLocsResource;
import com.myapp.resources.ZipsLocsUsersResource;

public class MyApplication extends Application {

  public MyApplication() {
// TODO Auto-generated constructor stub
  }

  public MyApplication(Context context) {
super(context);
// TODO Auto-generated constructor stub
  }

  @Override
  public Restlet createRoot() {

// Create a router Restlet that routes each call to a
Router router = new Router(getContext());

router.attach("/myapp/zipcodes/{zip}/", ZipsResource.class);
router.attach("/myapp/zipcodes/{zip}/locations/{location}",
ZipsLocsResource.class);
router.attach("/myapp/zipcodes/{zip}/locations/{location}/users/{user}",
ZipsLocsUsersResource.class);

return router;
  }
}


And the code for my resources are all basically the same as this one:

package com.myapp.resources;

import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class Resource extends ServerResource {
  
  private String zip;
  private String location;
  private String user;
  
  @Get
  public Representation represent() {
System.out.println("ZipLocsUsersResource.represent()");

this.zip = (String) getRequest().getAttributes().get("zip");
this.location = (String) getRequest().getAttributes().get("location");
this.user = (String) getRequest().getAttributes().get("user");

Representation result = new StringRepresentation("ZipsLocsUsersResource
zip[" + this.zip + "] location[" + this.location + "] user[" + this.user +
"]");
return result;
  }
}



Again... in my application class, if I use the ".attachDefault()" I can hit
the URI with my browser and get my "Hello World" response just fine. The
second I remove ".attachDefault()" and start attaching specific URI's, I get
404 responses with the restlet page that says "The server has not found
anything matching the request URI".

I really appreciate any help on what I'm doing wrong or not understanding...
I have read the first steps, read the first resource page, read through the
tutorial, and I have been looking at the example code that came with the
restlets package (2.0M3). I'm assuming my web.xml is properly configured or
I wouldn't have been successful with the "attachDefault()" first attempt I
made. 

Thanks in advance and regards,

Andrew









-- 
View this message in context: 
http://n2.nabble.com/Basic-Application-and-Resources-%28JBOSS%29-tp3032099p3032099.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Trouble Getting Query Parameters

2009-06-11 Thread Andrew Moore
I'm new to Restlet and I'm having trouble accessing the query parameters in
my ServerResource.

I'm using a URI comparable to: 
http://localhost:8080/myapp/zipcodes/{zip}/locations/{location}/users/{user}?&callback=someCallbackFunction

The client is written in EXT.js and is expecting me to wrap the json object
in a function with a name the 'callback' query parameter specifies.

I can't for the life of me understand what I'm doing wrong in trying to
access this query parameter. 

My application class is similar to this:


package com.myapp.applications;

import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.routing.Router;

import com.myapp.resources.ZipsLocsUsersResource;

public class MyApplication extends Application {

  public MyApplication() {
  }

  public MyApplication(Context context) {
super(context);
  }

  @Override
  public Restlet createRoot() {

// Create a router Restlet that routes each call to a
Router router = new Router(getContext());

router.attach("/myapp/zipcodes/{zip}/locations/{location}/users/{user}",
ZipsLocsUsersResource.class);

return router;
  }
} 



And my ServerResource class is similar to this:





package com.myapp.resources;

import org.restlet.data.Form;
import org.restlet.data.Parameter;
import org.restlet.data.Reference;
import org.restlet.data.Request;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

import com.myapp.representation.JsonRepresentation;

public class ZipsLocsUsersResource extends ServerResource {
 
  private String zip;
  private String location;
  private String user;
  private String callback;
 
  @Get
  public Representation represent() {  
this.zip = (String) getRequest().getAttributes().get("zip");
this.location = (String) getRequest().getAttributes().get("location");
this.user = (String) getRequest().getAttributes().get("user");
   
Form form = getRequest().getResourceRef().getQueryAsForm();
this.callback = form.getFirstValue("callback");

String jsonString = "{user:\"" + this.user + "\", loc: \"" +
this.location + "\", zip:\"" + this.zip + "\"}";

if (this.callback != null) {
  jsonString = this.callback + "(" + jsonString + ")";
}

Representation result = new JsonRepresentation(jsonString);
return result;
  }
} 



When I run with a debugger, my form always ends up being empty... and when I
dig through the request I can't find the parameters anywhere. I am wanting
this parameter to be optional. I'm not sure if I'm setting my application up
wrong, or if I'm trying to get the parameters the wrong way? This is on a
GET request, and everywhere I look, folks seem to not be able to access the
query parameters until they try the
getRequest().getResourceRef().getQueryAsForm() way of doing it. 

Thanks in advance for your help!

Regards,

Andrew

-- 
View this message in context: 
http://n2.nabble.com/Trouble-Getting-Query-Parameters-tp3063239p3063239.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Trouble Getting Query Parameters

2009-06-11 Thread Andrew Moore
I'm starting to understand what may be going on... when EXT.js makes the
request for my URI, the query string looks like this:

?&_dc=1244741620627&callback=stcCallback1001

And the org.restlet.engine.util.FormReader is not able to parse the
parameters. Here's the error:

06/11/2009 11:33:40.640 [http-0.0.0.0-8080-1] [STDERR] [ERROR] Jun 11, 2009
11:33:40 AM org.restlet.engine.util.FormReader addParameters
WARNING: Unable to parse a form parameter. Skipping the remaining
parameters.
java.io.IOException: Empty parameter name detected. Please check your form
data
at
org.restlet.engine.util.FormReader.readNextParameter(FormReader.java:239)
at org.restlet.engine.util.FormReader.addParameters(FormReader.java:132)
at org.restlet.engine.util.FormUtils.parse(FormUtils.java:302)
at org.restlet.data.Form.(Form.java:137)
at org.restlet.data.Form.(Form.java:121)
at org.restlet.data.Form.(Form.java:94)
at org.restlet.data.Reference.getQueryAsForm(Reference.java:1375)


I'm not sure how to get around this... Maybe my best option is to try and
modify what EXT.js is appending on my URI when it makes the request? 

Any thoughts? 

Thanks in advance for your help!

~ Andrew
-- 
View this message in context: 
http://n2.nabble.com/Trouble-Getting-Query-Parameters-tp3063239p3063444.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Trouble Getting Query Parameters

2009-06-11 Thread Andrew Moore
I just did a test with curl both with and without that initial ampersand in
there... yes, that ampersand is causing the parsing problem. 

Since this is EXT.js creating this, I guess I'll have to figure out a way to
change it or something.

Should the FormReader be able to handle an initial ampersand? Is that a bug,
and if so, should I file it?

Thanks for your help!
-- 
View this message in context: 
http://n2.nabble.com/Trouble-Getting-Query-Parameters-tp3063239p3063559.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


RIAP Client from within my J2EE application (jboss)

2009-07-29 Thread Andrew Moore
Hi, 

We're running a J2EE app on JBOSS, but we've started integrating Restlet so
that hopefully we can ditch our legacy app and move on with RESTful
services.

The short story is hopefully some other folks will be able to use our new
Restlet service to get the resources they need, but if they can't (due to a
deadline crunch) then we need to do the leg work for them: request from our
own service and give them the returned resource through a legacy mechanism
they know already works. 

I'm wanting to write a server-side client (oxymoron?) that uses RIAP so I
can bypass the HTTP overhead and keep request internal. I'd also like to do
it without having to specify any configuration information related to the
host we've installed our application on. I figured my best shot was to write
a client on the server-side (within our application on the same jvm) using
the RIAP protocol. I know I have my restlet application routing internal
RIAP requests correctly as I previously dabbled with some server resources
that called each other... 

I feel like I've tried a number of things... but I think my general problem
is I don't seem to have access to Context of my restlet Application. 

I thought at one point I could call the static method "getCurrent()" on my
Application (i.e. MyRestletApplication.getCurrent()) and then make my riap
request through there:

MyRestletApplication.getCurrent().getContext().getClientDispatcher().get("riap://component/path-to-my-resource")

That didn't seem to work... the MyRestletApplication.getCurrent() only
returns null. Is that something I need to set in the
MyRestletApplication.createRoot() method? 

I also tried just creating a Client with the RIAP protocol:

Client myclient = new Client(Protocol.RIAP);

...but that doesn't seem to work as I don't have a Context for
MyRestletApplication. 

I appreciate any help, direction and insight as to how I can accomplish
this.

Thanks in advance!

Regards,

Andrew




-- 
View this message in context: 
http://n2.nabble.com/RIAP-Client-from-within-my-J2EE-application-%28jboss%29-tp3353312p3353312.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: RIAP Client from within my J2EE application (jboss)

2009-07-30 Thread Andrew Moore
Thanks, I'll give that a shot and let you know if it works or what I'm still
stuck on.

Regards,

Andrew
-- 
View this message in context: 
http://n2.nabble.com/RIAP-Client-from-within-my-J2EE-application-%28jboss%29-tp3353312p3356788.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: RIAP Client from within my J2EE application (jboss)

2009-07-30 Thread Andrew Moore
I'm definitely still having issues... 

A little more background: we have a quartz job that calls a class which is
trying to make these requests. The Job class I created really has no context
for the my restlet application.  I'm not sure I'm creating my client
correctly... when I create it like this (which seems my only option since I
don't have access to a Context object):

Client riapClient = new Client(Protocol.RIAP);
riapClient.start();

I get a warning message:
WARNING: No available client connector supports the required protocols:
'RIAP' . Please add the JAR of a matching connector to your classpath.

I haven't seen a jar to add (and shouldn't this be part of the basic restlet
jar anyway?). When I try and start my client, a NullPointerException gets
thrown from somewhere inside the start() method. I'm assuming this is
probably due to not having a Context specified. But, I am having a hard time
trying to understand how I can get a Context object from my application. 

I haven't found any example code for instantiating and using an RIAP based
Client. I've seen (and used) RIAP requests from within a ServerResource to
another ServerResource, but not an RIAP request from a Client to the
ServerResource. 

I'm pretty sure I'm missing some sort of concept or using the Client in a
way it wasn't intended perhaps. 

Any help explaining what I'm missing or pointing me to some example code of
an RIAP Client that is sitting on the server-side would be greatly
appreciated! 

Regards,

Andrew
-- 
View this message in context: 
http://n2.nabble.com/RIAP-Client-from-within-my-J2EE-application-%28jboss%29-tp3353312p3357728.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Query Parameters for Directory Restlets and static files (405 error)

2009-10-28 Thread Andrew Moore
Hi,

I'm still learning REST, HTTP, and Restlets... so this may be a basic
question, but here goes...

My situation/problem space: 

We have a javascript heavy client and I am trying to set up a way of testing
individual UI components, while reusing the same javascript includes (so
everyone knows if something has broken with our proprietary javascript
library, regardless of what component someone is working on).

So I setup two static files: a test index.html file with links to a
TestViewer.html file, for which I am using a Directory resource to give
clients access to them.

My goal was to have links from the index.html file be of the form:

/myapplication/tests/TestViewer.html?testfile=/myapplication/tests/components/mywidget.js

The TestViewer.html has all the includes for the javascript library, parses
out the testfile query parameter, and dynamically includes the "mywidget.js"
file for testing out the component.


My Problem:

Unless my cache for my browser has been flushed (for either IE or Firefox),
when I try navigating to the TestViewer.html static file with query
parameters appended to the basic file's URI, I get a 405 "Method Not
Allowed" http error. 

What concept or setting up of my Directory resource am I doing wrong?

Code snippet from my Restlet Application class:

LocalReference staticContentDir =
LocalReference.createFileReference(rootPath);

Context context = component.getContext().createChildContext();
 
Directory staticContent = new Directory(context, staticContentDir);
staticContent.setDeeplyAccessible(true);
staticContent.setListingAllowed(false);
staticContent.setModifiable(false);

Any insights? Thanks in advance for your help!

Regards,

Andrew




  
-- 
View this message in context: 
http://n2.nabble.com/Query-Parameters-for-Directory-Restlets-and-static-files-405-error-tp3906669p3906669.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Query Parameters for Directory Restlets and static files (405 error)

2009-10-28 Thread Andrew Moore
I should add that we are using 2.0 M3 and serving it up with JBOSS.

~ Andrew
-- 
View this message in context: 
http://n2.nabble.com/Query-Parameters-for-Directory-Restlets-and-static-files-405-error-tp3906669p3907399.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Query Parameters for Directory Restlets and static files (405 error)

2009-10-30 Thread Andrew Moore
Any ideas anyone? Is there another list somewhere I should be posting this?

Regards,

Andrew



Andrew Moore wrote:
> 
> Hi,
> 
> I'm still learning REST, HTTP, and Restlets... so this may be a basic
> question, but here goes...
> 
> My situation/problem space: 
> 
> We have a javascript heavy client and I am trying to set up a way of
> testing individual UI components, while reusing the same javascript
> includes (so everyone knows if something has broken with our proprietary
> javascript library, regardless of what component someone is working on).
> 
> So I setup two static files: a test index.html file with links to a
> TestViewer.html file, for which I am using a Directory resource to give
> clients access to them.
> 
> My goal was to have links from the index.html file be of the form:
> 
> /myapplication/tests/TestViewer.html?testfile=/myapplication/tests/components/mywidget.js
> 
> The TestViewer.html has all the includes for the javascript library,
> parses out the testfile query parameter, and dynamically includes the
> "mywidget.js" file for testing out the component.
> 
> 
> My Problem:
> 
> Unless my cache for my browser has been flushed (for either IE or
> Firefox), when I try navigating to the TestViewer.html static file with
> query parameters appended to the basic file's URI, I get a 405 "Method Not
> Allowed" http error. 
> 
> What concept or setting up of my Directory resource am I doing wrong?
> 
> Code snippet from my Restlet Application class:
> 
> LocalReference staticContentDir =
> LocalReference.createFileReference(rootPath);
> 
> Context context = component.getContext().createChildContext();
>  
> Directory staticContent = new Directory(context, staticContentDir);
> staticContent.setDeeplyAccessible(true);
> staticContent.setListingAllowed(false);
> staticContent.setModifiable(false);
> 
> Any insights? Thanks in advance for your help!
> 
> Regards,
> 
> Andrew
> 
> 
> 
> 
>   
> 

-- 
View this message in context: 
http://n2.nabble.com/Query-Parameters-for-Directory-Restlets-and-static-files-405-error-tp3906669p3919724.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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