This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restlets not responding even though request shows in console

 
gilbert engle
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic