Basic Application and Resources (JBOSS)
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 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2359832
Basic Application and Resources (JBOSS)
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=4447dsMessageId=2359787