Re: 2 Apps, 1 Tomcat

2001-10-22 Thread Anand B N

Mazur,

Tomcat internally has ways of associating classes to which web-application 
they belong to. There are classes of three kinds that get loaded when 
Tomcat gets loaded:-

1. Tomcat internal classes - These are the actual classes loaded by default 
class loader of the JVM.
2. Common classes - These are classes that are shared across 
web-applications/Contexts. These are loaded using a custom class loader 
which comes as a part of Tomcat.
3. Web-Application classes - These are loaded using a WebAppClassLoader 
which takes care of associating with the correct web-app. A class of one 
web-app will not be accessble by another web-app.There are ways to enabling 
this in Tomcat but not all servlet engines support them.

The class loading sequence will be similar to the following:-

1. Look in the WEB-INF\lib and WEB-INF\classes
2. If present load it from there for the web-application that's trying to 
access it.
3. If not go to CLASSPATH  and see if the Class is available.

However you getting error on app2.classes while you are importing only 
app1.classes is quite a weird error.

Check out if you have any references to app2.classes in any of your beans 
that u use.

I have deployed the same classes with different properties in different 
web-applications and have not had a single problem so far. In fact if this 
is not supported our companys' primary product goes for a toss :)

Anand

At 08:46 AM 10/21/2001 -0700, you wrote:
Thanks for responding, Anand.

Ok, so are you suggesting that having the jar files in the
tomcat_home/lib directory may be messing things up and I should
have app1.jar and app2.jar in the
tomcat_home/webapps/examples/WEB-INF/classes directory?  And
then each of the jar files should be filled only with classes
containing the header package app1.classes line, or package
app2.classes line (depending on what they belong to)?

I guess I am not sure how Tomcat knows that a certain class is
part of a certain app.  I mean, as far as Tomcat is concerned,
both app1.jar and app2.jar could both be part of the same
application, and when it finds Products.class in app1.jar having
the header package app1.classes, but my jsp or other class is
calling for import app2.classes.Product, I am still going to
get an error like I am getting right now, won't I?

Thanks,
Rob

Anand B N wrote:
 
  Mazur,
 
  There is  a way of using the same classes in two different web-apps in 
 tomcat.
 
  Try making individual JARs of the respective classes for app#1 and app#2
  and put them in the corresponding WEB-INF/lib
 
  or
 
  put the classes for each of the web-app in the respective WEB-INF/classes.
 
  and remove the jar that u place in TOMCAT_HOME/lib/
 
  Tomcat has an web-app class loader that loads classes based on which
  web-application it belongs to. So even if you have the same Class(same
  package) in two different web-app the classes are loaded twice and this is
  how not only tomcat bu all servlet engines should work.
 
  In tomcat parlance each of these web-apps are called Context and Tomcat
  always loads a new copy ofthe class if it belongs to a different
  web-app/Context.
 
  Anand
  At 09:24 AM 10/20/2001 -0700, you wrote:
  Sort of longhoping more detail helps...
  
  Tomcat 3.2.3,   Apache 1.3.14,   RedHat 6.2
  
  I have a problem with class files with the same name being used
  by two different apps, both web-browser-based.
  
  I have 2 applications running on the same instance of Tomcat (low
  traffic).  They both have some class files that have identical
  names, but the contents are be mildly different.  This seems to
  be a problem when I use one app, then go to the other.  For
  example, if app #1 has a class object called Product.class, and
  then I go to app #2 that also uses an object called Product, but
  it has different properties/methods, I get an error because my
  browser (I *think* my browser is the culprit) is looking for the
  first Product object it already used from app#1.
  
  It is obvious I have a configuration problem.  But I'm not sure
  what the proper resolution is.  Here is what I have:
  
  I used to have only one app running, and therefore put all my
  class files into webapps/examples/WEB-INF/classes.  These classes
  would be called from other classes or JSP's with:
  import Product;
  -or-
  %@ page import = Product %;
  
  All was great.  Then I added an application that also uses an
  object called Product, but it is different.  I elected to put all
  classes for this app in a jar file, and put the jar in my
  tomcat_home/lib directory.  All the classes have the line at
  the top of the source:
  package app2/classes;
  
  ...and I have the jar file properly set to have those direcotries
  inside.  I call the classes in here from other classes or jsp's
  with:
  
  import app2.classes.Product;
  -or-
  %@ page import = app2.classes.Product;
  
  I thought the prefix would be enough to separate the two Product
  classes, but they are not.  Note that: if I

Re: admin context

2001-10-22 Thread Anand B N

David,

As regards to where to define your users here what you have to do :-

tomcat-users.xml defines a set of roles and users with passwords.

Here's a snippet:-

tomcat-users
   user name=tomcat password=tomcat roles=tomcat /
   user name=role1  password=tomcat roles=role1  /
   user name=both   password=tomcat roles=tomcat,role1 /
/tomcat-users

What is done normally for the admin context is that the role of admin 
is defined in the security-constraint of the web.xml of the admin context.

All you have to do is add a user with suitable userid and password with the 
same roles as admin.

i.e. add the follwing line to your tomcat-users.xml

user name=admin password=admin roles=admin /

Then the userid/password is admin/admin

The server.xml explains clearly what the trusted attribute is supposed to 
mean. Here's what it says:-

  trusted=false
  (trusted allows you to access tomcat internal objects
  with FacadeManager )

Hope that helps

Anand

At 11:33 AM 10/22/2001 +0200, you wrote:
Hello there,

I tried following the instructions of how to manage the admin context in
Tomcat 3.2.3, yet could not understand what to do...

what is the trusted attribute in the Context tag in server.xml? where do
I need to define users? in tomcat-users.xml? which role does the admin have?


Please link me to a clear explanation page, or list the actions I should
take...   :o)

Thanks in advance!
David.




Re: 2 Apps, 1 Tomcat

2001-10-21 Thread Anand B N

Mazur,

There is  a way of using the same classes in two different web-apps in tomcat.

Try making individual JARs of the respective classes for app#1 and app#2 
and put them in the corresponding WEB-INF/lib

or

put the classes for each of the web-app in the respective WEB-INF/classes.

and remove the jar that u place in TOMCAT_HOME/lib/

Tomcat has an web-app class loader that loads classes based on which 
web-application it belongs to. So even if you have the same Class(same 
package) in two different web-app the classes are loaded twice and this is 
how not only tomcat bu all servlet engines should work.

In tomcat parlance each of these web-apps are called Context and Tomcat 
always loads a new copy ofthe class if it belongs to a different 
web-app/Context.

Anand
At 09:24 AM 10/20/2001 -0700, you wrote:
Sort of longhoping more detail helps...

Tomcat 3.2.3,   Apache 1.3.14,   RedHat 6.2

I have a problem with class files with the same name being used
by two different apps, both web-browser-based.

I have 2 applications running on the same instance of Tomcat (low
traffic).  They both have some class files that have identical
names, but the contents are be mildly different.  This seems to
be a problem when I use one app, then go to the other.  For
example, if app #1 has a class object called Product.class, and
then I go to app #2 that also uses an object called Product, but
it has different properties/methods, I get an error because my
browser (I *think* my browser is the culprit) is looking for the
first Product object it already used from app#1.

It is obvious I have a configuration problem.  But I'm not sure
what the proper resolution is.  Here is what I have:

I used to have only one app running, and therefore put all my
class files into webapps/examples/WEB-INF/classes.  These classes
would be called from other classes or JSP's with:
import Product;
-or-
%@ page import = Product %;

All was great.  Then I added an application that also uses an
object called Product, but it is different.  I elected to put all
classes for this app in a jar file, and put the jar in my
tomcat_home/lib directory.  All the classes have the line at
the top of the source:
package app2/classes;

...and I have the jar file properly set to have those direcotries
inside.  I call the classes in here from other classes or jsp's
with:

import app2.classes.Product;
-or-
%@ page import = app2.classes.Product;

I thought the prefix would be enough to separate the two Product
classes, but they are not.  Note that: if I run one app, or the
other app only, they work great.  But if I go from one app to
another without first closing my browser and clearing cache, I
get an error saying there is an error with
app2.classes.Product...when I am using app#1 and it should only
be using Product from app#1, not app2.classes.Product.

I can certainly see one solution: Make sure ALL classes have
unique names, even if they are from separate apps.  But there
must be a better way, or something I am doing wrong.  How do you
guys set up 2 apps on one Tomcat instance, when disimilar objects
have the same name?

Thanks,
Rob Mazur

p.s.  I hopelessly looked for subject like this in the archive,
but couldn't find any.




Re: No one answering my question (security realted problem)

2001-09-06 Thread Anand B N

Sukhwinder,

I've faced this problem before. It's got something to do with where your 
JAR's are placed in the  classpath.

If the class throwing this exception is somewhere inside tomcat's internal 
classes (webserver.jar) then move it to a place other than the default /lib 
folder and inclde it in the  class path.

I'm not sure if that answered your question but try it out and also search 
on the net for Sealing violation. I digged it out of the archives and the 
reply from Craig was a solution similar to this which worked for me

Anand
At 02:14 PM 9/5/01 -0700, you wrote:
Hello,

   This is the third time I am sending email. No one is replying.

  I have downloaded tomcat version 3.2.3 source code and compiled it on my
windows 95 machine with Sun JDk 1.3.1. I also had to download JSSE because
there was no option to compile without ssl support. If these classes are not
in classpath then source doesn't compile. My problem is when after compiling
distribution when I try to start tomcat following errors is produced:

///
FATAL Configuration error:
java.lang.SecurityException: sealing violation
..
..


I have followed that steps provided in SSL howto about making entry in java
security file and using keytool.
For password it is written that password can be changeit but when keytool
asks about alias tomcat password what should be entered. (i.e. what is the
tomcat admin password).

Please help me in solving above problem because I am unable to start tomcat.

Is there any option to compile tomcat without ssl support?

Sukhwinder Singh





___
Send a cool gift with your E-Card
http://www.bluemountain.com/giftcenter/





Re: Is there a way to get the docBase property from within a servlet?

2001-09-05 Thread Anand B N

If you are not using WARs and using a folder for your web application then 
try :-

 ServletContext tContext = request.getServletContext();

 tContext.getRealPath(/);

Not sure if it works always but it works  and I guess most servlet engines 
also do function and retunr the docbase property this way.

Anand

At 03:00 PM 9/5/01 -0700, you wrote:


