You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Harish <ha...@postmark.net> on 1999/03/10 05:18:55 UTC

which classes to use to modify server.xml

Hi,
   I'm trying to write a plug-in which takes in a WAR file as input and
modifies the server.xml, copies the WAR into the directory of
jakarta-tomcat and then restart the server(or do i have the option of
hot deployment, without any restarts?)
   
   Can some one please tell me which packages/classes of tomcat can be
used to do this?

Thanks,
harish

Re: which classes to use to modify server.xml

Posted by Gary Yang <yg...@yahoo.com>.
costin@eng.sun.com wrote:

> >       Looked into the 3.1 beta RC1 version. saw the context admin interface.
> > NOW: When i add a context using this interface, it doesn't modify
> > "server.xml". Ideally, shouldn't it be adding a <context></context>
>
> Yes, but it does add the context to the running server without restart.
>
> About saving to server.xml - it is not implemented, and it should be
> independent of the admin interface.
> server.xml is not the only config system, and you want to have everything
> working if you use LDAP for configuration or any other native application
> format.
>

I am so suprised that web.xml uses elements to store all config arguments,
however,
server.xml uses attributes only.



Re: I've built RPMS

Posted by jv...@kw.igs.net.
Sorry I forgot to mention that I used the GNU classpathx JSDK and
that's built in the RPM as well. I'm not sure if this is acceptable, I know
there are some serialization issues with the GNU JSDK because they
can't legally look at the sources to see what SUN is doing.

Jason van Zyl


I've built RPMS

Posted by jv...@kw.igs.net.
Hello,

I have a first version of an RPM for tomcat. Right now it's suited to my particular needs but
the
RPM could easily be modified to be useful for others. Here's a quick list of what's in it:

-> builds ApacheJServ as a DSO (with EAPI for use with mod_ssl)
-> builds jakarta-ant package
-> builds jakarta-tomcat package (all the examples are present)
-> htttp.conf has been modifed to take -DJSERV or -DTOMCAT so you
       can use the servlet engine of your choice.
-> RedHat init script takes the same options as above so they can be
       passed into apache. The selection of TOMCAT will automatically
       start tomcat.

Some notes:

I don't use the standard RedHat layout: I use

/www/apache

and keep everything under there. So there's a

/www/apache/jserv

and a

/www/apache/tomcat

As well, my base apache RPM has been built using the EAPI so that I could build
mod_ssl as a DSO.

Like I said the above oddities could easily be changed if the RPMs would be generally
useful. Maybe someone has already done this. It was still in the TOMCAT todo.

I also don't have anywhere to put the RPMs for sharing. I would be glad to
make a set of RPMs for easy installation if someone could provide a little space.

Jason van Zyl


Error in reading XML

Posted by Harish <ha...@postmark.net>.
Hi,
	I added code to expand the war file into webapps directory and now i'm
able to do hot deployment. [BTW, I'm on Win98 using tomcat standalone,
could that be the reason that i'd to do all whatever i have done?]
[I've done some not-so-nice coding in this. I'll make it neater and send
it within a couple of days - U guys can check it and put it 'in' or
throw it 'off' :) ] 
There's another problem now:
	I get this error whenever i deploy war files which have the
<descrption>DESC</descrption> tag. The exception is:
java.lang.NoSuchMethodException: setDescription(st. trace is appended
below). The problem is that in XmlMapper.matchend() method[which in turn
calls MethodSetter.end()]: ServletWrapper.setDescription() is getting
called(method.invoke()).But setDescription() method is not present in
SW[There is a setServletDescription() method in SW,however] I found a
workaround by adding the method, but i'm not very sure that its correct.
u guys please tell me what to do.
[I'm adding the xml as well below: ]

Cheers to the Jakarta group,
harish

STACK TRACE:
===========
ERROR reading C:\Program Files\Apache
Group\jakarta-tomcat\webapps\hello\WEB-INF
\web.xml
At Line 15 /web-app/servlet/description/ [[[SEE BELOW FOR THE WEB.XML
FILE]]]

ERROR reading C:\Program Files\Apache
Group\jakarta-tomcat\webapps\hello\WEB-INF
\web.xml
java.lang.NoSuchMethodException: setDescription
        at java.lang.Class.getMethod0(Native Method)
        at java.lang.Class.getMethod(Class.java, Compiled Code)
        at org.apache.tomcat.util.xml.MethodSetter.end(XmlMapper.java,
Compiled
Code)
        at org.apache.tomcat.util.xml.XmlMapper.matchEnd(XmlMapper.java,
Compile
d Code)
        at
org.apache.tomcat.util.xml.XmlMapper.endElement(XmlMapper.java, Compi
led Code)
        at com.sun.xml.parser.Parser.maybeElement(Parser.java, Compiled
Code)
        at com.sun.xml.parser.Parser.content(Parser.java, Compiled Code)
        at com.sun.xml.parser.Parser.maybeElement(Parser.java, Compiled
Code)
        at com.sun.xml.parser.Parser.content(Parser.java, Compiled Code)
        at com.sun.xml.parser.Parser.maybeElement(Parser.java, Compiled
Code)
        at com.sun.xml.parser.Parser.parseInternal(Parser.java:491)
        at com.sun.xml.parser.Parser.parse(Parser.java:283)
        at
org.apache.tomcat.util.xml.XmlMapper.readXml(XmlMapper.java:198)
        at
org.apache.tomcat.context.WebXmlReader.processFile(WebXmlReader.java:
124)
        at
org.apache.tomcat.context.WebXmlReader.contextInit(WebXmlReader.java:
38)
        at
org.apache.tomcat.core.ContextManager.initContext(ContextManager.java
, Compiled Code)
        at
org.apache.tomcat.core.ContextManager.init(ContextManager.java, Compi
led Code)
        at org.apache.tomcat.startup.Tomcat.execute(Tomcat.java:123)
        at org.apache.tomcat.startup.Tomcat.main(Tomcat.java:130)


WEB.XML
======
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app>

<web-app> 
  <icon> 
    <small-icon /> 
    <large-icon /> 
  </icon> 
  <display-name>web-app1</display-name> 
  <description>No Description</description> 
  <servlet> 
    <servlet-name>newaccount</servlet-name> 
    <display-name>newaccount</display-name> 
    <description>No Description</description> <!-- harish: I think the
prob. is here!! -->
    <jsp-file>newaccount.jsp</jsp-file> 
  </servlet> 
  <servlet> 
    <servlet-name>bank</servlet-name> 
    <display-name>bank</display-name> 
    <description>No Description</description> 
    <jsp-file>bank.jsp</jsp-file> 
  </servlet> 
  <servlet> 
    <servlet-name>info</servlet-name> 
    <display-name>info</display-name> 
    <description>No Description</description> 
    <jsp-file>info.jsp</jsp-file> 
  </servlet> 
  <servlet> 
    <servlet-name>viewledger</servlet-name> 
    <display-name>viewledger</display-name> 
    <description>No Description</description> 
    <jsp-file>viewledger.jsp</jsp-file> 
  </servlet> 
  <servlet> 
    <servlet-name>options</servlet-name> 
    <display-name>options</display-name> 
    <description>No Description</description> 
    <jsp-file>options.jsp</jsp-file> 
  </servlet> 
  <servlet> 
    <servlet-name>transfer</servlet-name> 
    <display-name>transfer</display-name> 
    <description>No Description</description> 
    <jsp-file>transfer.jsp</jsp-file> 
  </servlet> 
  <servlet> 
    <servlet-name>allaccounts</servlet-name> 
    <display-name>allaccounts</display-name> 
    <description>No Description</description> 
    <jsp-file>allaccounts.jsp</jsp-file> 
  </servlet> 
  <session-config> 
    <description>No Description</description> 
    <session-timeout>-1</session-timeout> 
  </session-config> 
  <ejb-ref> 
    <description>No Description</description> 
    <ejb-ref-name>ejb/Transfer</ejb-ref-name> 
    <ejb-ref-type>Entity Bean</ejb-ref-type> 
    <home>proton.bank.TransferHome</home> 
    <remote>proton.bank.Transfer</remote> 
    <ejb-link /> 
  </ejb-ref> 
  <ejb-ref> 
    <description>No Description</description> 
    <ejb-ref-name>ejb/Ledger</ejb-ref-name> 
    <ejb-ref-type>Entity Bean</ejb-ref-type> 
    <home>proton.bank.LedgerHome</home> 
    <remote>proton.bank.Ledger</remote> 
    <ejb-link /> 
  </ejb-ref> 
  <ejb-ref> 
    <description>No Description</description> 
    <ejb-ref-name>ejb/Checking</ejb-ref-name> 
    <ejb-ref-type>Entity Bean</ejb-ref-type> 
    <home>proton.bank.CheckingHome</home> 
    <remote>proton.bank.Checking</remote> 
    <ejb-link /> 
  </ejb-ref> 
</web-app>



Costin Manolache wrote:
> 
> Harish wrote:
> 
> > Hi,
> >         Earlier, i'd posted my questions to tomcat-dev in error. I'm resending
> > it to tomcat-user.
> >
> 
> I fixed it, it will show up in nightly builds. Thanks for the report - some of the callbacks
> were never used/tested.
> 
> Costin
> 
> --------------------------------------------------------------------------
> To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commmands, email: tomcat-user-help@jakarta.apache.org

Re: Bug in the Impl of Interceptor architecture?

Posted by Costin Manolache <co...@eng.sun.com>.

Harish wrote:

> Hi,
>         Earlier, i'd posted my questions to tomcat-dev in error. I'm resending
> it to tomcat-user.
>

I fixed it, it will show up in nightly builds. Thanks for the report - some of the callbacks
were never used/tested.

Costin


Re: Bug in the Impl of Interceptor architecture?

Posted by Harish <ha...@postmark.net>.
Hi,
 	Earlier, i'd posted my questions to tomcat-dev in error. I'm resending
it to tomcat-user.

Thanks in adv,
harish

Harish wrote:
> 
> Hi,
> 
>         I wrote a test interceptor which just checks if all the methods of the
> Interface are being called.Added the following entry in server.xml:
> "<RequestInterceptor className="MyInterceptor" />"
> (after all the Request Interceptors present).
> 
>         [I've attached the code and the output below.]
> 
>         The results say that only
> contextMap(),requestMap(),authorize(),beforeBody() are being called.
> Other methods like: preService(), postService() aren't getting called at
> all.
>         Isn't that a bug?
>         I tried accessing the admin context apart from the ROOT and got the
> same results.
> 
> Also, the AdminContext isn't adding the contexts on the fly. I'm going
> through the source of tomcat. I know that i'm getting the error from the
> "DefaultErrorPage" servlet, but am not able to find out who's causing it
> as request.getAttribute(tomcat.servlet.error.throwable) is NULL(and so i
> cant do a printStackTrace()). This is the case with servlets. Regarding
> Jsps it tries to fetch the page from "c:\program files\apache
> group\jakarta-tomcat\" directory.
> 
> I need to figure out the problem with the hot deployment of SERVLETS
> soon as i can. Please help me as to how to fix this problem of
> "hot-deployment".
> 
> Regards,
> harish









> 
> <code>
> import org.apache.tomcat.core.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.util.*;
> import java.rmi.*;
> import com.pramati.util.*;
> 
> public class MyInterceptor extends BaseInterceptor{
> 
>     public int contextMap(Request request){
>                 System.out.println("contextMap() called! class="+ request.getClass());
>                 return 0;
>         }
>     public int requestMap(Request request){
>                 System.out.println("requestMap() called!");
>                 return 0;
>         }
>     public int authenticate(Request request, Response response)
>         {
>                 return 0;
>         }
>     public int authorize(Request request, Response response){
>                 System.out.println("authorize() called!");
>                 return 0;
>         }
>     public int preService(Request request, Response response){
>                 System.out.println("preService() called!");
>                 return 0;
>         }
>     public int beforeBody( Request request, Response response){
>                 System.out.println("beforeBody() called!");
>                 return 0;
>         }
>     public int beforeCommit( Request request, Response response){
>                 System.out.println("beforeCommit() called!");
>                 return 0;
>         }
>     public int afterBody( Request request, Response response){
>                 System.out.println("afterBody() called!");
>                 return 0;
>         }
>     public int postService(Request request, Response response){
>                 System.out.println("postService() called!");
>                 return 0;
>         }
>     public String[] getMethods(){
>                 System.out.println("getMethods() called!");
>                 return new String[0];
>         }
> 
> }
> 
> </code>
> 
> output:(for each request sent to tomcat)
> 
> contextMap() called! class=class
> org.apache.tomcat.service.http.HttpRequestAdapt
> er
> requestMap() called!
> authorize() called!
> contextMap() called! class=class org.apache.tomcat.core.RequestImpl
> requestMap() called!
> contextMap() called! class=class
> org.apache.tomcat.service.http.HttpRequestAdapt
> er
> requestMap() called!
> beforeBody() called!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

Bug in the Impl of Interceptor architecture?

Posted by Harish <ha...@postmark.net>.
Hi costin,

	I wrote a test interceptor which just checks if all the methods of the
Interface are being called.Added the following entry in server.xml:
"<RequestInterceptor className="MyInterceptor" />"
(after all the Request Interceptors present). 

	[I've attached the code and the output below.]

	The results say that only
contextMap(),requestMap(),authorize(),beforeBody() are being called.
Other methods like: preService(), postService() aren't getting called at
all.
 	Isn't that a bug?
	I tried accessing the admin context apart from the ROOT and got the
same results.

Also, the AdminContext isn't adding the contexts on the fly. I'm going
through the source of tomcat. I know that i'm getting the error from the
"DefaultErrorPage" servlet, but am not able to find out who's causing it
as request.getAttribute(tomcat.servlet.error.throwable) is NULL(and so i
cant do a printStackTrace()). This is the case with servlets. Regarding
Jsps it tries to fetch the page from "c:\program files\apache
group\jakarta-tomcat\" directory.

I need to figure out the problem with the hot deployment of SERVLETS
soon as i can. Please help me as to how to fix this problem with
"hot-deployment".

Regards,
harish

<code>
import org.apache.tomcat.core.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.rmi.*;
import com.pramati.util.*;

public class MyInterceptor extends BaseInterceptor{
	
    public int contextMap(Request request){
		System.out.println("contextMap() called! class="+ request.getClass());
		return 0;
	}
    public int requestMap(Request request){
		System.out.println("requestMap() called!");
		return 0;
	}
    public int authenticate(Request request, Response response)
	{
		return 0;
	}
    public int authorize(Request request, Response response){
		System.out.println("authorize() called!");
		return 0;
	}
    public int preService(Request request, Response response){
		System.out.println("preService() called!");
		return 0;
	}
    public int beforeBody( Request request, Response response){
		System.out.println("beforeBody() called!");
		return 0;
	}
    public int beforeCommit( Request request, Response response){
		System.out.println("beforeCommit() called!");
		return 0;
	}
    public int afterBody( Request request, Response response){
		System.out.println("afterBody() called!");
		return 0;
	}
    public int postService(Request request, Response response){
		System.out.println("postService() called!");
		return 0;
	}
    public String[] getMethods(){
		System.out.println("getMethods() called!");
		return new String[0];
	}

}

</code>

output:(for each request sent to tomcat)

contextMap() called! class=class
org.apache.tomcat.service.http.HttpRequestAdapt
er
requestMap() called!
authorize() called!
contextMap() called! class=class org.apache.tomcat.core.RequestImpl
requestMap() called!
contextMap() called! class=class
org.apache.tomcat.service.http.HttpRequestAdapt
er
requestMap() called!
beforeBody() called!

Re: which classes to use to modify server.xml

Posted by co...@eng.sun.com.
> 	Looked into the 3.1 beta RC1 version. saw the context admin interface.
> NOW: When i add a context using this interface, it doesn't modify
> "server.xml". Ideally, shouldn't it be adding a <context></context>

Yes, but it does add the context to the running server without restart.

About saving to server.xml - it is not implemented, and it should be
independent of the admin interface. 
server.xml is not the only config system, and you want to have everything
working if you use LDAP for configuration or any other native application
format.

Check ContextInterceptor - it gets notifications when contexts are added,
you can implement persistence there ( i.e. an adapter for your config
system, we should provide a default one for server.xml )

> My questions are:
> 1) How is tomcat getting in the context "bank" when there is no entry in
> server.xml. Is it because tomcat "picks" the contexts from "webapp"
> directory rather than server.xml or am i missing something? Has
> "server.xml" been deprecated?  :) :)

No. Configuring via server.xml is easy, integrating with other
applications is hard - we don't want to force server.xml ( and I don't
think the format of server.xml was designed well enough or we had
feedback - so don't assume it's final !) 

We have a small interceptor that reads webapps/ and add them automatically
at startup. You can create other interceptors to implement other policies,
or just disable webapps and set up everything in config files.


> 2) Do i have to copy the WAR file into "c:\program files\apache
> group\jakarta-tomcat\webapps\" to use the Context Admin interface to add
> new contexts?

No, the context can be anywhere.

webapps/ are added automatically at startup.


> In case of any small prob.s/improvements with Context Admin, may be i
> can fix/make them(if none is working on it at present).

Please do so! Let me know if you need help.

Costin


Re: which classes to use to modify server.xml

Posted by Harish <ha...@postmark.net>.
[P.S. Hi Justyna, the archives told me that you developed the "context
admin" interface. Hope you can help me and so i'm copying it to you -
thanks for y'r attention - harish]

Hi costin,
		Thanks for the info. That really helped! 
	Looked into the 3.1 beta RC1 version. saw the context admin interface.
NOW: When i add a context using this interface, it doesn't modify
"server.xml". Ideally, shouldn't it be adding a <context></context>
entry in server.xml? It doesn't. 
I'll tell what exactly i did:
        I added a context named - "myapp" with a war file named
bank.war(which was in c:\my_folder\WAR\). When i tried accessing the
jsp's in it, tomcat said - file not found. When i restarted it and
tried, nothing happened.
        I copied the war file into "c:\program files\apache
group\jakarta-tomcat\webapps\" and then tried the whole thing. This
time: I got file not found when i accessed the jsps. I stopped tomcat
and checked the webapps directory - there was a folder with the name
"bank" into which all the jsps/servlets were extracted into. I
re-started tomcat now and now when i listed down the contexts, i got the
context name "bank", instead of "myapp". Now, i could access the
jsp/serlvets in bank.jar properly.

My questions are:
1) How is tomcat getting in the context "bank" when there is no entry in
server.xml. Is it because tomcat "picks" the contexts from "webapp"
directory rather than server.xml or am i missing something? Has
"server.xml" been deprecated?  :) :)

