• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat 8 - Convert Tomcat 7 "aliases=..."

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm upgrading a Tomcat version 7 environment to version 8.
The version 7 configuration contains:

In file: context.xml -

<Context
aliases="/pix=m:/$Media/Pix,/pixThm=m:/$Media/PixThm">

Which allows, for exampke, such requests as:

<ipaddress>/pix/<resourceid>

I don't see where/how to use the new <Resources> xml element to duplicate this function.

Please help!
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, that's horrible.

This mechanism is a flaunting of the concept that J(2)EE web applications should be self-contained. That is, all of the resources are located within a single WAR.

Historically, if you really needed to cheat on that idea (say, in order to share the same static content between one or more Tomcat apps and/or other servers such as Apache), you'd patch the deployed WAR to use a symlink and make sure that Tomcat was configured to allow symlink usage (by default, it isn't, for security reasons).

Apparently some people got creative in Tomcat 7 and added stuff like "aliases".

By Tomcat 8, they realized that they'd opened a can of worms and attempted to make it less of a hack, using Resources. For details: https://tomcat.apache.org/migration-8.html

Essentially, if you MUST use this feature, you'd need to map a physical location to a webapp's logical location, much as the Apache server's Alias command does. In the simplest case, that means defining a "base" attribute and a "webappMount" attribute. If I'm reading things properly, you need to do that on a "PreResources" sub-element to a Context's Resources element.

Unless you've got a really compelling reason, however, I don't recommend doing this. It's tying your application to not only being Tomcat-specific, but also requires extra care in the setup of the server and deployment information. Better to simply make the WAR self-sufficient if you can, either by putting the resources in the WAR itself or in the case of static content, by using URLs that pull from a master static content server.
 
Paul Dickler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,
Thanks for the heads-up on the inadvisability of this, but I've got a simple setup that suits my purposes, as is.
I just would like someone to show me how to do it.
I've tried several configurations (in V8), but can't get it to go.
An example would be great if you can point me there.

Paul
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's probably just because I'm a jerk about such things, but "simple" and "requires a specific release of a specific product" aren't words I use together. Then again, I get my jollies from creating nice tight solutions that work under the general standards and thumbing my nose at the vendors who want to lock me in to their specialized solutions.

Tomcat's doesn't have a whole lot of secondary documentation so you're probably going to have to go googling after blogs.

In theory, it's straightforward: you have the following structure:


Repeat PreResources (and possibly Resource) as needed. Each PreResource maps an absolute filesystem location to a webapp resource path. Which is what I'm presuming you want to do.

The old brute-force standards-compliant equivalent to this was that you'd map the resource path to a servlet, the servlet would open and copy the selected resource from its external filesystem location to the HttpResponse stream - decorated, of course with stuff like content-type headers and such. As far as I know, no one ever even bothered to write a library function to do that. Just dashed them out from scratch as needed. Works on everything from at least Tomcat 3 on up plus WebSphere, WebLogic, jetty, JBoss/WildFly, JoNaS, etc., etc., etc.
 
Paul Dickler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, finally got it:

In file "context.xml" I coded the following...

<Context>
<Resources className="org.apache.catalina.webresources.StandardRoot" >

<PreResources webAppMount="/pix" base="m:\\$media\\pix"
className="org.apache.catalina.webresources.DirResourceSet" />
</Resources>
</Context>

Now, all is well.
Thanks for your prompt attention to this.

Paul

 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic