aspose file tools*
The moose likes Web Services and the fly likes Restlets not responding even though request shows in console Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Restlets not responding even though request shows in console" Watch "Restlets not responding even though request shows in console" New topic
Author

Restlets not responding even though request shows in console

gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
Restlet Code

public static void main(String[] args) {

Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
component.getClients().add(Protocol.FILE);


Context ctx = component.getContext();
final Context childCtx = ctx.createChildContext();
Application application = new Application(childCtx) {
@Override
public Restlet createRoot() {
// Create a root router
Router router = new Router(childCtx);

public void handle(Request request, Response response) {
// Print the user name of the requested orders
String message = "Orders of user \""
+ request.getAttributes().get("users") + "\"";
response.setEntity(message, MediaType.TEXT_PLAIN);
}
};

router.attach("/users/{user}", account);
router.attach("/object/", TestServerResource.class);

return router;
}
};

component.getDefaultHost().attach(application);

component.start();
}
}
}

When I use the GUI test tool and submit a GET request the console logs the fact that a request was received but no data is returned. A breakpoint in the handle() method is never hit. The TestServerResource class is never accessed either. I copied this example from the Restlet user guide. I feel like I have entered everything correctly but things just aren't working. Is there an important step that I have missed?

thank you
gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
Here's some more information

I am using WizTools.org RESTClient 3.0

I issue the following GET request

127.0.0.1:8182/users/1 through RESTClient 3.0

The java console shows

Oct 03, 2012 8:40:02 AM com.noelios.restlet.LogFilter afterHandle
INFO: 2012-10-03 08:40:02 127.0.0.1 - - 8182 GET /users/1 - 200 0 - 16 http://127.0.0.1:8182 Apache-HttpClient/4.2.1 (java 1.5)

The RESTClient output shows

Oct 03, 2012 8:40:03 AM org.wiztools.restclient.HTTPClientRequestExecuter execut
e
WARNING: Content-Type header not available in response. Using platform default e
ncoding: windows-1252

The RESTClient 3.0 GUI reports

Content-Length 0
Date: (a date value of the request)
Accept-Ranges bytes
Server Noelios-Restlet-Engine/1.1.10
Connection close
gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
Trying to get this stuff to work on your own is crazy. The pieces and parts presented in the User's Guide are incomplete. I finally located some working source code

http://wiki.restlet.org/docs_2.0/304-restlet/version/default/part/AttachmentData/data/serializationFullSource.zip
gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
OK, I have made some progress since my original problem question post. Here's the new scenario

Server server = new Server(Protocol.HTTP, 8182, new TestServerApplication());
server.start()
// does NOT work
router.attach("/contacts/", ContactServerResource.class); Exception in thread "main" Not Found (404) - Not Found

// does NOT work
router.attach("/contacts/", ContactServerResource.class, Router.MODE_BEST_MATCH); Exception in thread "main" Not Found (404) - Not Found

// works!
router.attachDefault(ContactServerResource.class);

I thought maybe I could try something with Router.createRoute(String, Restlet) but the compiler tells me no such method

I'm stuck now. I'm not sure what else to try. Anybody have any ideas? thank you
 
Don't get me started about those stupid light bulbs.
 
subject: Restlets not responding even though request shows in console