On Wed, 5 Sep 2001, Rick Mann wrote:

  Date: Wed, 05 Sep 2001 14:38:07 -0700
  From: Rick Mann [EMAIL PROTECTED]
  To: tomcat user jakarta.apache.org [EMAIL PROTECTED],
   Craig R. McClanahan [EMAIL PROTECTED]
  Subject: Re: Is there a way to get the docBase property from within a
  servlet?
 
  on 9/1/01 9:48 PM, Craig R. McClanahan at [EMAIL PROTECTED] wrote:
 
   Is there a Servlet spec-compliant way to get the webapp's 
 directory's path
   programmatically, from within a servlet?
  
   No.
  
   Something like calling
   ServletConfig.getInitParameter(docBase), but something that's 
 standard,
   and that does not require me to specify the path explicitly in a
   configuration file?
  
  
   You are starting from an incorect assumption, that there *is* such a 
 thing
   as a portable directory path to a web application.  It is entirely 
 legal
   for a servlet container to run a web application directly from a WAR file
   (in which case there is no expanded directory), or by storing its static
   resources in some other sort of structure (such as being BLOB objects 
 in a
   database).
 
  Okay. I get that. How does one access a resource, then, whether it's a file
  in a directory or a file in a WAR file? For example, we have properties
  files that specify certain things for our web app. Currently, I provide a
  full path, from root, to this file as an init param to a servlet that gets
  loaded at context startup.
 
  I'd like to be able to refer to this file relative to the web app's
  directory (or within the web app's) .WAR file. Can you tell me how I'd go
  about doing this, or what concepts to search for in the documentation to
  answer this question?
 

The API calls for this are ServletContext.getResource() and
ServletContext.getResourcesAsStream().  The path you specify is context
relative, and must start with a slash (/) character.  Details are in the
servlet specification, available at:

   http://java.sun.com/products/servlet/download.html

For example, let's assume you wanted to parse the web app deployment
descriptor for your application.  You can access it like this:

   InputStream is =
 getServletContext().getResourceAsStream(/WEB-INF/web.xml);

The /WEB-INF directory is a good place to put resource files like this,
because the servlet container will refuse to serve them in response to a
direct request from a client.  Plus, this call will work no matter how
your servlet container deploys your application (in a directory, in a WAR
file, or whatever).  It also doesn't matter what context path your app
ends up with, because the path is only relative to the context.

In Servlet 2.3 (i.e. Tomcat 4.0), a new call was added that acts like the
list() method of the java.io.File class.  For instance, to see the names
of all the resources in the /WEB-INF directory, you can say:

   Set paths =
getServletContext().getResourcePaths(/WEB-INF);

and process all of them.  Tomcat 4 uses this, for example, to do directory
listings when there is no welcome file in the selected directory.


  As always, thanks for your help,
 
  
  Roderick Mann   rmann @ latencyzero.com.sansspam
 
 
 

Craig





Tomcat 4 :Weird probelms

2001-08-30 Thread Anand B N

Hi,

I'm still stuck with my Classes problem in tomcat 4.

As I mentioned earlier the whole thing works fine in a IDE environment like 
JBuilder but when I make them jars and put them in a standalone Tomcat 4 
envrn it doesn't work.

Here's what I am doing:-

I have a JSP that invokes a method in a JavaBean which inturns contacts a 
Singleton class to get handles on Deployer  object to get all available 
contexts. Here's the code snippet:-

   1.Context context;
   2.Deployer deployer = TomcatManager.getSharedInstance().getDeployer();
   3. System.out.println(deployer);
   4. String contextPaths[] = deployer.findDeployedApps();
   5. casInstanceList = new Array();
   6. response = new ResponseObject();
   7.  for (int i = 0; i  contextPaths.length; i++) {
   8.   context = 
TomcatManager.getSharedInstance().getDeployer().findDeployedApp(contextPaths[i]);
   9.   casInstanceList.add(context);
   10. }

Here TomcatManager get's initialized by a Servlet[which  implements the 
ContainerServlet interface] on startup.

Sequence of Events:-
On startup
1. Servlet intializes and set's the reference of Tomcat Maanger's Deployer 
and other objects

 From the webapp -
2. JSP is called and it invokes a JavaBean that invokes method on 
TomcatManager to obtain the Deployer reference
3. deployer.finDeployedApps() and now the expcetion is thrown.

As I told earlier I tried the following:-

1. Since my Javabean uses Deployer and Context classes I put them also in 
common/classes aprt from them being a part of catalina.jar. I get a linkage 
error(loader constraints violated)

2. I remove these and it says class not found

That's the whole picture and I'm not sure if I'm getting the solution as 
mentioned but Craig earlier.

Thanks

Anand






On doing further research I realized that the Exception is being thrown 
the  line 4 of the aboive snippet. It;s able to access the Deployer object 
and all that but it fails on this line.







Re: Tomcat 4 help

2001-08-28 Thread Anand B N

Craig,

Thanks for the input but let's say I have a situation wherein my web app 
classes are to use a static class that has references of the Catalina 
internals(like Deployer,Context) etc.  should I come to a conclusion that 
it is impossible a,s that's exactly what I'm doing with the application 
that I am writing.

