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:


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) {
    // TODO Auto-generated constructor stub

  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);

    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;
  public Representation 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

Thanks in advance and regards,


View this message in context: 
Sent from the Restlet Discuss mailing list archive at Nabble.com.


Reply via email to