You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Jason Novotny <no...@gridsphere.org> on 2006/10/10 01:33:26 UTC

using manager webapp programatically

Hi,

    I have a webapp (a portal) that sets the crossContext="true" and so 
can accesss other webapps in Tomcat. My goal is to do an include() on 
the manager webapp to show the deployed applications. Here is my code:

doGet(HttpServletRequest req, HttpServletResponse res) throws 
IOException, ServletException {

ServletContext context = ctx.getContext("/manager");   
context.getRequestDispatcher("/list").include(req, res);
       
}

Unfortunately I get the following:

FAIL - Unknown command /portal

I looked at the source code of the manager app and I see it has this line:

String command = request.getPathInfo();
        if (command == null)
            command = request.getServletPath();

So it looks like request.getPathInfo() is returning null so then it uses 
the getServletPath which returns my servlet path that is doing the 
dispatching, "portal" and not "/list" as I desire. Is that expected 
behaavior?

I finally "hacked" something together, where I have to pass in my own 
implementation of HttpServletRequest object in the include(),  where the 
getPathInfo returns a hardcoded "/list"-- it works but is a terrible 
hack. I'm wondering if there is a better way-- or maybe the manager 
webapp could be altered so that instead of doing request.getPathInfo it 
could do some kind of request.getParameter().. in which case the manager 
webapp would be invoked by doing /manager?command=list instead of 
/manager/list

    Thanks, Jason








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


Re: using manager webapp programatically

Posted by Yoav Shapira <yo...@apache.org>.
Hi,
Download mc4j (http://mc4j.org/confluence/display/mc4j/Home) or
jmanage (http://www.jmanage.org/) or JBoss Console
(http://jboss.org/wiki/Wiki.jsp?page=JMXConsole) and take a look at
their source code.  It's simple, elegant, and effective (all three
work well, and there are several others).

Yoav

On 10/10/06, Jason Novotny <no...@gridsphere.org> wrote:
>
>     Cool-- I'm new to JMX, can you provide any sample snippet code or
> place to look in order to use the Tomcat JMX stuff?
>
>     Thanks a bunch, Jason
>
> Yoav Shapira wrote:
> > Hi,
> > I don't have time to delve deeply into looking at the manager app
> > request path info code right now, but a quick suggestion: if I were to
> > do anything building on top of the manager / admin webapp
> > functionality, I wouldn't do it via request includes, and I would
> > instead build on top of the JMX stuff exposed by Tomcat.  That should
> > not only be easier, but more portable because your app and the manager
> > app wouldn't have to run on the same instance of Tomcat (which you do
> > when you rely on crossContext).
> >
> > Yoav
> >
> > On 10/9/06, Jason Novotny <no...@gridsphere.org> wrote:
> >>
> >> Hi,
> >>
> >>     I have a webapp (a portal) that sets the crossContext="true" and so
> >> can accesss other webapps in Tomcat. My goal is to do an include() on
> >> the manager webapp to show the deployed applications. Here is my code:
> >>
> >> doGet(HttpServletRequest req, HttpServletResponse res) throws
> >> IOException, ServletException {
> >>
> >> ServletContext context = ctx.getContext("/manager");
> >> context.getRequestDispatcher("/list").include(req, res);
> >>
> >> }
> >>
> >> Unfortunately I get the following:
> >>
> >> FAIL - Unknown command /portal
> >>
> >> I looked at the source code of the manager app and I see it has this
> >> line:
> >>
> >> String command = request.getPathInfo();
> >>         if (command == null)
> >>             command = request.getServletPath();
> >>
> >> So it looks like request.getPathInfo() is returning null so then it uses
> >> the getServletPath which returns my servlet path that is doing the
> >> dispatching, "portal" and not "/list" as I desire. Is that expected
> >> behaavior?
> >>
> >> I finally "hacked" something together, where I have to pass in my own
> >> implementation of HttpServletRequest object in the include(),  where the
> >> getPathInfo returns a hardcoded "/list"-- it works but is a terrible
> >> hack. I'm wondering if there is a better way-- or maybe the manager
> >> webapp could be altered so that instead of doing request.getPathInfo it
> >> could do some kind of request.getParameter().. in which case the manager
> >> webapp would be invoked by doing /manager?command=list instead of
> >> /manager/list
> >>
> >>     Thanks, Jason
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: dev-help@tomcat.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: dev-help@tomcat.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

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


Re: using manager webapp programatically

Posted by Jason Novotny <no...@gridsphere.org>.
    Cool-- I'm new to JMX, can you provide any sample snippet code or 
place to look in order to use the Tomcat JMX stuff?

    Thanks a bunch, Jason

Yoav Shapira wrote:
> Hi,
> I don't have time to delve deeply into looking at the manager app
> request path info code right now, but a quick suggestion: if I were to
> do anything building on top of the manager / admin webapp
> functionality, I wouldn't do it via request includes, and I would
> instead build on top of the JMX stuff exposed by Tomcat.  That should
> not only be easier, but more portable because your app and the manager
> app wouldn't have to run on the same instance of Tomcat (which you do
> when you rely on crossContext).
>
> Yoav
>
> On 10/9/06, Jason Novotny <no...@gridsphere.org> wrote:
>>
>> Hi,
>>
>>     I have a webapp (a portal) that sets the crossContext="true" and so
>> can accesss other webapps in Tomcat. My goal is to do an include() on
>> the manager webapp to show the deployed applications. Here is my code:
>>
>> doGet(HttpServletRequest req, HttpServletResponse res) throws
>> IOException, ServletException {
>>
>> ServletContext context = ctx.getContext("/manager");
>> context.getRequestDispatcher("/list").include(req, res);
>>
>> }
>>
>> Unfortunately I get the following:
>>
>> FAIL - Unknown command /portal
>>
>> I looked at the source code of the manager app and I see it has this 
>> line:
>>
>> String command = request.getPathInfo();
>>         if (command == null)
>>             command = request.getServletPath();
>>
>> So it looks like request.getPathInfo() is returning null so then it uses
>> the getServletPath which returns my servlet path that is doing the
>> dispatching, "portal" and not "/list" as I desire. Is that expected
>> behaavior?
>>
>> I finally "hacked" something together, where I have to pass in my own
>> implementation of HttpServletRequest object in the include(),  where the
>> getPathInfo returns a hardcoded "/list"-- it works but is a terrible
>> hack. I'm wondering if there is a better way-- or maybe the manager
>> webapp could be altered so that instead of doing request.getPathInfo it
>> could do some kind of request.getParameter().. in which case the manager
>> webapp would be invoked by doing /manager?command=list instead of
>> /manager/list
>>
>>     Thanks, Jason
>>
>>
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: dev-help@tomcat.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>


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


Re: using manager webapp programatically

Posted by Yoav Shapira <yo...@apache.org>.
Hi,
I don't have time to delve deeply into looking at the manager app
request path info code right now, but a quick suggestion: if I were to
do anything building on top of the manager / admin webapp
functionality, I wouldn't do it via request includes, and I would
instead build on top of the JMX stuff exposed by Tomcat.  That should
not only be easier, but more portable because your app and the manager
app wouldn't have to run on the same instance of Tomcat (which you do
when you rely on crossContext).

Yoav

On 10/9/06, Jason Novotny <no...@gridsphere.org> wrote:
>
> Hi,
>
>     I have a webapp (a portal) that sets the crossContext="true" and so
> can accesss other webapps in Tomcat. My goal is to do an include() on
> the manager webapp to show the deployed applications. Here is my code:
>
> doGet(HttpServletRequest req, HttpServletResponse res) throws
> IOException, ServletException {
>
> ServletContext context = ctx.getContext("/manager");
> context.getRequestDispatcher("/list").include(req, res);
>
> }
>
> Unfortunately I get the following:
>
> FAIL - Unknown command /portal
>
> I looked at the source code of the manager app and I see it has this line:
>
> String command = request.getPathInfo();
>         if (command == null)
>             command = request.getServletPath();
>
> So it looks like request.getPathInfo() is returning null so then it uses
> the getServletPath which returns my servlet path that is doing the
> dispatching, "portal" and not "/list" as I desire. Is that expected
> behaavior?
>
> I finally "hacked" something together, where I have to pass in my own
> implementation of HttpServletRequest object in the include(),  where the
> getPathInfo returns a hardcoded "/list"-- it works but is a terrible
> hack. I'm wondering if there is a better way-- or maybe the manager
> webapp could be altered so that instead of doing request.getPathInfo it
> could do some kind of request.getParameter().. in which case the manager
> webapp would be invoked by doing /manager?command=list instead of
> /manager/list
>
>     Thanks, Jason
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

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