As you had suggested my Container servlet is in the server/lib folder and 
my javabeans and other classes that the JSPs use in the common/lib folder.

Here's a method in a JavaBean that's called from one of the JSPs to list 
available contexts

   public boolean service()
   {
 try{
   String contextPaths[] = 
TomcatManager.getSharedInstance().getDeployer().findDeployedApps();
   Context context;
   casInstanceList = new Array();
   response = new ResponseObject();
   for (int i = 0; i  contextPaths.length; i++) {
  context = 
TomcatManager.getSharedInstance().getDeployer().findDeployedApp(contextPaths[i]);
  casInstanceList.add(context);
   }
   ...
   ..

   }

Here TomcatManager is the static class that get's it's Deployer and Wrapper 
instance set by the Container Servlet on initialization.

Though the task of listing context is a job done by the Manager servlet I 
would like to do more than that and therefore thought if I had the 
reference to Deployer object I would have better control.

The other thing is if I use a IDE like JBuilder this works perfectly fine 
and my application has no problems like those mentioned earlier.

Here's my folder structure:-

/catalina
  /common
 /lib
- casadmin.jar - JAR containing all Javabeans used by my 
JSPs/Webapp
  /server
 /lib
- catalina.jar - This contains my Container Servlet  also
  /webapp
 /casadmin
 - JSPs that use the Javabeans found in casadmin.jar

Hope that gives a better picture of what I'm trouble shooting.

Thanks

Anand


At 08:35 AM 8/27/01 -0700, you wrote:
Moving catalina.jar is pretty much guaranteed to break things, as you
found out.  It's placed where it is for fundamental architectural reasons.

The solution is to do what I described earlier:
* Put your Container servlet, and any other class that needs
   access to Catalina internals in /servlet/classes or /serv/et/lib/*.jar.
* Put classes that need to be visbile both to your Container servlet
   *and* to web apps in /common/classes or /common/lib/*.jar.

Under no circumstances will any class loaded from a web app class loader
be able to access the Catalina internal stuff.  That is why, for example,
the Manager webapp is designed the way that it is -- all requests are done
via HTTP instead of method calls.

(By the way, you could do the same thing by having your admin servlet use
HttpURLConnection to perform the actual deploy and undeploy operations via
ManagerServlet ...)

Craig


On Mon, 27 Aug 2001, Anand B N wrote:

  Date: Mon, 27 Aug 2001 19:18:02 +0530
  From: Anand B N [EMAIL PROTECTED]
  Reply-To: [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Subject: Tomcat 4 help
 
  Ok here's my problem:-
 
  I have a Singleton class that gets instantiated while the Servlet(a
  container servlet) initializes and in my web application I have JSPs with
  Javabeans which then use the Singleton class(called TomcatManager) to get
  handles on the Wrapper and Deployer objects so that I can control my
  web-aplications.
 
  The need here is to contol/administer web applications from a single point
  and we wanted to have more control on adminstering the webapp but
  automatically copying JARs required etc which the default Admin would 
 not do.
 
  So here's what I did:-
 
  I took the catalina.jar that comes in CATALINA_HOME/server/lib and copied
  it on to CATALINA_HOME/comman/lib.
 
  And here's the exception that I get from the Java bean that's trying to use
  the Deployer class:-
 
  java.lang.LinkageError: Class org/apache/catalina/Context violates loader
  constraints
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at 
 java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at
  
 
org.apache.catalina.loader.StandardClassLoader.findClass(StandardClassLoader.java:670)
at
  
 
org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1088)
at
  
 
org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:987)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method

Re: internal server error

2001-08-28 Thread Anand B N

Scott,

I may be wrong but here's what I think with respect to your problems:-

Question 1 : - I really don't know :)

Question 2: - Though u have mentioned auto reload to true try the follwing:-
Make a new Context entry in the Server.xml with your application and set 
the reload value to true and see of you observations repeat. We had done a 
similar observation and it defaults to  auto-reload=false if u don't 
mention it explicitly ion server.xml

Question 3:  Tomcat's web applications are loaded using an adaptive /web 
app class loader but it too is a class loader. So once a class is laoded by 
the class loader it wont load it again until the class has changed( as per 
your previous question) so removing your classes would not probably affect 
the Classes.

Hope that helps

Anand


At 08:23 AM 8/28/01 -0400, you wrote:
 I have a question that hopefully someone on this list can help 
 with. I use the startup.sh and shutdown.sh scripts to start and stop 
 tomcat. If i stop tomcat and then bring it back up and go and try to view 
 a servlet I get an internal server error from apache, like tomcat really 
 isnt up yet or something. But if i then hit refresh on my brower like 7 
 or 8 times tomcat will start responding like normal. I saw a message on 
 the same topic of this in the mail archives but I didnt see a definite 
 answer. Anyone know why this is? And is there any way to stop this?

Second question is about auto reloading. I use ant to create my war files 
so they are of the standard directory layout. After tomcat starts and 
unpacks the war I should be able to copy recompiled classes into the 
MyProject/WEB-INF/classes directory and have tomcat auto reload 
(server.xml says that auto reload is default to true ) This works most of 
the time. But sometimes i swear it wont reload my servlet until i stop 
tomcat, remove the unpacked war directory and restart tomcat. This doesn't 
make any sense to me?

Also one last semi related question. Can someone tell me how tomcat 
decides what servlets to cache in memory? If it is really auto reloaded 
servlets, if i delete all my class files i shouldnt be able to get to any 
servlets correct? But i have deleted all my class files and still can get 
to certain servlets in my web app. So how does tomcat choose what servlets 
to cache or not?

Any and all information that can help with these three questions would be 
greatly apprecaited. Thanks in advance.

 Scott Knight





Tomcat 4 help

2001-08-27 Thread Anand B N

Ok here's my problem:-

I have a Singleton class that gets instantiated while the Servlet(a 
container servlet) initializes and in my web application I have JSPs with 
Javabeans which then use the Singleton class(called TomcatManager) to get 
handles on the Wrapper and Deployer objects so that I can control my 
web-aplications.

The need here is to contol/administer web applications from a single point 
and we wanted to have more control on adminstering the webapp but 
automatically copying JARs required etc which the default Admin would not do.

So here's what I did:-

I took the catalina.jar that comes in CATALINA_HOME/server/lib and copied 
it on to CATALINA_HOME/comman/lib.

And here's the exception that I get from the Java bean that's trying to use 
the Deployer class:-

java.lang.LinkageError: Class org/apache/catalina/Context violates loader 
constraints
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at 
org.apache.catalina.loader.StandardClassLoader.findClass(StandardClassLoader.java:670)
at 
org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1088)
at 
org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:987)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at 
com.lbi.cas.deployment.handlers.ListCASHandler.init(ListCASHandler.java:27)
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:237)
at 
com.lbi.cas.deployment.components.RequestManager.getRequestHandler(RequestManager.java:70)
at 
org.apache.jsp._0002fjsp_0002fc3_0005fcas_0005flist_jsp._jspService(_0002fjsp_0002fc3_0005fcas_0005flist_jsp.java:90)

If I'm right this is sometihng to do with dependencies of the classes.

I'm not sure where I'm going wrong.

Anand





Help with Tomcat4

2001-08-26 Thread Anand B N

Hi,

I'm using experimenting with Tomcat4 and I did the following:-

I wrote a servlet that implements the ContainerServlet[Obviosuly in the 
org.apache.catalina.servlets package] . Now I have a set of JSPs which in turn use a 
set of Java beans whcih in turn use this Servlet for getting hol of information on 
Context etc. However I am facing the follwing problem:-

In my Java bean if I import org.apache.catalina.Deployer it's not able to find the 
class in my classpath and throws a ClassNotFoundException. I found this problem very 
weird as these are the classes in the standard JAR that comes with Tomcat 4.

Could someone please explain this to me?

Anand
Associate,RD,
Digital Think