aspose file tools*
The moose likes Tomcat and the fly likes Tomcat Configuration with more than 2,000 apps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat Configuration with more than 2,000 apps" Watch "Tomcat Configuration with more than 2,000 apps" New topic
Author

Tomcat Configuration with more than 2,000 apps

Julia Ding
Greenhorn

Joined: Apr 02, 2011
Posts: 5
I am pretty new to Apache/Tomcat configuration. Here is my situation:

We have more than two thousands applications in ten categories under on Tomcat server. Originally, those two thousands applications are all under Catalina_home/webapps/. I am asked to organize those applications into categories during our server migration. Ideally, when Apache sees a request with URI like

https://localhost:8080/category1/myapp11
https://localhost:8080/category1/myapp12
https://localhost:8080/category1/myapp13
https://localhost:8080/category1/myapp14

, those requests will be routed to a tomcat worker called worker1.

https://localhost:8080/category2/myapp21
https://localhost:8080/category2/myapp22
https://localhost:8080/category2/myapp23
https://localhost:8080/category2/myapp24

may also routed to worker1.

https://localhost:8080/category9/myapp94

may routed to worker2.

FYI, there are about 1,300 applications in category1.

I tried to add <Context> tag into server.xml file. I did like this:


<Context path="/category1"
docBase="/C:/Program Files/Tomcat 7.0/webapps/category1"
debug="0"
reloadable="true"
crossContext="true">
</Context>

I was hoping that /category1 will act like /webapps, all applications under webapps/category1 will be seen when URI

https://localhost:8080/category1/myapp1/
https://localhost:8080/category1/myapp2/
https://localhost:8080/category1/myapp3/
https://localhost:8080/category1/myapp4/

were used. But, it did not work! It cannot find myapp1, myapp2, and so on.

If I add /myapp1 into the path attribute like this:

<Context path="/category1/myapp1"
docBase="/C:/Program Files/Tomcat 7.0/webapps/category1/myapp1"
debug="0"
reloadable="true"
crossContext="true">
</Context>

It worked. But, if I do it this way, I will need to add 1,300 <Context> tags into server.xml. Each tag is only for one application. Is it too much?! Did I do something wrong?

Any suggestions is greatly appreciated!

Thanks a lot in advance!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

DON'T put them into server.xml! That's been discouraged for a long time.

You can create a set of XML files with one Context in each file and place them into the TOMCAT_HOME/conf/Catalina/localhost directory. Please note, however, that the webapp context names will be defined based on the name of the context file, NOT on the "path" attribute of the Context element ( ). I've never tried subdirectories on this directory, however, so I don't know if that will work.

Customer surveys are for companies who didn't pay proper attention to begin with.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
More out of curiosity than because I have a different approach to suggest: are these functionally different applications, or is it an attempt to establish a form of multi-tenancy?


Ping & DNS - my free Android networking tools app
Julia Ding
Greenhorn

Joined: Apr 02, 2011
Posts: 5
Tim Holloway wrote:DON'T put them into server.xml! That's been discouraged for a long time.

You can create a set of XML files with one Context in each file and place them into the TOMCAT_HOME/conf/Catalina/localhost directory. Please note, however, that the webapp context names will be defined based on the name of the context file, NOT on the "path" attribute of the Context element ( ). I've never tried subdirectories on this directory, however, so I don't know if that will work.



Thank you, Tim!

Here is the "myapp1.xml" file and I put it under TOMCAT_HOME/conf/Catalina/localhost /category1/myapp1 directory:
<?xml version="1.0" encoding="utf-8"?>

<Context docBase="tomcat_home/webapps/category1/myapp1" debug="0"
reloadable="true" crossContext="true">
</Context>

Still, the servlet of myapp1 cannot be found. Do I need to add more stuff in it? If you could post an example of the context.xml file, that will be great. By the way, the file name of the XML file should be "context.xml" or "myapp1.xml"?


Then, I tried to put the configuration inside server.xml like this:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Context path="" docBase="." debug="0"/>
<Context path="/category1/myapp1" docBase="tomcat_home/webapps/category1/myapp1" debug="0"
reloadable="true" crossContext="true">
</Context>

</Host>
</Engine>

Then it works and I saw a directory is created under /catalina_home/work/Catalina/localhost/category1_myapp1/
I tried to call my context XML file category1_myapp1.xml, it did not work either.

