title: Restlet Router Relative Path Error
body: <p>I am having an opposite error of what's written <a href="https://stackoverflow.com/questions/5728004/not-found-404-error-in-restlet">here</a>.</p>
  
  <p>I'm just trying to run a very simple sample application of Restlet in Eclipse.</p>
  
  <p><strong>MailServerApplication.java</strong></p>
  
  <pre><code>public class MailServerApplication extends Application {
  
      /**
       * Launches the application with an HTTP server.
       * 
       * @param args
       *            The arguments.
       * @throws Exception
       */
      public static void main(String[] args) throws Exception {
          Server mailServer = new Server(Protocol.HTTP, 8111);
          mailServer.setNext(new MailServerApplication());
          mailServer.start();
      }
  
      /**
       * Constructor.
       */
      public MailServerApplication() {
          setName("RESTful Mail Server");
          setDescription("Example for 'Restlet in Action' book");
          setOwner("Restlet S.A.S.");
          setAuthor("The Restlet Team");
      }
  
      /**
       * Creates a root Router to dispatch call to server resources.
       */
      @Override
      public Restlet createInboundRoot() {
          Router router = new Router(getContext());
          router.attach("http://localhost:8111/", 
                  RootServerResource.class);
          router.attach("http://localhost:8111/accounts/",
                  AccountsServerResource.class);
          router.attach("http://localhost:8111/accounts/{accountId}",
                  AccountServerResource.class);
          return router;
      }
  }
  </code></pre>
  
  <p><strong>RootServerResource.java</strong></p>
  
  <pre><code>public class RootServerResource 
      extends ServerResource implements RootResource {
  
      public String represent() {
          return "This is the root resource";
      }
  
      public String describe() {
          throw new RuntimeException("Not yet implemented");
      }
  }
  </code></pre>
  
  <p><strong>RootResource.java</strong></p>
  
  <pre><code>/**
   * Root resource.
   */
  public interface RootResource {
  
      /**
       * Represents the application root with a welcome message.
       * 
       * @return The root representation.
       */
      @Get("txt")
      public String represent();
  
  }
  </code></pre>
  
  <p>The code works perfectly as is if I'm running the server locally and if I type the full uri including the localhost on my browser "localhost:8111". However, as soon as I change my router declaration to be router, the page always throws a 404 error.</p>
  
  <pre><code>@Override
  public Restlet createInboundRoot() {
      Router router = new Router(getContext());
      router.attach("/", RootServerResource.class); 
      router.attach("/accounts/", AccountsServerResource.class);
      router.attach("/accounts/{accountId}", AccountServerResource.class);
      return router;
  }
  </code></pre>
  
  <p>So in other words, if I attach a full path including the http and the ip address to the router, it works correctly but the relative path doesn't.</p>
  
  <p>This is pretty bizzare. If there's any error, I would've assumed that the relative definition should work and the localhost definition shouldn't, but what I'm experiencing is the exact opposite. Any suggestions?</p>
  
  <p>Edit:</p>
  
  <p>Upon request, I'm including my AccountServerResource.class</p>
  
  <pre><code>/**
   * Implementation of a mail account resource.
   */
  public class AccountServerResource extends ServerResource implements
          AccountResource {
  
      /** The account identifier. */
      private int accountId;
  
      /**
       * Retrieve the account identifier based on the URI path variable
       * "accountId" declared in the URI template attached to the application
       * router.
       */
      @Override
      protected void doInit() throws ResourceException {
          this.accountId = Integer.parseInt(getAttribute("accountId"));
      }
  
      public String represent() {
          return AccountsServerResource.getAccounts().get(this.accountId);
      }
  
      public void store(String account) {
          AccountsServerResource.getAccounts().set(this.accountId, account);
      }
  
      public void remove() {
          AccountsServerResource.getAccounts().remove(this.accountId);
      }
  }
  </code></pre>
  
  <p>And the AccountResource interface:</p>
  
  <pre><code>/**
   * User account resource.
   */
  public interface AccountResource {
  
      /**
       * Represents the account as a simple string with the owner name for now.
       * 
       * @return The account representation.
       */
      @Get("txt")
      public String represent();
  
      /**
       * Stores the new value for the identified account.
       * 
       * @param account
       *            The identified account.
       */
      @Put("txt")
      public void store(String account);
  
      /**
       * Deletes the identified account by setting its value to null.
       */
      @Delete
      public void remove();
  
  }
  </code></pre>