You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Malin Ljungh <ma...@gmail.com> on 2007/10/17 17:13:18 UTC

T4.1: How to filter out exceptions from bots?

Hi all,

I've got some annoying stack traces in my log from bots, primarily a bot
called LiteFinder but also Googlebot. (the LiteFinder seems to get lowercase
URLs which results in many org.apache.tapestry.PageNotFoundException since I
use uppercase first letter of my pages)

I print stack trace in the exception page setException method - how can I at
this point detect the user-agent and just ignore it?

Cheers,
Malin

Re: T4.1: How to filter out exceptions from bots?

Posted by Malin Ljungh <ma...@gmail.com>.
Thanks A LOT!
Exactly what I was looking for - works great!

Malin

On 10/18/07, Ulrich Stärk <ul...@spielviel.de> wrote:
>
> Malin Ljungh schrieb:
> > Hi all,
> >
> > I've got some annoying stack traces in my log from bots, primarily a bot
> > called LiteFinder but also Googlebot. (the LiteFinder seems to get
> lowercase
> > URLs which results in many org.apache.tapestry.PageNotFoundExceptionsince I
> > use uppercase first letter of my pages)
> >
> > I print stack trace in the exception page setException method - how can
> I at
> > this point detect the user-agent and just ignore it?
> >
> > Cheers,
> > Malin
> >
>
> Just inject the WebRequest into your page and check for any unwanted
> user agents in your setException() method.
>
> @InjectObject("infrastructure:request")
> public abstract WebRequest getRequest();
>
> public void setException(Throwable t)
> {
>      String userAgent = getRequest().getHeader("User-Agent");
>      if(!isUnwanted(userAgent))
>      {
>          // user agent is valid
>          // do your logging stuff or whatever
>      }
> }
>
> Uli
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T4.1: How to filter out exceptions from bots?

Posted by Ulrich Stärk <ul...@spielviel.de>.
Malin Ljungh schrieb:
> Hi all,
> 
> I've got some annoying stack traces in my log from bots, primarily a bot
> called LiteFinder but also Googlebot. (the LiteFinder seems to get lowercase
> URLs which results in many org.apache.tapestry.PageNotFoundException since I
> use uppercase first letter of my pages)
> 
> I print stack trace in the exception page setException method - how can I at
> this point detect the user-agent and just ignore it?
> 
> Cheers,
> Malin
> 

Just inject the WebRequest into your page and check for any unwanted 
user agents in your setException() method.

@InjectObject("infrastructure:request")
public abstract WebRequest getRequest();

public void setException(Throwable t)
{
     String userAgent = getRequest().getHeader("User-Agent");
     if(!isUnwanted(userAgent))
     {
         // user agent is valid
         // do your logging stuff or whatever
     }
}

Uli

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org