You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Chris Cheshire <ya...@gmail.com> on 2017/12/08 18:49:28 UTC

context resources, replacement parameters

I have a directory resource set defined in my context.xml to handle images :

<Resources>
  <PreResources className="org.apache.catalina.webresources.DirResourceSet"
                base="${catalina.base}/cdn/p/images"
                webAppMount="/images" />
</Resources>

The /p in there actually represents the context path - a given sandbox
might have the same webapp deployed at different context paths
representing different development branches. Is it possible to use a
replacement parameter similar to catalina.base to replace the context
path the webapp is deployed at?

I tried following the source through for DirResourceSet but couldn't
see where even catalina.base is getting replaced.

(I know ant is a solution and I eventually need it for other things
too, but I have never used it and it's not a learning rabbit-hole I
can go down right now)

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


Re: context resources, replacement parameters

Posted by Mark Thomas <ma...@apache.org>.
On 11/12/17 19:12, Chris Cheshire wrote:
> I thought more about this over the weekend, and realised it is more
> hassle than it is worth, and not because I don't want to do it. I
> don't think it is actually feasible now that I think about it more.
> 
> Given that a JVM has one set of System.properties and one instance of
> Tomcat can have multiple deployed contexts, I can't just inject a
> single property. It would have to be mapped to some other value unique
> to the context. Thus it is starting to look more like a "tail wagging
> the dog" exercise, when I should just accept editing the config files
> manually for now until I can get around to figuring ant out and
> building them dynamically.

Happy to park this if you want but I think it should be possible for
Tomcat to inject a property (e.g. org.apache.tomcat.contextPath) with
the correct value for the current context. i.e. you use that value
everywhere and Tomcat ensures that the replacement value is correct for
each context.

Feel free to create a Bugzilla issue for this if you think it could be
helpful.

Mark


> 
> On Sat, Dec 9, 2017 at 11:19 AM, Mark Thomas <ma...@apache.org> wrote:
>> On 08/12/17 22:13, Chris Cheshire wrote:
>>> On Fri, Dec 8, 2017 at 3:36 PM, Mark Thomas <ma...@apache.org> wrote:
>>>> On 08/12/17 18:49, Chris Cheshire wrote:
>>>>> I have a directory resource set defined in my context.xml to handle images :
>>>>>
>>>>> <Resources>
>>>>>   <PreResources className="org.apache.catalina.webresources.DirResourceSet"
>>>>>                 base="${catalina.base}/cdn/p/images"
>>>>>                 webAppMount="/images" />
>>>>> </Resources>
>>>>>
>>>>> The /p in there actually represents the context path - a given sandbox
>>>>> might have the same webapp deployed at different context paths
>>>>> representing different development branches. Is it possible to use a
>>>>> replacement parameter similar to catalina.base to replace the context
>>>>> path the webapp is deployed at?
>>>>
>>>> Yes. You can use ant style property replacement in any XML file that is
>>>> processed by the digester (server.xml, context.xml, web.xml)
>>>>
>>>> See the opening section of
>>>>
>>>> http://tomcat.apache.org/tomcat-9.0-doc/config/index.html
>>>>
>>>> for details.
>>>>
>>>> Mark
>>>>
>>>
>>> I logged the System properties and there is nothing in there for the
>>> context path.
>>
>> Sorry, I didn't quite understand what you were asking. This isn't
>> possible out of the box.
>>
>> Injecting a special property (org.apache.tomcat.contextPath ?) should be
>> doable when working with context specific configuration files -
>> context.xml and web.xml - although there might be some edge cases with
>> context.xml since sometimes the context path is set in the file. I think
>> they can be handled with some documentation.
>>
>> Care to create an enhancement request? Better still, how do you fancy
>> taking a stab at a patch? We can give you some pointers to get started
>> if required.
>>
>> Mark
>>
>>
>>>
>>> In catalina logs I see
>>>
>>> 08-Dec-2017 22:02:05.532 INFO [ajp-nio-8019-exec-1]
>>> org.apache.catalina.core.ApplicationContext.log HTMLManager: restart:
>>> Reloading web application '/p'
>>> 08-Dec-2017 22:02:05.533 INFO [ajp-nio-8019-exec-1]
>>> org.apache.catalina.core.StandardContext.reload Reloading Context with
>>> name [/p] has started
>>> 08-Dec-2017 22:02:14.596 INFO [ajp-nio-8019-exec-1]
>>> org.apache.catalina.core.StandardContext.reload Reloading Context with
>>> name [/p] is completed
>>>
>>> It seems catalina knows the value of the context path for the webapp
>>> when context.xml is being digested. Should I post an RFE on BZ to have
>>> it added to the system properties, or am I incorrect in this
>>> assumption?
>>>
>>>
>>>
>>>>
>>>>>
>>>>> I tried following the source through for DirResourceSet but couldn't
>>>>> see where even catalina.base is getting replaced.
>>>>>
>>>>> (I know ant is a solution and I eventually need it for other things
>>>>> too, but I have never used it and it's not a learning rabbit-hole I
>>>>> can go down right now)
>>>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
> 
> ---------------------------------------------------------------------
> 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: context resources, replacement parameters

