This discussion is archived
0 Replies Latest reply: Oct 19, 2012 4:36 AM by 965904 RSS

router.attach(String, Class<? extends ServerResource>) not working properly

965904 Newbie
Currently Being Moderated
I am having getting router.attach() to work properly


Server server = new Server(Protocol.HTTP, 8182, new TestServerApplication());
server.start()

Here's the code that's in the client
ClientResource clientResource = new ClientResource(
"http://localhost:8182/contacts/123");
The following code does NOT work

router.attach("/contacts/123", ContactServerResource.class);

Exception in thread "main" Not Found (404) - Not Found
The following code does NOT work

router.attach("/contacts/123", ContactServerResource.class, Router.MODE_BEST_MATCH);
Exception in thread "main" Not Found (404) - Not Found
* using attachDefault results in the call being handled properly

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


I also tried something different rather than using a Server.

Component component = new Component();

// Add a new HTTP server listening on port 8182.
component.getServers().add(Protocol.HTTP, 8182);

// Attach the sample application.
component.getDefaultHost().attach("/contacts/123",
new TestServerApplication());

component.start();
In this case router.attach("/contacts/123", ContactServerResource.class) is still called and it still fails to work. You have to attachDefault() to get it to work

I can't think of anything else to try. Anybody have any ideas? thank you

java

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points