Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8775823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:54:02+00:00 2026-06-13T18:54:02+00:00

Prototyping with Restlet 2.1.0, Java SE version, I am having trouble mapping ServerResource classes

  • 0

Prototyping with Restlet 2.1.0, Java SE version, I am having trouble mapping ServerResource classes to urls. I’ve tried quite a few variations using the Router.attach method, but nothing has worked.

My current code looks like this:

/**
 * @param args
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    final Router router = new Router();
    router.attach("/hello", FirstServerResource.class);
    router.attach("/json", Json.class);

    Application myApp = new Application() {
        @Override
        public org.restlet.Restlet createInboundRoot() {
            router.setContext(getContext());
            return router;
        };
    };

    new Server(Protocol.HTTP, 8182, myApp).start();
}

When I browse to http://localhost:8182/hello it doesn’t do the template match correctly. Debugging through the source code, I see what happens is that the match logic sees the requested resource as http://localhost:8182/hello instead of just /hello. The Restlet code where this happens is here:

// HttpInboundRequest.java
// Set the resource reference
if (resourceUri != null) {
    setResourceRef(new Reference(getHostRef(), resourceUri));

    if (getResourceRef().isRelative()) {
        // Take care of the "/" between the host part and the segments.
        if (!resourceUri.startsWith("/")) {
            setResourceRef(new Reference(getHostRef().toString() + "/"
                    + resourceUri));
        } else {
            setResourceRef(new Reference(getHostRef().toString()
                    + resourceUri));
        }
    }

    setOriginalRef(getResourceRef().getTargetRef());
}

In the code above, it sees the Resource as relative, and therefore changes the requested resource from /hello to the full url. I’m missing something obvious here, but I’m totally stumped.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:54:04+00:00Added an answer on June 13, 2026 at 6:54 pm

    Finally found the solution by turning on the logging (FINE). I saw this log message:

    By default, an application should be attached to a parent component in
    order to let application’s outbound root handle calls properly.

    I don’t totally understand what it meant (maybe I have to read docs start to finish?). Attaching the application to a VirtualHost fixed the problem:

    public static void main(String[] args) throws Exception {   
        final Router router = new Router();
        router.attach("/hello", FirstServerResource.class);
        router.attach("/json", Json.class);
        router.attachDefault(Default.class);
    
        Application myApp = new Application() {
            @Override
            public org.restlet.Restlet createInboundRoot() {
                router.setContext(getContext());                
                return router;
            };
        };
    
    
        Component component = new Component();
        component.getDefaultHost().attach("/test", myApp);
    
        new Server(Protocol.HTTP, 8182, component).start();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm prototyping a game using the Bresenham algorithm for player movement. I used the
I'm prototyping a concurrent/distributed system in Java. When a process is terminated (e.g. ctrl+c
I'm prototyping a thin client UI using extjs and am looking for an effect
I'm busy prototyping a training management app using the DevExpress eXpressApp framework & Domain
I have been using Turbogears 1 for prototyping small sites for the last couple
I am in the process of prototyping a web application using ruby on rails.
I'm prototyping a simple RPC server in Java for an internal application. While eventually
I'm using Joshua Gatcke's 99Lime HTML Kickstart framework for prototyping. It uses an implementation
I'm prototyping GUI layout with PyGTK, sometimes using glade/builder sometimes not, and the following
I'm using Haml as a quick way of prototyping layouts. This is not using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.