Posted by Chris Cheshire <ya...@gmail.com>.
I thought more about this over the weekend, and realised it is more
hassle than it is worth, and not because I don't want to do it. I
don't think it is actually feasible now that I think about it more.

Given that a JVM has one set of System.properties and one instance of
Tomcat can have multiple deployed contexts, I can't just inject a
single property. It would have to be mapped to some other value unique
to the context. Thus it is starting to look more like a "tail wagging
the dog" exercise, when I should just accept editing the config files
manually for now until I can get around to figuring ant out and
building them dynamically.

On Sat, Dec 9, 2017 at 11:19 AM, Mark Thomas <ma...@apache.org> wrote:
> On 08/12/17 22:13, Chris Cheshire wrote:
>> On Fri, Dec 8, 2017 at 3:36 PM, Mark Thomas <ma...@apache.org> wrote:
>>> On 08/12/17 18:49, Chris Cheshire wrote:
>>>> I have a directory resource set defined in my context.xml to handle images :
>>>>
>>>> <Resources>
>>>>   <PreResources className="org.apache.catalina.webresources.DirResourceSet"
>>>>                 base="${catalina.base}/cdn/p/images"
>>>>                 webAppMount="/images" />
>>>> </Resources>
>>>>
>>>> The /p in there actually represents the context path - a given sandbox
>>>> might have the same webapp deployed at different context paths
>>>> representing different development branches. Is it possible to use a
>>>> replacement parameter similar to catalina.base to replace the context
>>>> path the webapp is deployed at?
>>>
>>> Yes. You can use ant style property replacement in any XML file that is
>>> processed by the digester (server.xml, context.xml, web.xml)
>>>
>>> See the opening section of
>>>
>>> http://tomcat.apache.org/tomcat-9.0-doc/config/index.html
>>>
>>> for details.
>>>
>>> Mark
>>>
>>
>> I logged the System properties and there is nothing in there for the
>> context path.
>
> Sorry, I didn't quite understand what you were asking. This isn't
> possible out of the box.
>
> Injecting a special property (org.apache.tomcat.contextPath ?) should be
> doable when working with context specific configuration files -
> context.xml and web.xml - although there might be some edge cases with
> context.xml since sometimes the context path is set in the file. I think
> they can be handled with some documentation.
>
> Care to create an enhancement request? Better still, how do you fancy
> taking a stab at a patch? We can give you some pointers to get started
> if required.
>
> Mark
>
>
>>
>> In catalina logs I see
>>
>> 08-Dec-2017 22:02:05.532 INFO [ajp-nio-8019-exec-1]
>> org.apache.catalina.core.ApplicationContext.log HTMLManager: restart:
>> Reloading web application '/p'
>> 08-Dec-2017 22:02:05.533 INFO [ajp-nio-8019-exec-1]
>> org.apache.catalina.core.StandardContext.reload Reloading Context with
>> name [/p] has started
>> 08-Dec-2017 22:02:14.596 INFO [ajp-nio-8019-exec-1]
>> org.apache.catalina.core.StandardContext.reload Reloading Context with
>> name [/p] is completed
>>
>> It seems catalina knows the value of the context path for the webapp
>> when context.xml is being digested. Should I post an RFE on BZ to have
>> it added to the system properties, or am I incorrect in this
>> assumption?
>>
>>
>>
>>>
>>>>
>>>> I tried following the source through for DirResourceSet but couldn't
>>>> see where even catalina.base is getting replaced.
>>>>
>>>> (I know ant is a solution and I eventually need it for other things
>>>> too, but I have never used it and it's not a learning rabbit-hole I
>>>> can go down right now)
>>>>
>>
>> ---------------------------------------------------------------------
>> 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
>

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


Re: context resources, replacement parameters

Posted by Mark Thomas <ma...@apache.org>.
On 08/12/17 22:13, Chris Cheshire wrote:
> On Fri, Dec 8, 2017 at 3:36 PM, Mark Thomas <ma...@apache.org> wrote:
>> On 08/12/17 18:49, Chris Cheshire wrote:
>>> I have a directory resource set defined in my context.xml to handle images :
>>>
>>> <Resources>
>>>   <PreResources className="org.apache.catalina.webresources.DirResourceSet"
>>>                 base="${catalina.base}/cdn/p/images"
>>>                 webAppMount="/images" />
>>> </Resources>
>>>
>>> The /p in there actually represents the context path - a given sandbox
>>> might have the same webapp deployed at different context paths
>>> representing different development branches. Is it possible to use a
>>> replacement parameter similar to catalina.base to replace the context
>>> path the webapp is deployed at?
>>
>> Yes. You can use ant style property replacement in any XML file that is
>> processed by the digester (server.xml, context.xml, web.xml)
>>
>> See the opening section of
>>
>> http://tomcat.apache.org/tomcat-9.0-doc/config/index.html
>>
>> for details.
>>
>> Mark
>>
> 
> I logged the System properties and there is nothing in there for the
> context path.

