Simple question about mapping one URL to another

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

Simple question about mapping one URL to another

Andres C. Rodriguez

Hi,

I recently had a small issue with Jetty.  I was trying to make the
server (with no web app involved) respond to one URL with a certain
file.  For example:

css/simple.css --> c:\my-complicated-path\my-complicated-name.css

I could not find a way to do it.  At the end I came up with the
following Handler, that although very simple, begs the question wether
this functionality is already supported in Jetty or not.  Could the
gurus please advice wether I am doing the correct thing?  Note that my
handler does not completely solve my problem, since I am really mapping
from one URL to another, not to a file.

Thanks,


Andres C. Rodriguez


-----

class RedirectorResourceHandler extends ResourceHandler {
     private static final long serialVersionUID = 1594126495011129446L;
     private Map<String,String> map = new HashMap<String,String>();
     public void map(String from, String to) { map.put(from,to); }
     public void handle(String pathInContext,
                        String pathParams,
                        HttpRequest request,
                        HttpResponse response)
       throws HttpException, IOException {
         String redirPath = map.get(pathInContext);
         handle(redirPath == null? pathInContext : redirPath,
                pathParams, request, response);
     }
}



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Simple question about mapping one URL to another

Greg Wilkins-5

I'm not sure I understand your question?
You say you want to map from one URL to another, but it looks
like you are really trying to map a URL to a file name.

If so, then ResourceHandler is what you want - although it
normally maps a URL space to a directory.

You might want to extend ResourceHandler and implement
getResource to simplify things.

regards



Andres C. Rodriguez wrote:

>
> Hi,
>
> I recently had a small issue with Jetty.  I was trying to make the
> server (with no web app involved) respond to one URL with a certain
> file.  For example:
>
> css/simple.css --> c:\my-complicated-path\my-complicated-name.css
>
> I could not find a way to do it.  At the end I came up with the
> following Handler, that although very simple, begs the question wether
> this functionality is already supported in Jetty or not.  Could the
> gurus please advice wether I am doing the correct thing?  Note that my
> handler does not completely solve my problem, since I am really mapping
> from one URL to another, not to a file.
>
> Thanks,
>
>
> Andres C. Rodriguez
>
>
> -----
>
> class RedirectorResourceHandler extends ResourceHandler {
>     private static final long serialVersionUID = 1594126495011129446L;
>     private Map<String,String> map = new HashMap<String,String>();
>     public void map(String from, String to) { map.put(from,to); }
>     public void handle(String pathInContext,
>                        String pathParams,
>                        HttpRequest request,
>                        HttpResponse response)
>       throws HttpException, IOException {
>         String redirPath = map.get(pathInContext);
>         handle(redirPath == null? pathInContext : redirPath,
>                pathParams, request, response);
>     }
> }
>
>
>
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support