Servlet Mapping Recursion Problem

2001-05-11 Thread Bill Winspur




In my web.xml I set up the servlet mapping, for a (front) servlet to handle 
all requests for the web app, to '/'. This works to the extent that all requests 
are passed to the servlet. BUT... if I do a forward to another resource from the 
servlet, the servlet's doGet() method is invoked recursively with no response 
generated until the jvm runs out of memory. The same thing happens with a 
url-pattern of '/*'. If the servlet 
itself generates html output, that works. If I map my servlet to a specific resource, like /index.html, forwarding 
works fine, but the servlet cant handle 
all requests and 'http://myhost/myapp' returns 'no directory browsing'. 

The url-pattern '/' seems like a valid 
directory specification (as per the servlet 2.2 spec, 'Servlet Mapping 
Techniques') and a front component, handling all requests is fundamental in the 
j2EE blueprints (http://java.sun.com/j2ee/blueprints/index.html, section 10.6), 
so my approach seems architecturally reasonable.

I've looked thru the archives and found two reports of the same problem. A 
proposed workaround from Magnus seems to recommend explicitly mapping every 
request your app generates (which would make the web.xml coding difficult to 
maintain in a large app) pendng the delivery of 'filters', perhaps in Servlet 
2.3. I dont really understand what Magnus is suggesting:
PS: If you're bound to 2.2 or lower then you will not be able to use 
Filters, in that case you'd have to apply a more complex solution with duplicate 
resource roots and so on.
It looks like 'no front servlets on Orion' to me, but I hope I'm wrong.
I was not able to find any references to the problem on bugzilla, but I'm not 
very adept with its query interface.
My hunch is that Orion's request dispatcher is invoked in two contexts (from 
a client, and from a forward) and does not distinguishbetween them when it 
comes to selectinga resource to respond to the client. Ifthe 
dispatcher ignored mapping in the forward context and just accepted the 
specified resource, the recursion problem would vanish and the front servlet 
would trap ALL client requests as per the blueprint architecture. Just a hunch, 
things are probably not that simple.
Does anyone know if this is a problem with other webservers ? My experience 
with Apache was all static pages.
My environment is NT4(sp6), Orion 1.4.8, IE 5.00, JDK 1.2.2.
Also, if somebody is actually using the front servlet pattern and univeral 
mapping on Orion, and could let me know how to set it up and/or get around the 
recursion I'd be a happy camper. 
TIA,
Bill.


RE: Servlet Mapping Recursion Problem

2001-05-11 Thread elephantwalker



Bill,

yeh...we need the apache url re-writting stuff in a 
servlet. That's an issue with orion. I think the opensymphony people are writing 
something.

There 
is a simple workaround. Have a forward.jsp as your welcome page for the default 
app. In the forward.jsp, use this code:

% String servletPath = 
request.getRequestURI().substring(0, 
request.getRequestURI().indexOf(request.getServletPath())); 
response.sendRedirect(servletPath+"/somepath/to/index or home or whatever.html") 
;

%

the 
somepath can be /main/home.html, for example.

in 
your web.xml, map your "controller-rewriter servlet" to the 
/main/*

so 
instead of yourpages asking for resouces at /myfavoritegif.gif, they would 
just be /main/myfavoritegif.gif. 

This 
is ugly, and quick and dirty, but it works. You can even read in an xml file 
when you rewriter servlet starts up so that all of your path mapping, rewritting 
works like apache.

Regards,

The 
elephantwalker





  -Original Message-From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED]]On Behalf Of Bill 
  WinspurSent: Thursday, May 10, 2001 8:51 AMTo: 
  Orion-InterestSubject: Servlet Mapping Recursion 
  Problem
  
  In my web.xml I set up the servlet mapping, for a (front) servlet to handle 
  all requests for the web app, to '/'. This works to the extent that all 
  requests are passed to the servlet. BUT... if I do a forward to another 
  resource from the servlet, the servlet's doGet() method is invoked recursively 
  with no response generated until the jvm runs out of memory. The same thing 
  happens with a url-pattern of '/*'. If 
  the servlet itself generates html output, that works. If I map my servlet to a specific resource, like 
  /index.html, forwarding works fine, but the servlet cant handle all requests and 'http://myhost/myapp' returns 
  'no directory browsing'. 
  The url-pattern '/' seems like a valid 
  directory specification (as per the servlet 2.2 spec, 'Servlet Mapping 
  Techniques') and a front component, handling all requests is fundamental in 
  the j2EE blueprints (http://java.sun.com/j2ee/blueprints/index.html, section 
  10.6), so my approach seems architecturally reasonable.
  
  I've looked thru the archives and found two reports of the same problem. A 
  proposed workaround from Magnus seems to recommend explicitly mapping every 
  request your app generates (which would make the web.xml coding difficult to 
  maintain in a large app) pendng the delivery of 'filters', perhaps in Servlet 
  2.3. I dont really understand what Magnus is suggesting:
  PS: If you're bound to 2.2 or lower then you will not be able to use 
  Filters, in that case you'd have to apply a more complex solution with 
  duplicate resource roots and so on.
  It looks like 'no front servlets on Orion' to me, but I hope I'm wrong.
  I was not able to find any references to the problem on bugzilla, but I'm 
  not very adept with its query interface.
  My hunch is that Orion's request dispatcher is invoked in two contexts 
  (from a client, and from a forward) and does not distinguishbetween them 
  when it comes to selectinga resource to respond to the client. 
  Ifthe dispatcher ignored mapping in the forward context and just 
  accepted the specified resource, the recursion problem would vanish and the 
  front servlet would trap ALL client requests as per the blueprint 
  architecture. Just a hunch, things are probably not that simple.
  Does anyone know if this is a problem with other webservers ? My experience 
  with Apache was all static pages.
  My environment is NT4(sp6), Orion 1.4.8, IE 5.00, JDK 1.2.2.
  Also, if somebody is actually using the front servlet pattern and univeral 
  mapping on Orion, and could let me know how to set it up and/or get around the 
  recursion I'd be a happy camper. 
  TIA,
  Bill.


Re: Servlet Mapping Recursion Problem

2001-05-11 Thread Joni Suominen

Hi Bill!
I am using a front servlet pattern with Orion. I use Struts but I
suppose this approach should work in any framework.

1. The front servlet mapping in web.xml:
  servlet-mapping
servlet-nameaction/servlet-name
url-pattern*.html/url-pattern
  /servlet-mapping

So all the requests ending to .html are processed by the front-end
servlet.

2. All the valid URL's are mapped in an xml config file. The front
servlet initializes its state by reading this file in a startup. An
entry in this file looks like:
  actionpath=/faq
 type=org.shiftctrl.general.interaction.EmptyAction
forward name=success  path=/faq.jsp/
  /action

This means that the request http://myserver.com/faq.html is first
processed by front servlet. The servlet searches its configured mapping
and forwards the request. In this case it would forward the request to
faq.jsp.

I haven't had problems with this setup and I really like it for
following reasons:
1. It is easy pipeline actions. Just configure the mapping so that its
forward part points to another mapping.
2. You can hide the technology being used. Clients only see URLs which
are always ending .html (so .jsps are not exposed outside, their
function is only to provide the view part in MVC pattern)
3. It is possible to dynamically change the URL mapping by calling
appropriate methods in front servlet.

--
Joni
[EMAIL PROTECTED]

 Bill Winspur wrote:
 
 In my web.xml I set up the servlet mapping, for a (front) servlet to
 handle all requests for the web app, to '/'. This works to the extent
 that all requests are passed to the servlet. BUT... if I do a forward
 to another resource from the servlet, the servlet's doGet() method is
 invoked recursively with no response generated until the jvm runs out
 of memory. The same thing happens with a url-pattern of '/*'. If the
 servlet itself generates html output, that works.  If I map my servlet
 to a specific resource, like /index.html, forwarding works fine, but
 the servlet cant handle all requests and 'http://myhost/myapp' returns
 'no directory browsing'.
 
 The url-pattern '/' seems like a valid directory specification (as per
 the servlet 2.2 spec, 'Servlet Mapping Techniques') and a front
 component, handling all requests is fundamental in the j2EE blueprints
 (http://java.sun.com/j2ee/blueprints/index.html, section 10.6), so my
 approach seems architecturally reasonable.
 
 I've looked thru the archives and found two reports of the same
 problem. A proposed workaround from Magnus seems to recommend
 explicitly mapping every request your app generates (which would make
 the web.xml coding difficult to maintain in a large app) pendng the
 delivery of 'filters', perhaps in Servlet 2.3. I dont really
 understand what Magnus is suggesting:
 
 PS: If you're bound to 2.2 or lower then you will not be able to use
 Filters, in that case you'd have to apply a more complex solution with
 duplicate resource roots and so on.
 
 It looks like 'no front servlets on Orion' to me, but I hope I'm
 wrong.
 
 I was not able to find any references to the problem on bugzilla, but
 I'm not very adept with its query interface.
 
 My hunch is that Orion's request dispatcher is invoked in two contexts
 (from a client, and from a forward) and does not distinguish between
 them when it comes to selecting a resource to respond to the client.
 If the dispatcher ignored mapping in the forward context and just
 accepted the specified resource, the recursion problem would vanish
 and the front servlet would trap ALL client requests as per the
 blueprint architecture. Just a hunch, things are probably not that
 simple.
 
 Does anyone know if this is a problem with other webservers ? My
 experience with Apache was all static pages.
 
 My environment is NT4(sp6), Orion 1.4.8, IE 5.00, JDK 1.2.2.
 
 Also, if somebody is actually using the front servlet pattern and
 univeral mapping on Orion, and could let me know how to set it up
 and/or get around the recursion I'd be a happy camper.
 
 TIA,
 
 Bill.




Re: Servlet Mapping Recursion Problem

2001-05-11 Thread Bill Winspur

Thanks Joni,

very elegant. I've started down that route (ie. having externally visible
urls that are different to the internally visible urls), but hadn't thought
of driving the whole thing off a configuration file.  Neat. The application
provider could package it with the app, leaving the front servlet truly
generic. Also, the *.html servlet-mapping hides *.gif resource mapping, etc.
from the servlet.. And reason number four to like this approach is: it
should work on any webserver.

After my previous post I discovered that recursion doesn't just happen if
the '/' is mapped to your front servlet (it seems obvious now).  If you map
'myUrl' to your front servlet, and then forward to 'myUrl', you also get
recursion and a crash.

Its been a good day,

Bill.


- Original Message -
From: Joni Suominen [EMAIL PROTECTED]
To: Orion-Interest [EMAIL PROTECTED]
Sent: Friday, May 11, 2001 11:48 AM
Subject: Re: Servlet Mapping Recursion Problem


 Hi Bill!
 I am using a front servlet pattern with Orion. I use Struts but I
 suppose this approach should work in any framework.

 1. The front servlet mapping in web.xml:
   servlet-mapping
 servlet-nameaction/servlet-name
 url-pattern*.html/url-pattern
   /servlet-mapping

 So all the requests ending to .html are processed by the front-end
 servlet.

 2. All the valid URL's are mapped in an xml config file. The front
 servlet initializes its state by reading this file in a startup. An
 entry in this file looks like:
   actionpath=/faq
  type=org.shiftctrl.general.interaction.EmptyAction
 forward name=success  path=/faq.jsp/
   /action

 This means that the request http://myserver.com/faq.html is first
 processed by front servlet. The servlet searches its configured mapping
 and forwards the request. In this case it would forward the request to
 faq.jsp.

 I haven't had problems with this setup and I really like it for
 following reasons:
 1. It is easy pipeline actions. Just configure the mapping so that its
 forward part points to another mapping.
 2. You can hide the technology being used. Clients only see URLs which
 are always ending .html (so .jsps are not exposed outside, their
 function is only to provide the view part in MVC pattern)
 3. It is possible to dynamically change the URL mapping by calling
 appropriate methods in front servlet.

 --
 Joni
 [EMAIL PROTECTED]

  Bill Winspur wrote:
 
  In my web.xml I set up the servlet mapping, for a (front) servlet to
  handle all requests for the web app, to '/'. This works to the extent
  that all requests are passed to the servlet. BUT... if I do a forward
  to another resource from the servlet, the servlet's doGet() method is
  invoked recursively with no response generated until the jvm runs out
  of memory. The same thing happens with a url-pattern of '/*'. If the
  servlet itself generates html output, that works.  If I map my servlet
  to a specific resource, like /index.html, forwarding works fine, but
  the servlet cant handle all requests and 'http://myhost/myapp' returns
  'no directory browsing'.
 
  The url-pattern '/' seems like a valid directory specification (as per
  the servlet 2.2 spec, 'Servlet Mapping Techniques') and a front
  component, handling all requests is fundamental in the j2EE blueprints
  (http://java.sun.com/j2ee/blueprints/index.html, section 10.6), so my
  approach seems architecturally reasonable.
 
  I've looked thru the archives and found two reports of the same
  problem. A proposed workaround from Magnus seems to recommend
  explicitly mapping every request your app generates (which would make
  the web.xml coding difficult to maintain in a large app) pendng the
  delivery of 'filters', perhaps in Servlet 2.3. I dont really
  understand what Magnus is suggesting:
 
  PS: If you're bound to 2.2 or lower then you will not be able to use
  Filters, in that case you'd have to apply a more complex solution with
  duplicate resource roots and so on.
 
  It looks like 'no front servlets on Orion' to me, but I hope I'm
  wrong.
 
  I was not able to find any references to the problem on bugzilla, but
  I'm not very adept with its query interface.
 
  My hunch is that Orion's request dispatcher is invoked in two contexts
  (from a client, and from a forward) and does not distinguish between
  them when it comes to selecting a resource to respond to the client.
  If the dispatcher ignored mapping in the forward context and just
  accepted the specified resource, the recursion problem would vanish
  and the front servlet would trap ALL client requests as per the
  blueprint architecture. Just a hunch, things are probably not that
  simple.
 
  Does anyone know if this is a problem with other webservers ? My
  experience with Apache was all static pages.
 
  My environment is NT4(sp6), Orion 1.4.8, IE 5.00, JDK 1.2.2.
 
  Also, if somebody is actually using the front servlet pattern and
  univeral mapping on Orion, and could let me know how