Sorry, I didn't quite understand what you were asking. This isn't
possible out of the box.

Injecting a special property (org.apache.tomcat.contextPath ?) should be
doable when working with context specific configuration files -
context.xml and web.xml - although there might be some edge cases with
context.xml since sometimes the context path is set in the file. I think
they can be handled with some documentation.

Care to create an enhancement request? Better still, how do you fancy
taking a stab at a patch? We can give you some pointers to get started
if required.

Mark


> 
> In catalina logs I see
> 
> 08-Dec-2017 22:02:05.532 INFO [ajp-nio-8019-exec-1]
> org.apache.catalina.core.ApplicationContext.log HTMLManager: restart:
> Reloading web application '/p'
> 08-Dec-2017 22:02:05.533 INFO [ajp-nio-8019-exec-1]
> org.apache.catalina.core.StandardContext.reload Reloading Context with
> name [/p] has started
> 08-Dec-2017 22:02:14.596 INFO [ajp-nio-8019-exec-1]
> org.apache.catalina.core.StandardContext.reload Reloading Context with
> name [/p] is completed
> 
> It seems catalina knows the value of the context path for the webapp
> when context.xml is being digested. Should I post an RFE on BZ to have
> it added to the system properties, or am I incorrect in this
> assumption?
> 
> 
> 
>>
>>>
>>> I tried following the source through for DirResourceSet but couldn't
>>> see where even catalina.base is getting replaced.
>>>
>>> (I know ant is a solution and I eventually need it for other things
>>> too, but I have never used it and it's not a learning rabbit-hole I
>>> can go down right now)
>>>
> 
> ---------------------------------------------------------------------
> 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: context resources, replacement parameters

Posted by Chris Cheshire <ya...@gmail.com>.
On Fri, Dec 8, 2017 at 3:36 PM, Mark Thomas <ma...@apache.org> wrote:
> On 08/12/17 18:49, Chris Cheshire wrote:
>> I have a directory resource set defined in my context.xml to handle images :
>>
>> <Resources>
>>   <PreResources className="org.apache.catalina.webresources.DirResourceSet"
>>                 base="${catalina.base}/cdn/p/images"
>>                 webAppMount="/images" />
>> </Resources>
>>
>> The /p in there actually represents the context path - a given sandbox
>> might have the same webapp deployed at different context paths
>> representing different development branches. Is it possible to use a
>> replacement parameter similar to catalina.base to replace the context
>> path the webapp is deployed at?
>
> Yes. You can use ant style property replacement in any XML file that is
> processed by the digester (server.xml, context.xml, web.xml)
>
> See the opening section of
>
> http://tomcat.apache.org/tomcat-9.0-doc/config/index.html
>
> for details.
>
> Mark
>

I logged the System properties and there is nothing in there for the
context path.

In catalina logs I see

08-Dec-2017 22:02:05.532 INFO [ajp-nio-8019-exec-1]
org.apache.catalina.core.ApplicationContext.log HTMLManager: restart:
Reloading web application '/p'
08-Dec-2017 22:02:05.533 INFO [ajp-nio-8019-exec-1]
org.apache.catalina.core.StandardContext.reload Reloading Context with
name [/p] has started
08-Dec-2017 22:02:14.596 INFO [ajp-nio-8019-exec-1]
org.apache.catalina.core.StandardContext.reload Reloading Context with
name [/p] is completed

It seems catalina knows the value of the context path for the webapp
when context.xml is being digested. Should I post an RFE on BZ to have
it added to the system properties, or am I incorrect in this
assumption?



>
>>
>> I tried following the source through for DirResourceSet but couldn't
>> see where even catalina.base is getting replaced.
>>
>> (I know ant is a solution and I eventually need it for other things
>> too, but I have never used it and it's not a learning rabbit-hole I
>> can go down right now)
>>

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


Re: context resources, replacement parameters

Posted by Mark Thomas <ma...@apache.org>.
On 08/12/17 18:49, Chris Cheshire wrote:
> I have a directory resource set defined in my context.xml to handle images :
> 
> <Resources>
>   <PreResources className="org.apache.catalina.webresources.DirResourceSet"
>                 base="${catalina.base}/cdn/p/images"
>                 webAppMount="/images" />
> </Resources>
> 
> The /p in there actually represents the context path - a given sandbox
> might have the same webapp deployed at different context paths
> representing different development branches. Is it possible to use a
> replacement parameter similar to catalina.base to replace the context
> path the webapp is deployed at?

Yes. You can use ant style property replacement in any XML file that is
processed by the digester (server.xml, context.xml, web.xml)

See the opening section of

http://tomcat.apache.org/tomcat-9.0-doc/config/index.html

for details.

Mark


> 
> I tried following the source through for DirResourceSet but couldn't
> see where even catalina.base is getting replaced.
> 
> (I know ant is a solution and I eventually need it for other things
> too, but I have never used it and it's not a learning rabbit-hole I
> can go down right now)
> 
> ---------------------------------------------------------------------
> 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