File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Tomcat 'internal URL rewrite' strategies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat Watch "Tomcat New topic
Author

Tomcat 'internal URL rewrite' strategies

Stu Thompson
Hooplehead
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
Hi all,

I know what I want to do, but not how to do it. After looking at some stuff on the net (like UrlRewriteFilter) nothing seems to be what I want. Maybe I just don't know what to call it. Maybe there is something native to tomcat that does this. I just don't know. Here is how it should work:

  • Browser requests http://myServer.com/myWebApp/virtualUrlPrefix/longAndNonSequentialString
  • This maps to {tomcat}/webapps/myWebApp/
  • my web.xml matches virtualUrlPrefix to a set of logic,
  • and this set of logic resolves longAndNonSequentialString to a path like {tomcat}/webapps/myWebApp/WEB-INF/privateData/1/2/3.
  • All of the data in this content directory would be static flat files.
  • There cannot be any interaction with the browser, like HTTP redirection.
  • It must 'scale'.


  • Any thoughts?

    Thanks in advance!

    Stu
    [ November 20, 2006: Message edited by: Stu Thompson ]

    "This is not to say that design is unnecessary. But after a certain point, design is just speculation." --Philip Chu
    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12675
        
        5
    Sounds like REST to me ;) Short REST summary.
    A google search for "REST servlet" turned up some possibilities.

    As I understand it, your initial servlet at myWebApp can get the additional data with the getQueryString() (or maybe its the getPathInfo()) method and then parse that and serve the file all in one go without doing any redirect.


    Bill

    [ November 20, 2006: Message edited by: William Brogden ]
    [ November 20, 2006: Message edited by: William Brogden ]

    Java Resources at www.wbrogden.com
    Stu Thompson
    Hooplehead
    Ranch Hand

    Joined: Jun 14, 2006
    Posts: 136
    Hi,

    Thanks! I had come across REST in the past, and part of my implementation plans include an RSS feed for the content, of which Atom is apparently 'RESTful', so will keep in mind.

    But what I don't understand is the actual implementation mechanics with JSP/Servlets. No query strings, so like you say my plans would use something like getPathInfo(), parsing the raw HTTP GET, etc. But that is the easy part.

    How do I tell Tomcat to return the existing static content in an "off-line" folder?

    Thanks again,

    Stu
    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12675
        
        5
    How do I tell Tomcat to return the existing static content in an "off-line" folder?

    The default Tomcat server - that normally serves plain html, etc. is not allowed to serve content from "off-line" folders.

    This is not really a problem, your servlet will just have take over these duties by reading the files and sending the content in the response. The only tricky bits will be getting the headers right for various content types - see the default servlet code for starters.

    Bill
    Stu Thompson
    Hooplehead
    Ranch Hand

    Joined: Jun 14, 2006
    Posts: 136
    Hi Bill,

    Ho, hum...not what I wanted to hear but it was half expected.

    I am a bit sceptical about a read-n-spew approach...specifically my ability to code something ability to perform in the same league as Tomcat itself. A lot of people smarter than myself have put considerable time and effort into tomcat static file serving performance.

    Thanks anyways!

    Stu
    [ November 21, 2006: Message edited by: Stu Thompson ]
    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12675
        
        5
    "read and spew"
    Actually it is no big deal to get performance with a decent size byte[] to read the file into and write the file out of. Getting the headers right to match the file type is the real pain.

    Bill
    Stu Thompson
    Hooplehead
    Ranch Hand

    Joined: Jun 14, 2006
    Posts: 136
    OK, a related project has come up that requires read-n-spew Time to learn loads about java.io. Lucky me, my content is limited and I have control over it--setting content type headers will be easy.

    Thanks!

    Stu
    [ November 22, 2006: Message edited by: Stu Thompson ]
     
    Don't get me started about those stupid light bulbs.
     
    subject: Tomcat 'internal URL rewrite' strategies
     
    Similar Threads
    Tomcat installation on Windows2000 Server
    Context Root in TomCat
    Configuring tomcat 6 with eclipse to serve servlets and jsp/html.
    UnpackWAR
    Getting Tomcat to recognize directory