Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat 'internal URL rewrite' strategies

 
Stu Thompson
Hooplehead
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    William Brogden
    Author and all-around good cowpoke
    Rancher
    Posts: 13071
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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 ]
     
    Stu Thompson
    Hooplehead
    Ranch Hand
    Posts: 136
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 13071
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 136
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 13071
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    "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
    Posts: 136
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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 ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic