Making Apache httpd fallback to local file after receiving 404 from backend Tomcat?

2009-05-20 Thread Imner, Andreas
Hi all

I'm setting up a website using Apache webserver 2.2.11 / mod_jk 1.2.28 (Windows 
Server 2000) that connects to two 
backend Apache Tomcat 6.0.18 server (Windows Server 2003) with load balancing. 
The webserver also uses mod_proxy to forward some requests to an IIS5 server 
running on the same server but on a 
different port. 
The IIS5 hosts an Episerver 3 installation.

To speed things up, Apache webserver is serving the /images folder used by 
Episerver using an Alias directive

Alias /images "E:/Inetpub/EPiServer3/root/images"

Order deny,allow
Allow from all


For mod_jk, the uriworkermap.properties -file specifies that all requests to 
/images/... should be sent to 
Apache Tomcat since the webapp contains a lot of images with that path

/images/*=wlb


Is there some way to achieve any of the following behaviours?:

1.  A request for /images/logo.jpg is processed by Apache webserver (This 
file is located on the Apache webserver, in
E:/Inetpub/EPiServer3/root/images)
2.  Mod_jk forwards the request to an Apache Tomcat server which returns a 
404 since logo.jpg does not exist
on the server
3.  Apache webserver detects this 404 response and fetches logo.jpg from 
E:/Inetpub/EPiServer3/root/images and returns it

Alternative

1.  Same as above
2.  Apache webserver returns logo.jpg from E:/Inetpub/EPiServer3/root/images
(3. In the case that logo.jpg is not found in 
E:/Inetpub/EPiServer3/root/images, an attempt is made to send the request to 
the Apache Tomcat server using mod_jk)

I have done some research and came accross the mod_jk option ForwardDirectories 
but it doesnt seem to handle any of the above
scenarios? It seems more related to directory indexing?! (I'm quite new with 
Apache Webserver / Apache Tomcat :-) )

Thank you for your attention!

Best Regards
/Andreas Imner




-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



SV: Making Apache httpd fallback to local file after receiving 404 from backend Tomcat?

2009-05-20 Thread Imner, Andreas
 
Thanks for the reply and the thoughts about my question. 



Med vänlig hälsning
Andreas Imner
Systemutvecklare 
KG Knutsson AB
Autokatalogen

Tel: +46 8 92 34 37
Mobil: +46 70 606 34 37
andreas.im...@kgk.se 



-Ursprungligt meddelande-
Från: Pid [mailto:p...@pidster.com] 
Skickat: den 20 maj 2009 11:14
Till: Tomcat Users List
Ämne: Re: Making Apache httpd fallback to local file after receiving 404 from 
backend Tomcat?

Imner, Andreas wrote:
> Hi all
> 
> I'm setting up a website using Apache webserver 2.2.11 / mod_jk 1.2.28 
> (Windows Server 2000) that connects to two 
> backend Apache Tomcat 6.0.18 server (Windows Server 2003) with load 
> balancing. 
> The webserver also uses mod_proxy to forward some requests to an IIS5 server 
> running on the same server but on a 
> different port. 
> The IIS5 hosts an Episerver 3 installation.
> 
> To speed things up, Apache webserver is serving the /images folder used by 
> Episerver using an Alias directive
> 
> Alias /images "E:/Inetpub/EPiServer3/root/images"
> 
>   Order deny,allow
>   Allow from all
> 
> 
> For mod_jk, the uriworkermap.properties -file specifies that all requests to 
> /images/... should be sent to 
> Apache Tomcat since the webapp contains a lot of images with that path
> 
> /images/*=wlb

So the short version is that you have two images directories, with the
same external path and you want overlapping mappings?

Inventing some complex solution to resolve it seems like a poor choice
to me.  If you have control of one or either of the applications I'd
adjust the path to the images instead.

Otherwise you're probably looking at individually mapping each image
file, which would be tedious.

A simple solution will be better in the long run.

p



> Is there some way to achieve any of the following behaviours?:
> 
> 1.A request for /images/logo.jpg is processed by Apache webserver (This 
> file is located on the Apache webserver, in
>   E:/Inetpub/EPiServer3/root/images)
> 2.Mod_jk forwards the request to an Apache Tomcat server which returns a 
> 404 since logo.jpg does not exist
>   on the server
> 3.Apache webserver detects this 404 response and fetches logo.jpg from 
> E:/Inetpub/EPiServer3/root/images and returns it
> 
> Alternative
> 
> 1.Same as above
> 2.Apache webserver returns logo.jpg from E:/Inetpub/EPiServer3/root/images
> (3.   In the case that logo.jpg is not found in 
> E:/Inetpub/EPiServer3/root/images, an attempt is made to send the request to 
>   the Apache Tomcat server using mod_jk)
> 
> I have done some research and came accross the mod_jk option 
> ForwardDirectories but it doesnt seem to handle any of the above
> scenarios? It seems more related to directory indexing?! (I'm quite new with 
> Apache Webserver / Apache Tomcat :-) )
> 
> Thank you for your attention!
> 
> Best Regards
> /Andreas Imner
> 
> 
> 
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> 


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Why do stacktraces from servlets print to stdout, when the other end up in the log4j -log file?

2009-06-09 Thread Imner, Andreas

My companys web application uses log4j 1.2.8 for logging and have just recently 
switched from Weblogic to Tomcat 6.0.18.

Since the we switched to Tomcat, when we do some logging within a servlet
 
"
private static final Log log = LogFactory.getLog(ExceptionHandlerServlet.class);
log.error("some message, throwable);
"

The "some message" -line is written to the file specified by log4j, but why 
does the stacktrace gets written to Tomcats stdout.log?

This behaviour is for servlets only. For the other Java classes in the webapp, 
both the "some message" -line and the stacktrace is written to the file 
specified by log4j.


___

Extra info
The log -settings of Tomcat is the standard setup

This is our log4j.properties file

"
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.MaxBackupIndex=20
log4j.appender.A1.MaxFileSize=10MB

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %-5p %X{ak} [%c{1}] %m%n
log4j.rootLogger=ERROR, A1

log4j.category.se=INFO

# All System.out.println is redirected to stdout logger, INFO level
log4j.category.stdout=INFO

# All System.err.println (includes Exception.printStackTrace() is redirected to 
stderr logger, INFO level
log4j.category.stderr=INFO
"

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Why do stacktraces from servlets print to stdout, when the other end up in the log4j -log file?

2009-06-10 Thread Imner, Andreas
Hi

The Servlet does not propegate the error. This perticular servlet is one we use 
for handling "unhandled" exceptions and displaying an unexpected-error page to 
the user.
_
From web.xml


exceptionHandler

se.kgk.webshop.web.general.ExceptionHandlerServlet

errorPageURL
goto.do?forward=error

3



exceptionHandler
/error



  java.lang.Throwable
  /error



The servlet code looks something like this 

private static final Log log = 
LogFactory.getLog(ExceptionHandlerServlet.class);

protected void doPost(final HttpServletRequest request, final 
HttpServletResponse response)
throws ServletException {
try {
Throwable throwable = null;

( Some code to extract the throwable, the requestURI etc... )

log.error("Exception while handling request: " + requestURI, 
throwable);

request.getRequestDispatcher(errorPageURL).forward(request, 
response);

} catch (final Throwable t) {
   t.printStackTrace();
}
}




If we run the webapp in Weblogic, both the "Exception while handling..." 
message and the stacktrace gets printed to the log file specified by log4j

If we run exactly the same webapp in Tomcat, the "Exception while handling..." 
message is printed to the log4j -logfile but the stacktrace gets printed to 
stdout.log!?! 
Note that this only applies to log calls from within this servlet. Then doing 
the exact same log4j-call from within one of our filter -classes, everything 
works as expected. 

I suspect something is different with the servlet load sequence or log settings 
when using Tomcat, but what?






Med vänlig hälsning
Andreas Imner
Systemutvecklare 
KG Knutsson AB
Autokatalogen

Tel: +46 8 92 34 37
Mobil: +46 70 606 34 37
andreas.im...@kgk.se 



-Ursprungligt meddelande-
Från: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Skickat: den 9 juni 2009 21:57
Till: Tomcat Users List
Ämne: Re: Why do stacktraces from servlets print to stdout, when the other end 
up in the log4j -log file?

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Andreas,

On 6/9/2009 3:31 PM, Imner, Andreas wrote:
> My companys web application uses log4j 1.2.8 for logging and have
> just recently switched from Weblogic to Tomcat 6.0.18.
> 
> Since the we switched to Tomcat, when we do some logging within a
> servlet
> 
> " private static final Log log =
> LogFactory.getLog(ExceptionHandlerServlet.class);
> log.error("some message", throwable);
> "
> 
> The "some message" -line is written to the file specified by log4j,
> but why does the stacktrace gets written to Tomcats stdout.log?

That depends on what else is going on in your servlet. If you let the
exception propagate (by re-throwing it or throwing a new exception) and
nobody else catches it, then Tomcat's request processing thread code
will catch it and log it to stdout.

> This is our log4j.properties file
> 
> "
> log4j.appender.A1=org.apache.log4j.RollingFileAppender
> log4j.appender.A1.MaxBackupIndex=20
> log4j.appender.A1.MaxFileSize=10MB
> 
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> 
> log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %-5p %X{ak} [%c{1}] 
> %m%n
> log4j.rootLogger=ERROR, A1
> 
> log4j.category.se=INFO
> 
> # All System.out.println is redirected to stdout logger, INFO level
> log4j.category.stdout=INFO
> 
> # All System.err.println (includes Exception.printStackTrace() is redirected 
> to stderr logger, INFO level
> log4j.category.stderr=INFO
> "

The code you provided does not show any use of the "stdout" category,
but it doesn't really matter because the stdout category does not
actually log to stdout :)

Check to see that your code is not allowing exceptions to propagate.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkouvpkACgkQ9CaO5/Lv0PDwrACgsjUoqePn7xzDy5qVoBukKdOz
iboAn2qKdOJxCDKQ+/mtp5vDnbv1v5ZN
=AvA2
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



SV: Why do stacktraces from servlets print to stdout, when the other end up in the log4j -log file?

2009-06-10 Thread Imner, Andreas
My bad, I did not debug my servlet properly. If had done that earlier I would 
have seen that it was the extraction of the exception from the request object 
that failed.

When running the webapp in Weblogic as we did earlier, the following code 
worked as expected and the exception was properly fetched:

Object obj = request.getAttribute("javax.servlet.jsp.jspException"); 

When the webapp is running in Tomcat (version 6.0.18, running on Windows server 
2003 as a service, standard "package" downloaded from Tomcat homepage, standard 
Tomcat log settings) the call resulted in "obj" being set to null.

When I changed the code to,

Object obj = request.getAttribute("javax.servlet.error.exception");

... The exception is properly fetched and everyting works as expected also in 
Tomcat

/Andreas

-Ursprungligt meddelande-
Från: Imner, Andreas [mailto:andreas.im...@kgk.se] 
Skickat: den 10 juni 2009 11:09
Till: Tomcat Users List
Ämne: RE: Why do stacktraces from servlets print to stdout, when the other end 
up in the log4j -log file?

Hi

The Servlet does not propegate the error. This perticular servlet is one we use 
for handling "unhandled" exceptions and displaying an unexpected-error page to 
the user.
_
From web.xml


exceptionHandler

se.kgk.webshop.web.general.ExceptionHandlerServlet

errorPageURL
goto.do?forward=error

3



exceptionHandler
/error



  java.lang.Throwable
  /error



The servlet code looks something like this 

private static final Log log = 
LogFactory.getLog(ExceptionHandlerServlet.class);

protected void doPost(final HttpServletRequest request, final 
HttpServletResponse response)
throws ServletException {
try {
Throwable throwable = null;

( Some code to extract the throwable, the requestURI etc... )

log.error("Exception while handling request: " + requestURI, 
throwable);

request.getRequestDispatcher(errorPageURL).forward(request, 
response);

} catch (final Throwable t) {
   t.printStackTrace();
}
}




If we run the webapp in Weblogic, both the "Exception while handling..." 
message and the stacktrace gets printed to the log file specified by log4j

If we run exactly the same webapp in Tomcat, the "Exception while handling..." 
message is printed to the log4j -logfile but the stacktrace gets printed to 
stdout.log!?! 
Note that this only applies to log calls from within this servlet. Then doing 
the exact same log4j-call from within one of our filter -classes, everything 
works as expected. 

I suspect something is different with the servlet load sequence or log settings 
when using Tomcat, but what?



-Ursprungligt meddelande-
Från: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Skickat: den 9 juni 2009 21:57
Till: Tomcat Users List
Ämne: Re: Why do stacktraces from servlets print to stdout, when the other end 
up in the log4j -log file?

-----BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Andreas,

On 6/9/2009 3:31 PM, Imner, Andreas wrote:
> My companys web application uses log4j 1.2.8 for logging and have
> just recently switched from Weblogic to Tomcat 6.0.18.
> 
> Since the we switched to Tomcat, when we do some logging within a
> servlet
> 
> " private static final Log log =
> LogFactory.getLog(ExceptionHandlerServlet.class);
> log.error("some message", throwable);
> "
> 
> The "some message" -line is written to the file specified by log4j,
> but why does the stacktrace gets written to Tomcats stdout.log?

That depends on what else is going on in your servlet. If you let the
exception propagate (by re-throwing it or throwing a new exception) and
nobody else catches it, then Tomcat's request processing thread code
will catch it and log it to stdout.

> This is our log4j.properties file
> 
> "
> log4j.appender.A1=org.apache.log4j.RollingFileAppender
> log4j.appender.A1.MaxBackupIndex=20
> log4j.appender.A1.MaxFileSize=10MB
> 
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> 
> log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %-5p %X{ak} [%c{1}] 
> %m%n
> log4j.rootLogger=ERROR, A1
> 
> log4j.category.se=INFO
> 
> # All System.out.println is redirected to stdout logger, INFO level
> log4j.category.stdout=INFO
> 
> # All System.err.println (includes Exception.printStackTrace() is redirected 
> to stderr logger, INFO level
> log4j.category.stderr=INFO
> "

The code you provided does not show any use of the "stdout" category,
but it doesn&#