Manually setting the base URL in Restlet

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Manually setting the base URL in Restlet

Hannes Ebner
Hi,

I have a Restlet application running in Tomcat, proxied through Apache. Only Apache can be reached from the outside.

Internally I'm using the OpenID extension to perform authentication, which causes problems in the given reverse proxy setting. The OpenID extension asks Restlet for the base URL to set the realm, and Restlet of course only knows its URL via Tomcat, which in turn does not know that it is being proxied.
This means that the application is reached from the outside via https://base/app, but Restlet and OpenID think that it is http://base:8080/something which does not work with all the necessary redirects in the OpenID flow.

I tried really hard to find a way of telling Restlet (and the OpenID extension) to use a base URL that is different from the one that Tomcat reports, but still, I ended up asking for help on this list.

Can the base URL be manually set somehow?

Best regards,
Hannes
Reply | Threaded
Open this post in threaded view
|

Re: Manually setting the base URL in Restlet

Thierry Boileau-4
Hello Hannes,


did you try to set the request's resourceRef, for example by using a filter?
For example, the client hits "http://localhost:8182/test?querypart", but the application is routed on "http://localhost:8182/app/test"
The filter leverages the remaining part of the request's reference, which is updated by each router that the request meets before hitting the target resource.

@Override
public Restlet createInboundRoot() {
    final Router router = new Router(getContext());
    router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
    router.attach("/app/test", TestResource.class);

    Filter filter = new Filter(getContext(), router) {
        @Override
        protected int beforeHandle(Request request, Response response) {
            Reference ref = request.getResourceRef();
            ref.setIdentifier("http://localhost/app" + ref.getRemainingPart());
            ref.setBaseRef("http://localhost");
            return super.beforeHandle(request, response);
        }
   };
   return filter;
}


I'm not sure it solves exactly your problem, but it can gives you some ideas.

Best regards,
Thierry Boileau





2013/12/6 Hannes Ebner <[hidden email]>
Hi,

I have a Restlet application running in Tomcat, proxied through Apache. Only Apache can be reached from the outside.

Internally I'm using the OpenID extension to perform authentication, which causes problems in the given reverse proxy setting. The OpenID extension asks Restlet for the base URL to set the realm, and Restlet of course only knows its URL via Tomcat, which in turn does not know that it is being proxied.
This means that the application is reached from the outside via https://base/app, but Restlet and OpenID think that it is http://base:8080/something which does not work with all the necessary redirects in the OpenID flow.

I tried really hard to find a way of telling Restlet (and the OpenID extension) to use a base URL that is different from the one that Tomcat reports, but still, I ended up asking for help on this list.

Can the base URL be manually set somehow?

Best regards,
Hannes

Reply | Threaded
Open this post in threaded view
|

Re: Manually setting the base URL in Restlet

Hannes Ebner
Hi Thierry,

that's exactly what I needed, thanks!

Best regards,
Hannes

On Mon, Dec 9, 2013 at 11:12 AM, Thierry Boileau <[hidden email]> wrote:
Hello Hannes,


did you try to set the request's resourceRef, for example by using a filter?
For example, the client hits "http://localhost:8182/test?querypart", but the application is routed on "http://localhost:8182/app/test"
The filter leverages the remaining part of the request's reference, which is updated by each router that the request meets before hitting the target resource.

@Override
public Restlet createInboundRoot() {
    final Router router = new Router(getContext());
    router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
    router.attach("/app/test", TestResource.class);

    Filter filter = new Filter(getContext(), router) {
        @Override
        protected int beforeHandle(Request request, Response response) {
            Reference ref = request.getResourceRef();
            ref.setIdentifier("http://localhost/app" + ref.getRemainingPart());
            ref.setBaseRef("http://localhost");
            return super.beforeHandle(request, response);
        }
   };
   return filter;
}


I'm not sure it solves exactly your problem, but it can gives you some ideas.

Best regards,
Thierry Boileau





2013/12/6 Hannes Ebner <[hidden email]>
Hi,

I have a Restlet application running in Tomcat, proxied through Apache. Only Apache can be reached from the outside.

Internally I'm using the OpenID extension to perform authentication, which causes problems in the given reverse proxy setting. The OpenID extension asks Restlet for the base URL to set the realm, and Restlet of course only knows its URL via Tomcat, which in turn does not know that it is being proxied.
This means that the application is reached from the outside via https://base/app, but Restlet and OpenID think that it is http://base:8080/something which does not work with all the necessary redirects in the OpenID flow.

I tried really hard to find a way of telling Restlet (and the OpenID extension) to use a base URL that is different from the one that Tomcat reports, but still, I ended up asking for help on this list.

Can the base URL be manually set somehow?

Best regards,
Hannes