tags:

views:

899

answers:

2

I'm not overly familiar with Tomcat, but my team has inherited a complex project that revolves around a Java Servlet being hosted in Tomcat across many servers. Custom configuration management software is used to write out the server.xml, and various resources (connection pools, beans, server variables, etc) written into server.xml configure the servlet. This is all well and good.

However, the names of some of the resources aren't known in advance. For example, the Servlet may need access to any number of "Anonymizers" as configured by the operator. Each anonymizer has a unique name associated with it. We create and configure each anonymizer using java beans similar to the following:

<Resource
  name="bean/Anonymizer_toon"
  type="com.company.tomcatutil.AnonymizerBean"
  factory="org.apache.naming.factory.BeanFactory"
  className="teAnonymizer"
  databaseId="50"
/>
<Resource
  name="bean/Anonymizer_default"
  type="com.company.tomcatutil.AnonymizerBean"
  factory="org.apache.naming.factory.BeanFactory"
  className="teAnonymizer"
  databaseId="54"
/>

However, this appears to require us to have explicit entries in the Servlet's context.xml file for each an every possible resource name in advance. I'd like to replace the explicit context.xml entries with wildcards, or know if there is a better solution to this type of problem.

Currently:

  <ResourceLink name="bean/Anonymizer_default"
                global="bean/Anonymizer_default"
                type="com.company.tomcatutil.AnonymizerBean"/>

  <ResourceLink name="bean/Anonymizer_toon"
                global="bean/Anonymizer_toon"
                type="com.company.tomcatutil.AnonymizerBean"/>

Replaced with something like:

  <ResourceLink name="bean/Anonymizer_*"
                global="bean/Anonymizer_*"
                type="com.company.tomcatutil.AnonymizerBean"/>

However, I haven't been able to figure out if this is possible or what the correct syntax might be. Can anyone make any suggestions about better ways to handle this?

+1  A: 

I don't know if it's what you require, but perhaps you may want to investigate creating your own custom resource factory for Tomcat. Here is the general documentation for all things resources via Tomcat: Tomcat Resources

MetroidFan2002
That answers part of the question. There seems to be no way to define a ResourceLink with any form of name wildcard. Perhaps we could try to address this by bundling resources together somehow, so that all anonymizers pass through context.xml as a single resource.
DonGar
+1  A: 

I've not come across this, but it might be easier to have something like an AnonymizerService as a resource that reveals all the different required AnonymizerBeans. This way you have no issues with wildcards, have to publish only one Resource to the web application and you're back on the well defined and well understood path.

Hope that helps about a month after the initial question...

Olaf