You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jspwiki.apache.org by Brian Burch <br...@PingToo.com> on 2008/12/04 23:18:36 UTC
Displaying images outside the webapp container
I am running jspWiki 2.8.1 under tomcat 5.5.27, on an ubuntu linux system.
I have successfully used the ImpagePlugin and SlideShowPlugin to display
digital photos WITHIN the webapp directory path. I think I understand
how they generate inline url's within the web page, so that the browser
issues an HTTP GET for the individual image files. This means that
tomcat, not jspWiki, will be responsible for delivering the individual
image files.
I have LOADS of photo's in a directory hierarchy which is outside the
tomcat directory structure. I don't want to move this huge hierarchy
inside the jspWiki container because it simply isn't the right place for it.
I've created a symlink for the root of my photos directory, e.g.
ln -s /real/path/to/my/photos/ /tomcat-home/webapps/wiki/files/photos
My photos can be found with system commands, e.g. both
ls -l /real/path/to/my/photos/2008/November/DSCF0123.JPG
ls -l /tomcat-home/webapps/wiki/files/photos/2008/November/DSCF0123.JPG
work fine.
However, when my wiki page uses either plugin with
src='files/photos/2008/November/DSCF0123.JPG,
the image file is not displayed. When I view the page source, the url
for the <img> src url appears to be fine.
This a known tomcat issue - that it will not follow a symlinked
directory by default.
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
says to define a context.xml in the webapp META-INF directory. Mine
simply contains <context allowLinking="true"/>, because the
documentation recommends NOT specifying docBase.
The tomcat log says:
INFO: default: DefaultServlet.serveResource: Serving resource
'/files/pictures/2008/11-lateAutumn/DSCF2686.JPG' headers and data
This looks suspicious to me - the url has a leading slash, rather than
relative to the webapp docBase, and tomcat doesn't serve up the image
file! Presumably, I've missed an important detail.
Any quick words of wisdom would be appreciated.
Brian
Re: Displaying images outside the webapp container (SOLVED)
Posted by Brian Burch <br...@PingToo.com>.
Hassan Schroeder wrote:
>
>> The only problem is that every other webapp under the same Host will
>> now be allowed to follow symlinks, so I need to work out how to
>> restrict the permission to only jspWiki.
>
> ? allowLinking is a Context attribute, not a Host attribute.
Well, sort of... you have to create a context xml file in
$CATALINA_HOME/conf/[engine-name]/[host-name]/[context-path].xml
I have just added a new section on this topic to the Tomcat FAQ in the wiki.
http://www.jspwiki.org/wiki/Tomcat#section-Tomcat-HowToAccessFilesOutsideTheWebappContainer
I have also put a link to it from the FAQAdministration page.
Regards,
Brian
Re: Displaying images outside the webapp container (SOLVED)
Posted by Hassan Schroeder <ha...@webtuitive.com>.
Brian Burch wrote:
> I added allowLinking="true" to the auto-deploy context and MY SYMLINKED
> IMAGE DISPLAYED!
Ah, yeah, you should have deleted that file first, so the one from
META-INF would be used (copied over) :-)
> The only problem is that every other webapp under the same Host will now
> be allowed to follow symlinks, so I need to work out how to restrict the
> permission to only jspWiki.
? allowLinking is a Context attribute, not a Host attribute.
--
Hassan Schroeder ----------------------------- hassan@webtuitive.com
Webtuitive Design === (+1) 408-621-3445 === http://webtuitive.com
dream. code.
Re: Displaying images outside the webapp container (SOLVED)
Posted by Brian Burch <br...@PingToo.com>.
Brian Burch wrote:
>
> The DefaultServlet logs that it has inserted a leading forward slash,
> but I now think this is misleading.
>
> I created two folders side by side. files/pictures/ is a symlink and
> files/pictures-local/ is a real folder. View source for both image urls
> is equivalent (both without leading slash), and the DefaultServlet log
> entries are also equivalent (both with leading slash). The only
> difference is that the non-symlink image displays while the symlink one
> does not.
>
> I think the most likely explanation is that my META-INF/context.xml is
> applied to the jspWiki webapp, but tomcat is scheduling the
> DefaultServlet to find the image. If I am right, I will need to apply
> allowLinking to the DefaultServlet, or possibly the entire tomcat Host.
My deduction was not correct. The DefaultServlet is running in the
context of the jspWiki webapp, which is why it is able to find and
deliver the files/pictures-local/ image.
This meant it was not finding the symlinked image because my
META-INF/context.xml file was being ignored.
I read the tomcat docs again. My Host is configured to auto-deploy its
webapps. Auto-deployment uses the $CATALINA_HOME/conf/context.xml file
and so I presume the META-INF/context.xml file is never processed, or is
too late because the Context is already created.
I added allowLinking="true" to the auto-deploy context and MY SYMLINKED
IMAGE DISPLAYED!
The only problem is that every other webapp under the same Host will now
be allowed to follow symlinks, so I need to work out how to restrict the
permission to only jspWiki.
Once I have sorted out the details, I will transfer this knowledge to
the wiki for anyone else who wants to do the same thing.
Brian
Re: Displaying images outside the webapp container
Posted by Brian Burch <br...@PingToo.com>.
Hassan Schroeder wrote:
> Brian Burch wrote:
>
>> This a known tomcat issue - that it will not follow a symlinked
>> directory by default.
>> http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
>> says to define a context.xml in the webapp META-INF directory. Mine
>> simply contains <context allowLinking="true"/>, because the
>> documentation recommends NOT specifying docBase.
>
> Is that a typo? Because it's <Context..., not <context...
You are correct. Tomcat/jspWiki are running on another machine and I was
too lazy to copy the file to this one. My live file has <Context
allowLinking="true"/> (i.e. without docBase).
>> INFO: default: DefaultServlet.serveResource: Serving resource
>> '/files/pictures/2008/11-lateAutumn/DSCF2686.JPG' headers and data
>>
>> This looks suspicious to me - the url has a leading slash, rather than
>> relative to the webapp docBase, and tomcat doesn't serve up the image
>> file! Presumably, I've missed an important detail.
>
> You did say the 'view source' URL was correct, yes?
The view source shows me this section of html inserted by the ImagePlugin:-
<p>Try to get a thumbnail via my new symlink...
<table border="0" class="imageplugin" style="margin-left: auto;
margin-right: auto;">
<tr><td><a href="files/pictures/2008/11-lateAutumn/03112008016.JPG"><img
src="files/pictures/2008/11-lateAutumn/.ginp/100-03112008016.JPG"
/></a></td></tr>
</table>
</p>
The DefaultServlet logs that it has inserted a leading forward slash,
but I now think this is misleading.
I created two folders side by side. files/pictures/ is a symlink and
files/pictures-local/ is a real folder. View source for both image urls
is equivalent (both without leading slash), and the DefaultServlet log
entries are also equivalent (both with leading slash). The only
difference is that the non-symlink image displays while the symlink one
does not.
I think the most likely explanation is that my META-INF/context.xml is
applied to the jspWiki webapp, but tomcat is scheduling the
DefaultServlet to find the image. If I am right, I will need to apply
allowLinking to the DefaultServlet, or possibly the entire tomcat Host.
Thanks for your comments.
Brian
Re: Displaying images outside the webapp container
Posted by Hassan Schroeder <ha...@webtuitive.com>.
Brian Burch wrote:
> This a known tomcat issue - that it will not follow a symlinked
> directory by default.
> http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
> says to define a context.xml in the webapp META-INF directory. Mine
> simply contains <context allowLinking="true"/>, because the
> documentation recommends NOT specifying docBase.
Is that a typo? Because it's <Context..., not <context...
> INFO: default: DefaultServlet.serveResource: Serving resource
> '/files/pictures/2008/11-lateAutumn/DSCF2686.JPG' headers and data
>
> This looks suspicious to me - the url has a leading slash, rather than
> relative to the webapp docBase, and tomcat doesn't serve up the image
> file! Presumably, I've missed an important detail.
You did say the 'view source' URL was correct, yes?
--
Hassan Schroeder ----------------------------- hassan@webtuitive.com
Webtuitive Design === (+1) 408-621-3445 === http://webtuitive.com
dream. code.