You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Yavuz Kavus <ya...@gmail.com> on 2009/02/04 14:50:08 UTC

Subcontext, filter problem.

hi.

i have a problem and need some assistance.

i want to map an external directory to a tomcat wepapp(virtual directory).

i can achieve this in many ways.
1- adding another context, and setting docbase to my external 
directory(in server.xml)
2- adding a subcontext to 
$CATALINA_BASE/conf/[enginename]/[hostname]/mainApp#mysubContext.xml
3- implementing a filter, checking url, if find mysubContext in the url, 
reading appropriate resource
as a InputStream, and sending read bytes to servlet 
outputstream.(buffering is included)
4- moving external directory to under main app. But this is impossible. 
Because external directory content
size too large. and found on an external disk.

i am currently using the third one. but it is a bit slow and i dont want 
to use a filter
for such a task.

i am trying to add subcontext(second one). But here the problem is, my 
filters/servlets
in main app's deployment descriptor, not called on external directory urls.

example :
*  myapp name is tw. and its jar(tw.jar) is under $CATALINA_BASE/wepapps 
directory.(auto deployment)

* $CATALINA_BASE/conf/Catalina/localhost/tw#repo.xml includes
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="/somedir/someotherdir/" >
</Context>

*$CATALINA_BASE/wepapps/tw/WEB-INF/web.xml includes
...
  <filter>
    <display-name>TestFilter</display-name>
    <filter-name>TestFilter</filter-name>
    <filter-class>tw.filter.TestFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>TestFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>REQUEST</dispatcher>
  </filter-mapping>
...

when i request the /tw/newspaper.gif, filter works. that is good.
but when i request the /tw/repo/clip.gif filter not works.

how can i achieve this?

thanks for any help.
yavuz.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Subcontext, filter problem.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Yavuz Kavus [mailto:yavuzkavus@gmail.com]
> Subject: Re: Subcontext, filter problem.
>
> DefaultServlet caches content of files, length, content types etc.

I suspect the better performance of the DefaultServlet is related to its use of sendfile, not its cache (which persists for only a few seconds).

> i think tomcat should serve resources, under others external
> directories, as a part of main app.

It does, by using the filter mechanism.

> i have serviced document archive(external dir) as a
> sperate context.

Instead of doing that, you could write your own DefaultServlet that subclasses the one provided by Tomcat.  I think the only method you would have to override is getRelativePath().

Alternatively, you could create a softlink to the external directory.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Subcontext, filter problem.

Posted by Yavuz Kavus <ya...@gmail.com>.
DefaultServlet caches content of files, length, content types etc.
i do not cache content of them, everytime a file in the external directory
requested, i simply set response headers, read bytes of the resource, 
and send bytes
to the client. i can cache, but i dont want to write a small server 
integrated in to
tomcat. i have no time not because of me, and i have not such an experience.

i am installing 6.0.18, and will test app on this version, a bit later.

i think tomcat should serve resources, under others external directories,
as a part of main app.
as i know, other servers do that.

think my case:

i have a document archive, whose size is around 400GB. maybe after a year
it will go around 1TB.
it contains, images, pdfs,txts etc. that lots of them should be served 
to client.
it is not possible to move this archive, under main app.
because main app is simply a jar, and updated once a week and
document archive is on an external disk and mobile.

so far, i have serviced document archive(external dir) as a sperate context.
but i should put a security filter in front of document archive.
in this filter, i will use lots of classes from my main app.
i dont want to copy these classes to other context.
Beyond that, the information i use for the security check is in my main 
app's sessions.
perhaps clustering, but doubling memory usage, not an option.

what do you think about that?

thanks a lot.

Caldarale, Charles R yazmış:
>> From: Yavuz Kavus [mailto:yavuzkavus@gmail.com]
>> Subject: Re: Subcontext, filter problem.
>>     
>
>   
>> i am currently using the third one. but it is a bit slow
>> and i dont want to use a filter for such a task.
>>     
>
> There's nothing wrong with using a filter to catch references to the external directory.  The speed of such a filter should be the same as if Tomcat were serving the static resource itself, so there may be a problem in how you've implemented it.  You might want to compare your filter code with that in Tomcat's DefaultServlet to see what the differences are.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Subcontext, filter problem.