Again, thank you so much for your help! Very much appreciated!

- Julia
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

If you name your context XML file "context.xml", the webapp will respond to the URL context "context". If you name the context.xml file "webapp1.xml", the webapp will respond to the URL context "webapp1". The context path within the context XML file is ignored; the name of the context XML file itself is all that's used.

The only thing worse, however, than putting Context elements in server.xml is putting 2000 Context elements in server.xml. It makes server administration a nightmare. So I repeat:

DON'T put the Context definitions into server.xml!

Julia Ding
Greenhorn

Joined: Apr 02, 2011
Posts: 5
Tim Holloway wrote:If you name your context XML file "context.xml", the webapp will respond to the URL context "context". If you name the context.xml file "webapp1.xml", the webapp will respond to the URL context "webapp1". The context path within the context XML file is ignored; the name of the context XML file itself is all that's used.

The only thing worse, however, than putting Context elements in server.xml is putting 2000 Context elements in server.xml. It makes server administration a nightmare. So I repeat:

DON'T put the Context definitions into server.xml!



Yes, I agree with you. It will be a nightmare. I am desperately seek another solution!
I created a category1#myapp1.xml in CATALINA_HOME\conf\Catalina\localhost\

CATALINA_HOME\conf\Catalina\localhost\category1#myapp1.xml

I got a "Fatal Error" right after I restarted tomcat:

INFO: Deploying configuration descriptor category1#myapp1.xml from CATALINA_HOME\conf\Catalina\localhost
Apr 5, 2011 3:34:36 PM org.apache.tomcat.util.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 1 column 1: Content is not allowed in prolog.


Here is the content of the category1#myapp1.xml file:

<Context docBase="CATALINA_HOME/webapps/category1/myapp1"
reloadable="true" crossContext="true">
</Context>


Can some one tell me what the problem is?

Thanks for any help in advance!
Julia Ding
Greenhorn

Joined: Apr 02, 2011
Posts: 5
Ulf Dittmer wrote:More out of curiosity than because I have a different approach to suggest: are these functionally different applications, or is it an attempt to establish a form of multi-tenancy?


These are group of legacy applications developed during 1999 - 2000. It is an attempt to establish a form of multi-tenancy as you have guessed. Switched from few Application Servers, but the application themselves stayed pretty much as they were. No plan to rewrite them yet. I wish they do.

I am still struggling with the configuration. I have created an XML file called category1#myapp1.xml
in CATALINA_HOME\conf\Catalina\localhost\category1#myapp1.xml

I got a "Fatal Error" right after I restarted tomcat:
----------------------------------------------------------
INFO: Deploying configuration descriptor category1#myapp1.xml from CATALINA_HOME\conf\Catalina\localhost
Apr 5, 2011 3:34:36 PM org.apache.tomcat.util.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 1 column 1: Content is not allowed in prolog.
----------------------------------------------------------

Here is the content of the category1#myapp1.xml file:
--------
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="CATALINA_HOME/webapps/category1/myapp1"
reloadable="true" crossContext="true">
</Context>
--------

What could be wrong with my configuration?

Thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
SEVERE: Parse Fatal Error at line 1 column 1: Content is not allowed in prolog.


Is usually due to extra characters before the <?xml start - probably accidentally introduced by editing the file.

Bill
Julia Ding
Greenhorn

Joined: Apr 02, 2011
Posts: 5
William Brogden wrote:
SEVERE: Parse Fatal Error at line 1 column 1: Content is not allowed in prolog.


Is usually due to extra characters before the <?xml start - probably accidentally introduced by editing the file.

Bill


Thank you, Bill.

I tried manually type all the contents of this xml file to avoid paste extra characters. But still, it gives me the same error. Sigh.

- Julia
Chandra Barnett
Greenhorn

Joined: Apr 08, 2011
Posts: 1
Interestingly, I'm having this problem too. I dug around in the logs and noticed that in my case, the file Tomcat is failing to parse isn't myapp.xml. It seems to be a generated temp file in the same directory, called ._myapp.xml, which I'd presume is based on the content of myapp.xml.

It's a mystery to me why Tomcat would generate a file it then can't parse. Does anybody know what files Tomcat references when creating this temporary file?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat Configuration with more than 2,000 apps