2) Do i have to copy the WAR file into "c:\program files\apache
group\jakarta-tomcat\webapps\" to use the Context Admin interface to add
new contexts?

In case of any small prob.s/improvements with Context Admin, may be i
can fix/make them(if none is working on it at present).

Thanks for the help,
harish

costin@eng.sun.com wrote:
> 
> >       It isn't HttpServer, but AdminImpl.java that i have overridden. I have
> > added a method getHttpServer() which return me the ref. to the
> > HttpServer that AdminImpl contains. From the HttpServer reference, i get
> > the CM and so on.
> 
> > >      I'm doing a look up in the RMI Registry to get a reference to the
> > > HttpServer(Tomcat "HttpServer" class) running[All my program  knows is
> > > the host/port number of the registry].I have overridden the
> > > HttpServer.java, added a "getContextManager()" method using which i get
> > > a ref. to the context Manager. This,i use to get the info all the
> > > contexts i wish to modify(or delete etc.)
> 
> You are using an old version of tomcat.
> Get 3.1beta and take a look at the admin interface.
> ( it's going to have a user/password and run on a different port ).
> 
> You just need to write a normal servlet and make a normal http connection
> to your servlet. Inside the servlet you'll access the real Request object
> and get the ContextManager.
> 
> Please note that all this will require special permissions for your
> servlet, and will be protected by a SecurityManager.
> 
> Costin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

Re: which classes to use to modify server.xml

Posted by co...@eng.sun.com.
>  	It isn't HttpServer, but AdminImpl.java that i have overridden. I have
> added a method getHttpServer() which return me the ref. to the
> HttpServer that AdminImpl contains. From the HttpServer reference, i get
> the CM and so on.

> >      I'm doing a look up in the RMI Registry to get a reference to the
> > HttpServer(Tomcat "HttpServer" class) running[All my program  knows is
> > the host/port number of the registry].I have overridden the
> > HttpServer.java, added a "getContextManager()" method using which i get
> > a ref. to the context Manager. This,i use to get the info all the
> > contexts i wish to modify(or delete etc.)

You are using an old version of tomcat. 
Get 3.1beta and take a look at the admin interface. 
( it's going to have a user/password and run on a different port ).

You just need to write a normal servlet and make a normal http connection
to your servlet. Inside the servlet you'll access the real Request object
and get the ContextManager.

Please note that all this will require special permissions for your
servlet, and will be protected by a SecurityManager.

Costin


Re: which classes to use to modify server.xml

Posted by Harish <ha...@postmark.net>.
hi,
 	It isn't HttpServer, but AdminImpl.java that i have overridden. I have
added a method getHttpServer() which return me the ref. to the
HttpServer that AdminImpl contains. From the HttpServer reference, i get
the CM and so on.

sorry for the mistake,
harish

Harish wrote:
> 
> Hi,
> 
>      This is for a scenario in which Tomcat is running on a
> machine(which wasn't started from my program) and i need to connect to
> it from my program and do an addition/modification/deletion of Contexts.
> 
>      I'm doing a look up in the RMI Registry to get a reference to the
> HttpServer(Tomcat "HttpServer" class) running[All my program  knows is
> the host/port number of the registry].I have overridden the
> HttpServer.java, added a "getContextManager()" method using which i get
> a ref. to the context Manager. This,i use to get the info all the
> contexts i wish to modify(or delete etc.)
> 
>      I have a strong feeling that there's a neater way of doing it
> instead of overriding HttpServer.java, something which i'm not able to
> figure out. Do I need to use a Connector(excuse me if i'm wrong)?
> 
> someone please enlighten me,
> Thanks,
> harish
> 
> Harish wrote:
> >
> > Hi,
> >    I'm trying to write a plug-in which takes in a WAR file as input and
> > modifies the server.xml, copies the WAR into the directory of
> > jakarta-tomcat and then restart the server(or do i have the option of
> > hot deployment, without any restarts?)
> >
> >    Can some one please tell me which packages/classes of tomcat can be
> > used to do this?
> >
> > Thanks,
> > harish

Re: which classes to use to modify server.xml

Posted by Harish <ha...@postmark.net>.
Hi,

     This is for a scenario in which Tomcat is running on a
machine(which wasn't started from my program) and i need to connect to
it from my program and do an addition/modification/deletion of Contexts.

     I'm doing a look up in the RMI Registry to get a reference to the
HttpServer(Tomcat "HttpServer" class) running[All my program  knows is
the host/port number of the registry].I have overridden the
HttpServer.java, added a "getContextManager()" method using which i get
a ref. to the context Manager. This,i use to get the info all the
contexts i wish to modify(or delete etc.)
    
     I have a strong feeling that there's a neater way of doing it
instead of overriding HttpServer.java, something which i'm not able to
figure out. Do I need to use a Connector(excuse me if i'm wrong)?

someone please enlighten me,
Thanks,
harish

Harish wrote:
> 
> Hi,
>    I'm trying to write a plug-in which takes in a WAR file as input and
> modifies the server.xml, copies the WAR into the directory of
> jakarta-tomcat and then restart the server(or do i have the option of
> hot deployment, without any restarts?)
> 
>    Can some one please tell me which packages/classes of tomcat can be
> used to do this?
> 
> Thanks,
> harish