Posted by Yavuz Kavus <ya...@gmail.com>.
Caldarale, Charles R yazmış:
>
>> i am currently using the third one. but it is a bit slow
>> and i dont want to use a filter for such a task.
>>     
>
> There's nothing wrong with using a filter to catch references to the external directory.  The speed of such a filter should be the same as if Tomcat were serving the static resource itself, so there may be a problem in how you've implemented it.  You might want to compare your filter code with that in Tomcat's DefaultServlet to see what the differences are.
>
>  - Chuck
>
>   
I think i will override, FileDirContext.protected File file(String name)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Subcontext, filter problem.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: Subcontext, filter problem.
>
> I would instead use a servlet, and map it to the appropriate
> URI prefix.

Yes, that's what I told him to do - extend the DefaultServlet so it can target the external resources and still have the advantages of sendfile and caching already present in DefaultServlet.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Subcontext, filter problem.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Yavuz Kavus [mailto:yavuzkavus@gmail.com]
>> Subject: Re: Subcontext, filter problem.
>>
>> i am currently using the third one. but it is a bit slow and i dont
>> want to use a filter for such a task.
> 
> There's nothing wrong with using a filter to catch references to the
> external directory.

I would instead use a servlet, and map it to the appropriate URI prefix.
Why bother writing your own URI-parsing and recognition code when Tomcat
can do it for you?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmMVAoACgkQ9CaO5/Lv0PBoLwCfSLwXEsZMa6FoQENdIOVkV3b1
zaUAoMMlsxRl2/pOHDyvwGF9NU45Yaqm
=DtSO
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Subcontext, filter problem.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Yavuz Kavus [mailto:yavuzkavus@gmail.com]
> Subject: Re: Subcontext, filter problem.

> i am currently using the third one. but it is a bit slow
> and i dont want to use a filter for such a task.

There's nothing wrong with using a filter to catch references to the external directory.  The speed of such a filter should be the same as if Tomcat were serving the static resource itself, so there may be a problem in how you've implemented it.  You might want to compare your filter code with that in Tomcat's DefaultServlet to see what the differences are.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Subcontext, filter problem.

Posted by Yavuz Kavus <ya...@gmail.com>.
it does not work on apache-tomcat-6.0.18, too.

Caldarale, Charles R yazmış:
>> From: Yavuz Kavus [mailto:yavuzkavus@gmail.com]
>> Subject: Re: Subcontext, filter problem.
>>
>> apache-tomcat-6.0.16
>>     
>
> There were some fixes for multi-level paths that went into 6.0.17.  If possible, install 6.0.18 from tomcat.apache.org and test with that level.
>
>   
>> my filters/servlets in main app's deployment descriptor,
>> not called on external directory urls.
>>     
>
> Nor should they be.  Webapps are, by definition, independent.  There's no such thing as a "sub-context" in the servlet spec, so you can't expect Tomcat to implement such a concept.  The filters for one webapp are completely separate from the filters for another.
>
> You could replace your filter with a <Valve> at the <Host> level, and this would be invoked for all URLs coming through that <Host>.  Valves are Tomcat-specific; don't know if that's important to you.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Subcontext, filter problem.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Yavuz Kavus [mailto:yavuzkavus@gmail.com]
> Subject: Re: Subcontext, filter problem.
>
> apache-tomcat-6.0.16

There were some fixes for multi-level paths that went into 6.0.17.  If possible, install 6.0.18 from tomcat.apache.org and test with that level.

> my filters/servlets in main app's deployment descriptor,
> not called on external directory urls.

Nor should they be.  Webapps are, by definition, independent.  There's no such thing as a "sub-context" in the servlet spec, so you can't expect Tomcat to implement such a concept.  The filters for one webapp are completely separate from the filters for another.

You could replace your filter with a <Valve> at the <Host> level, and this would be invoked for all URLs coming through that <Host>.  Valves are Tomcat-specific; don't know if that's important to you.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Subcontext, filter problem.

Posted by Yavuz Kavus <ya...@gmail.com>.
very sorry.
apache-tomcat-6.0.16

Caldarale, Charles R yazmış:
>> From: Yavuz Kavus [mailto:yavuzkavus@gmail.com]
>> Subject: Subcontext, filter problem.
>>     
>
>   
>> how can i achieve this?
>>     
>
> For the gazillionth time, TELL US WHAT VERSION OF TOMCAT YOU'RE USING!!!!
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Subcontext, filter problem.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Yavuz Kavus [mailto:yavuzkavus@gmail.com]
> Subject: Subcontext, filter problem.

> how can i achieve this?

For the gazillionth time, TELL US WHAT VERSION OF TOMCAT YOU'RE USING!!!!

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org