You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Bethoju, Praveen" <Be...@consumer.org> on 2011/07/28 22:08:23 UTC
Custom Error Handler servlet
Hi -
I'd like to create a custom error handler that will handle exceptions thrown
from scripts (at a specific path... ex: /content/api/*) and I want
errors/exceptions from all other servlets/scripts to be handled in the
default way (when no custom error handlers are set) using
DefaultErrorHandlerServlet.
For this purpose, I created a Servlet and mapped it to
"/apps/sling/servlet/errorhandler/default"
/**
*
* @scr.component metatype="no" immediate="true"
* @scr.service interface="javax.servlet.Servlet"
*
* This is the custom error handler servlet
*
* @scr.property name="sling.servlet.paths"
value="/apps/sling/servlet/errorhandler/default"
* @scr.property name="sling.servlet.prefix" value="0"
*
*
*/
public class CustomExceptionHandlerServlet extends GenericServlet {
/**
* @scr.reference policy="static"
*/
protected DefaultErrorHandlerServlet theDefaultErrorHandlerServlet;
@Override
public void service(ServletRequest request, ServletResponse response)
throws IOException {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)
request;
SlingHttpServletResponse slingResponse = (SlingHttpServletResponse)
response;
String resourcePath =
request.getRequestPathInfo().getResourcePath();
if(resourcePath.contains("/content/api"))
{
// perform custom processing.
}
else
{
// Somehow forward to the default error handler servlet
// or call the default error handler servlet, may be this way ?
theDefaultErrorHandlerServlet.service(request, response);
}
}
}
I have two questions:
1. In Felix, I see that there's an active component called - "
org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServ
let" available. So, I've added a reference to it from my
CustomExceptionHandlerServlet class. But for some reason, this dependency is
"unsatisfied". Not sure if I am not doing this wiring correctly. Please
advise.
2. If I can't wire the DefaultErrorHandlerServlet as in #1 or if its not the
approach to take, is there a way to forward processing of the error to the
default error handler servlet?
Thanks
Praveen
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
Re: Custom Error Handler servlet
Posted by "Bethoju, Praveen" <Be...@consumer.org>.
OptingServlet was what I needed.
Thanks all !!
On 7/29/11 8:32 AM, "Justin Edelson" <ju...@justinedelson.com> wrote:
You can use OptingServlet with a JSP.
On Jul 29, 2011, at 7:09 AM, sam " <sk...@gmail.com> wrote:
> If OSGi gets hairy, just store jsp in the repository.
>
> /apps/sling/servlet/errorhandler/Throwable.jsp
>
> look here:
> http://sling.apache.org/site/errorhandling.html
>
>
>
> On Fri, Jul 29, 2011 at 1:34 AM, Eric Norman <er...@gmail.com>wrote:
>
>> I haven't tried this, but it seems like implementing the OptingServlet
>> interface may do what you need.
>>
>> OptingServlet is described briefly @
>> http://sling.apache.org/site/servlets.html
>>
>>
>> Regards,
>> Eric
>>
>> On Thu, Jul 28, 2011 at 9:04 PM, Bethoju, Praveen <BethPr@consumer.org
>>> wrote:
>>
>>> I tried using sling.servlet.resourceTypes instead of the
>> slingservlet.paths
>>> as suggested but I still have my component's (
>> CustomExceptionHandlerServlet
>>> ) status = "unsatisfied". I think this makes my component unavailable as
>> a
>>> replacement to the default error handler.
>>>
>>> The CustomExceptionHandlerServlet servlet is a part of my OSGI bundle.
>> And
>>> the DefaultErrorHandlerServlet provided by Sling is a part of
>>> org.apache.sling.servlets.resolver bundle. Do I need to add
>>> org.apache.sling.servlets.resolver.* to the import-package definition of
>> my
>>> bundle ?
>>>
>>> My Maven bundle plugin configurations for my OSGI bundle (CUUtilities)
>>> looks like this ..
>>>
>>> <plugin>
>>> <groupId>org.apache.felix</groupId>
>>> <artifactId>maven-bundle-plugin</artifactId>
>>> <extensions>true</extensions>
>>> <configuration>
>>> <instructions>
>>>
>>>
>> <Bundle-SymbolicName>org.consumersunion.cq.CUUtilities</Bundle-SymbolicName>
>>>
>>> <Bundle-Activator>org.consumersunion.cq.Activator</Bundle-Activator>
>>> <Export-Package>
>>>
>>>
>> com.day.cu.creator.*,org.consumersunion.*,org.consumerreports.*;version="${project.version}",com.emeta.*,org.cu.*,org.jdom.*,com.opensymphony.oscache.*;version="2.1",com.google.*;version="1.0",org.codehaus.jackson.*,net.sf.ehcache.*
>>> </Export-Package>
>>>
>>> <Import-Package>*;resolution:=optional</Import-Package>
>>> <Bundle-License>n/a</Bundle-License>
>>> <Bundle-Copyright>Copyright (c) Consumers Reports
>>> 2011. All Rights Reserved.</Bundle-Copyright>
>>>
>>> <excludeDependencies>*;scope=provided|runtime</excludeDependencies>
>>> </instructions>
>>> </configuration>
>>> </plugin>
>>>
>>> Thanks for any help.
>>> - Praveen
>>>
>>>
>>> On 7/28/11 8:35 PM, "sam "" <sk...@gmail.com> wrote:
>>>
>>> can you try @scr.property sling.servlet.resourceTypes =
>>> "sling/servlet/errorhandler/default"
>>> ?
>>>
>>>
>>>
>>> On Thu, Jul 28, 2011 at 4:08 PM, Bethoju, Praveen <BethPr@consumer.org
>>>> wrote:
>>>
>>>> Hi -
>>>>
>>>> I'd like to create a custom error handler that will handle exceptions
>>>> thrown
>>>> from scripts (at a specific path... ex: /content/api/*) and I want
>>>> errors/exceptions from all other servlets/scripts to be handled in the
>>>> default way (when no custom error handlers are set) using
>>>> DefaultErrorHandlerServlet.
>>>>
>>>> For this purpose, I created a Servlet and mapped it to
>>>> "/apps/sling/servlet/errorhandler/default"
>>>>
>>>> /**
>>>> *
>>>> * @scr.component metatype="no" immediate="true"
>>>> * @scr.service interface="javax.servlet.Servlet"
>>>> *
>>>> * This is the custom error handler servlet
>>>> *
>>>> * @scr.property name="sling.servlet.paths"
>>>> value="/apps/sling/servlet/errorhandler/default"
>>>> * @scr.property name="sling.servlet.prefix" value="0"
>>>> *
>>>> *
>>>> */
>>>> public class CustomExceptionHandlerServlet extends GenericServlet {
>>>>
>>>> /**
>>>> * @scr.reference policy="static"
>>>> */
>>>> protected DefaultErrorHandlerServlet theDefaultErrorHandlerServlet;
>>>>
>>>>
>>>> @Override
>>>> public void service(ServletRequest request, ServletResponse
>> response)
>>>> throws IOException {
>>>>
>>>> SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)
>>>> request;
>>>> SlingHttpServletResponse slingResponse =
>>> (SlingHttpServletResponse)
>>>> response;
>>>>
>>>> String resourcePath =
>>>> request.getRequestPathInfo().getResourcePath();
>>>> if(resourcePath.contains("/content/api"))
>>>> {
>>>> // perform custom processing.
>>>> }
>>>> else
>>>> {
>>>> // Somehow forward to the default error handler servlet
>>>> // or call the default error handler servlet, may be this
>> way
>>> ?
>>>> theDefaultErrorHandlerServlet.service(request, response);
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>> I have two questions:
>>>>
>>>> 1. In Felix, I see that there's an active component called - "
>>>>
>>>>
>>>
>> org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServ
>>>> let" available. So, I've added a reference to it from my
>>>> CustomExceptionHandlerServlet class. But for some reason, this
>> dependency
>>>> is
>>>> "unsatisfied". Not sure if I am not doing this wiring correctly. Please
>>>> advise.
>>>>
>>>> 2. If I can't wire the DefaultErrorHandlerServlet as in #1 or if its
>> not
>>>> the
>>>> approach to take, is there a way to forward processing of the error to
>>> the
>>>> default error handler servlet?
>>>>
>>>> Thanks
>>>> Praveen
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> **
>>>> This e-mail message is intended only for the designated recipient(s)
>>> named
>>>> above. The information contained in this e-mail and any attachments may
>>> be
>>>> confidential or legally privileged. If you are not the intended
>>> recipient,
>>>> you may not review, retain, copy, redistribute or use this e-mail or
>> any
>>>> attachment for any purpose, or disclose all or any part of its
>> contents.
>>> If
>>>> you have received this e-mail in error, please immediately notify the
>>> sender
>>>> by reply e-mail and permanently delete this e-mail and any attachments
>>> from
>>>> your computer system.
>>>>
>>>
>>>
>>> ***
>>> Scanned
>>>
>>>
>>>
>>> **
>>> This e-mail message is intended only for the designated recipient(s)
>> named
>>> above. The information contained in this e-mail and any attachments may
>> be
>>> confidential or legally privileged. If you are not the intended
>> recipient,
>>> you may not review, retain, copy, redistribute or use this e-mail or any
>>> attachment for any purpose, or disclose all or any part of its contents.
>> If
>>> you have received this e-mail in error, please immediately notify the
>> sender
>>> by reply e-mail and permanently delete this e-mail and any attachments
>> from
>>> your computer system.
>>>
>>
***
Scanned
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
Re: Custom Error Handler servlet
Posted by Justin Edelson <ju...@justinedelson.com>.
You can use OptingServlet with a JSP.
On Jul 29, 2011, at 7:09 AM, sam ” <sk...@gmail.com> wrote:
> If OSGi gets hairy, just store jsp in the repository.
>
> /apps/sling/servlet/errorhandler/Throwable.jsp
>
> look here:
> http://sling.apache.org/site/errorhandling.html
>
>
>
> On Fri, Jul 29, 2011 at 1:34 AM, Eric Norman <er...@gmail.com>wrote:
>
>> I haven't tried this, but it seems like implementing the OptingServlet
>> interface may do what you need.
>>
>> OptingServlet is described briefly @
>> http://sling.apache.org/site/servlets.html
>>
>>
>> Regards,
>> Eric
>>
>> On Thu, Jul 28, 2011 at 9:04 PM, Bethoju, Praveen <BethPr@consumer.org
>>> wrote:
>>
>>> I tried using sling.servlet.resourceTypes instead of the
>> slingservlet.paths
>>> as suggested but I still have my component's (
>> CustomExceptionHandlerServlet
>>> ) status = "unsatisfied". I think this makes my component unavailable as
>> a
>>> replacement to the default error handler.
>>>
>>> The CustomExceptionHandlerServlet servlet is a part of my OSGI bundle.
>> And
>>> the DefaultErrorHandlerServlet provided by Sling is a part of
>>> org.apache.sling.servlets.resolver bundle. Do I need to add
>>> org.apache.sling.servlets.resolver.* to the import-package definition of
>> my
>>> bundle ?
>>>
>>> My Maven bundle plugin configurations for my OSGI bundle (CUUtilities)
>>> looks like this ..
>>>
>>> <plugin>
>>> <groupId>org.apache.felix</groupId>
>>> <artifactId>maven-bundle-plugin</artifactId>
>>> <extensions>true</extensions>
>>> <configuration>
>>> <instructions>
>>>
>>>
>> <Bundle-SymbolicName>org.consumersunion.cq.CUUtilities</Bundle-SymbolicName>
>>>
>>> <Bundle-Activator>org.consumersunion.cq.Activator</Bundle-Activator>
>>> <Export-Package>
>>>
>>>
>> com.day.cu.creator.*,org.consumersunion.*,org.consumerreports.*;version="${project.version}",com.emeta.*,org.cu.*,org.jdom.*,com.opensymphony.oscache.*;version="2.1",com.google.*;version="1.0",org.codehaus.jackson.*,net.sf.ehcache.*
>>> </Export-Package>
>>>
>>> <Import-Package>*;resolution:=optional</Import-Package>
>>> <Bundle-License>n/a</Bundle-License>
>>> <Bundle-Copyright>Copyright (c) Consumers Reports
>>> 2011. All Rights Reserved.</Bundle-Copyright>
>>>
>>> <excludeDependencies>*;scope=provided|runtime</excludeDependencies>
>>> </instructions>
>>> </configuration>
>>> </plugin>
>>>
>>> Thanks for any help.
>>> - Praveen
>>>
>>>
>>> On 7/28/11 8:35 PM, "sam "" <sk...@gmail.com> wrote:
>>>
>>> can you try @scr.property sling.servlet.resourceTypes =
>>> "sling/servlet/errorhandler/default"
>>> ?
>>>
>>>
>>>
>>> On Thu, Jul 28, 2011 at 4:08 PM, Bethoju, Praveen <BethPr@consumer.org
>>>> wrote:
>>>
>>>> Hi -
>>>>
>>>> I'd like to create a custom error handler that will handle exceptions
>>>> thrown
>>>> from scripts (at a specific path... ex: /content/api/*) and I want
>>>> errors/exceptions from all other servlets/scripts to be handled in the
>>>> default way (when no custom error handlers are set) using
>>>> DefaultErrorHandlerServlet.
>>>>
>>>> For this purpose, I created a Servlet and mapped it to
>>>> "/apps/sling/servlet/errorhandler/default"
>>>>
>>>> /**
>>>> *
>>>> * @scr.component metatype="no" immediate="true"
>>>> * @scr.service interface="javax.servlet.Servlet"
>>>> *
>>>> * This is the custom error handler servlet
>>>> *
>>>> * @scr.property name="sling.servlet.paths"
>>>> value="/apps/sling/servlet/errorhandler/default"
>>>> * @scr.property name="sling.servlet.prefix" value="0"
>>>> *
>>>> *
>>>> */
>>>> public class CustomExceptionHandlerServlet extends GenericServlet {
>>>>
>>>> /**
>>>> * @scr.reference policy="static"
>>>> */
>>>> protected DefaultErrorHandlerServlet theDefaultErrorHandlerServlet;
>>>>
>>>>
>>>> @Override
>>>> public void service(ServletRequest request, ServletResponse
>> response)
>>>> throws IOException {
>>>>
>>>> SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)
>>>> request;
>>>> SlingHttpServletResponse slingResponse =
>>> (SlingHttpServletResponse)
>>>> response;
>>>>
>>>> String resourcePath =
>>>> request.getRequestPathInfo().getResourcePath();
>>>> if(resourcePath.contains("/content/api"))
>>>> {
>>>> // perform custom processing.
>>>> }
>>>> else
>>>> {
>>>> // Somehow forward to the default error handler servlet
>>>> // or call the default error handler servlet, may be this
>> way
>>> ?
>>>> theDefaultErrorHandlerServlet.service(request, response);
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>> I have two questions:
>>>>
>>>> 1. In Felix, I see that there's an active component called - "
>>>>
>>>>
>>>
>> org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServ
>>>> let" available. So, I've added a reference to it from my
>>>> CustomExceptionHandlerServlet class. But for some reason, this
>> dependency
>>>> is
>>>> "unsatisfied". Not sure if I am not doing this wiring correctly. Please
>>>> advise.
>>>>
>>>> 2. If I can't wire the DefaultErrorHandlerServlet as in #1 or if its
>> not
>>>> the
>>>> approach to take, is there a way to forward processing of the error to
>>> the
>>>> default error handler servlet?
>>>>
>>>> Thanks
>>>> Praveen
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> **
>>>> This e-mail message is intended only for the designated recipient(s)
>>> named
>>>> above. The information contained in this e-mail and any attachments may
>>> be
>>>> confidential or legally privileged. If you are not the intended
>>> recipient,
>>>> you may not review, retain, copy, redistribute or use this e-mail or
>> any
>>>> attachment for any purpose, or disclose all or any part of its
>> contents.
>>> If
>>>> you have received this e-mail in error, please immediately notify the
>>> sender
>>>> by reply e-mail and permanently delete this e-mail and any attachments
>>> from
>>>> your computer system.
>>>>
>>>
>>>
>>> ***
>>> Scanned
>>>
>>>
>>>
>>> **
>>> This e-mail message is intended only for the designated recipient(s)
>> named
>>> above. The information contained in this e-mail and any attachments may
>> be
>>> confidential or legally privileged. If you are not the intended
>> recipient,
>>> you may not review, retain, copy, redistribute or use this e-mail or any
>>> attachment for any purpose, or disclose all or any part of its contents.
>> If
>>> you have received this e-mail in error, please immediately notify the
>> sender
>>> by reply e-mail and permanently delete this e-mail and any attachments
>> from
>>> your computer system.
>>>
>>
Re: Custom Error Handler servlet
Posted by sam ” <sk...@gmail.com>.
If OSGi gets hairy, just store jsp in the repository.
/apps/sling/servlet/errorhandler/Throwable.jsp
look here:
http://sling.apache.org/site/errorhandling.html
On Fri, Jul 29, 2011 at 1:34 AM, Eric Norman <er...@gmail.com>wrote:
> I haven't tried this, but it seems like implementing the OptingServlet
> interface may do what you need.
>
> OptingServlet is described briefly @
> http://sling.apache.org/site/servlets.html
>
>
> Regards,
> Eric
>
> On Thu, Jul 28, 2011 at 9:04 PM, Bethoju, Praveen <BethPr@consumer.org
> >wrote:
>
> > I tried using sling.servlet.resourceTypes instead of the
> slingservlet.paths
> > as suggested but I still have my component's (
> CustomExceptionHandlerServlet
> > ) status = "unsatisfied". I think this makes my component unavailable as
> a
> > replacement to the default error handler.
> >
> > The CustomExceptionHandlerServlet servlet is a part of my OSGI bundle.
> And
> > the DefaultErrorHandlerServlet provided by Sling is a part of
> > org.apache.sling.servlets.resolver bundle. Do I need to add
> > org.apache.sling.servlets.resolver.* to the import-package definition of
> my
> > bundle ?
> >
> > My Maven bundle plugin configurations for my OSGI bundle (CUUtilities)
> > looks like this ..
> >
> > <plugin>
> > <groupId>org.apache.felix</groupId>
> > <artifactId>maven-bundle-plugin</artifactId>
> > <extensions>true</extensions>
> > <configuration>
> > <instructions>
> >
> >
> <Bundle-SymbolicName>org.consumersunion.cq.CUUtilities</Bundle-SymbolicName>
> >
> > <Bundle-Activator>org.consumersunion.cq.Activator</Bundle-Activator>
> > <Export-Package>
> >
> >
> com.day.cu.creator.*,org.consumersunion.*,org.consumerreports.*;version="${project.version}",com.emeta.*,org.cu.*,org.jdom.*,com.opensymphony.oscache.*;version="2.1",com.google.*;version="1.0",org.codehaus.jackson.*,net.sf.ehcache.*
> > </Export-Package>
> >
> > <Import-Package>*;resolution:=optional</Import-Package>
> > <Bundle-License>n/a</Bundle-License>
> > <Bundle-Copyright>Copyright (c) Consumers Reports
> > 2011. All Rights Reserved.</Bundle-Copyright>
> >
> > <excludeDependencies>*;scope=provided|runtime</excludeDependencies>
> > </instructions>
> > </configuration>
> > </plugin>
> >
> > Thanks for any help.
> > - Praveen
> >
> >
> > On 7/28/11 8:35 PM, "sam "" <sk...@gmail.com> wrote:
> >
> > can you try @scr.property sling.servlet.resourceTypes =
> > "sling/servlet/errorhandler/default"
> > ?
> >
> >
> >
> > On Thu, Jul 28, 2011 at 4:08 PM, Bethoju, Praveen <BethPr@consumer.org
> > >wrote:
> >
> > > Hi -
> > >
> > > I'd like to create a custom error handler that will handle exceptions
> > > thrown
> > > from scripts (at a specific path... ex: /content/api/*) and I want
> > > errors/exceptions from all other servlets/scripts to be handled in the
> > > default way (when no custom error handlers are set) using
> > > DefaultErrorHandlerServlet.
> > >
> > > For this purpose, I created a Servlet and mapped it to
> > > "/apps/sling/servlet/errorhandler/default"
> > >
> > > /**
> > > *
> > > * @scr.component metatype="no" immediate="true"
> > > * @scr.service interface="javax.servlet.Servlet"
> > > *
> > > * This is the custom error handler servlet
> > > *
> > > * @scr.property name="sling.servlet.paths"
> > > value="/apps/sling/servlet/errorhandler/default"
> > > * @scr.property name="sling.servlet.prefix" value="0"
> > > *
> > > *
> > > */
> > > public class CustomExceptionHandlerServlet extends GenericServlet {
> > >
> > > /**
> > > * @scr.reference policy="static"
> > > */
> > > protected DefaultErrorHandlerServlet theDefaultErrorHandlerServlet;
> > >
> > >
> > > @Override
> > > public void service(ServletRequest request, ServletResponse
> response)
> > > throws IOException {
> > >
> > > SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)
> > > request;
> > > SlingHttpServletResponse slingResponse =
> > (SlingHttpServletResponse)
> > > response;
> > >
> > > String resourcePath =
> > > request.getRequestPathInfo().getResourcePath();
> > > if(resourcePath.contains("/content/api"))
> > > {
> > > // perform custom processing.
> > > }
> > > else
> > > {
> > > // Somehow forward to the default error handler servlet
> > > // or call the default error handler servlet, may be this
> way
> > ?
> > > theDefaultErrorHandlerServlet.service(request, response);
> > >
> > > }
> > >
> > > }
> > >
> > > }
> > >
> > >
> > > I have two questions:
> > >
> > > 1. In Felix, I see that there's an active component called - "
> > >
> > >
> >
> org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServ
> > > let" available. So, I've added a reference to it from my
> > > CustomExceptionHandlerServlet class. But for some reason, this
> dependency
> > > is
> > > "unsatisfied". Not sure if I am not doing this wiring correctly. Please
> > > advise.
> > >
> > > 2. If I can't wire the DefaultErrorHandlerServlet as in #1 or if its
> not
> > > the
> > > approach to take, is there a way to forward processing of the error to
> > the
> > > default error handler servlet?
> > >
> > > Thanks
> > > Praveen
> > >
> > >
> > >
> > >
> > >
> > > **
> > > This e-mail message is intended only for the designated recipient(s)
> > named
> > > above. The information contained in this e-mail and any attachments may
> > be
> > > confidential or legally privileged. If you are not the intended
> > recipient,
> > > you may not review, retain, copy, redistribute or use this e-mail or
> any
> > > attachment for any purpose, or disclose all or any part of its
> contents.
> > If
> > > you have received this e-mail in error, please immediately notify the
> > sender
> > > by reply e-mail and permanently delete this e-mail and any attachments
> > from
> > > your computer system.
> > >
> >
> >
> > ***
> > Scanned
> >
> >
> >
> > **
> > This e-mail message is intended only for the designated recipient(s)
> named
> > above. The information contained in this e-mail and any attachments may
> be
> > confidential or legally privileged. If you are not the intended
> recipient,
> > you may not review, retain, copy, redistribute or use this e-mail or any
> > attachment for any purpose, or disclose all or any part of its contents.
> If
> > you have received this e-mail in error, please immediately notify the
> sender
> > by reply e-mail and permanently delete this e-mail and any attachments
> from
> > your computer system.
> >
>
Re: Custom Error Handler servlet
Posted by Eric Norman <er...@gmail.com>.
I haven't tried this, but it seems like implementing the OptingServlet
interface may do what you need.
OptingServlet is described briefly @
http://sling.apache.org/site/servlets.html
Regards,
Eric
On Thu, Jul 28, 2011 at 9:04 PM, Bethoju, Praveen <Be...@consumer.org>wrote:
> I tried using sling.servlet.resourceTypes instead of the slingservlet.paths
> as suggested but I still have my component's ( CustomExceptionHandlerServlet
> ) status = "unsatisfied". I think this makes my component unavailable as a
> replacement to the default error handler.
>
> The CustomExceptionHandlerServlet servlet is a part of my OSGI bundle. And
> the DefaultErrorHandlerServlet provided by Sling is a part of
> org.apache.sling.servlets.resolver bundle. Do I need to add
> org.apache.sling.servlets.resolver.* to the import-package definition of my
> bundle ?
>
> My Maven bundle plugin configurations for my OSGI bundle (CUUtilities)
> looks like this ..
>
> <plugin>
> <groupId>org.apache.felix</groupId>
> <artifactId>maven-bundle-plugin</artifactId>
> <extensions>true</extensions>
> <configuration>
> <instructions>
>
> <Bundle-SymbolicName>org.consumersunion.cq.CUUtilities</Bundle-SymbolicName>
>
> <Bundle-Activator>org.consumersunion.cq.Activator</Bundle-Activator>
> <Export-Package>
>
> com.day.cu.creator.*,org.consumersunion.*,org.consumerreports.*;version="${project.version}",com.emeta.*,org.cu.*,org.jdom.*,com.opensymphony.oscache.*;version="2.1",com.google.*;version="1.0",org.codehaus.jackson.*,net.sf.ehcache.*
> </Export-Package>
>
> <Import-Package>*;resolution:=optional</Import-Package>
> <Bundle-License>n/a</Bundle-License>
> <Bundle-Copyright>Copyright (c) Consumers Reports
> 2011. All Rights Reserved.</Bundle-Copyright>
>
> <excludeDependencies>*;scope=provided|runtime</excludeDependencies>
> </instructions>
> </configuration>
> </plugin>
>
> Thanks for any help.
> - Praveen
>
>
> On 7/28/11 8:35 PM, "sam "" <sk...@gmail.com> wrote:
>
> can you try @scr.property sling.servlet.resourceTypes =
> "sling/servlet/errorhandler/default"
> ?
>
>
>
> On Thu, Jul 28, 2011 at 4:08 PM, Bethoju, Praveen <BethPr@consumer.org
> >wrote:
>
> > Hi -
> >
> > I'd like to create a custom error handler that will handle exceptions
> > thrown
> > from scripts (at a specific path... ex: /content/api/*) and I want
> > errors/exceptions from all other servlets/scripts to be handled in the
> > default way (when no custom error handlers are set) using
> > DefaultErrorHandlerServlet.
> >
> > For this purpose, I created a Servlet and mapped it to
> > "/apps/sling/servlet/errorhandler/default"
> >
> > /**
> > *
> > * @scr.component metatype="no" immediate="true"
> > * @scr.service interface="javax.servlet.Servlet"
> > *
> > * This is the custom error handler servlet
> > *
> > * @scr.property name="sling.servlet.paths"
> > value="/apps/sling/servlet/errorhandler/default"
> > * @scr.property name="sling.servlet.prefix" value="0"
> > *
> > *
> > */
> > public class CustomExceptionHandlerServlet extends GenericServlet {
> >
> > /**
> > * @scr.reference policy="static"
> > */
> > protected DefaultErrorHandlerServlet theDefaultErrorHandlerServlet;
> >
> >
> > @Override
> > public void service(ServletRequest request, ServletResponse response)
> > throws IOException {
> >
> > SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)
> > request;
> > SlingHttpServletResponse slingResponse =
> (SlingHttpServletResponse)
> > response;
> >
> > String resourcePath =
> > request.getRequestPathInfo().getResourcePath();
> > if(resourcePath.contains("/content/api"))
> > {
> > // perform custom processing.
> > }
> > else
> > {
> > // Somehow forward to the default error handler servlet
> > // or call the default error handler servlet, may be this way
> ?
> > theDefaultErrorHandlerServlet.service(request, response);
> >
> > }
> >
> > }
> >
> > }
> >
> >
> > I have two questions:
> >
> > 1. In Felix, I see that there's an active component called - "
> >
> >
> org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServ
> > let" available. So, I've added a reference to it from my
> > CustomExceptionHandlerServlet class. But for some reason, this dependency
> > is
> > "unsatisfied". Not sure if I am not doing this wiring correctly. Please
> > advise.
> >
> > 2. If I can't wire the DefaultErrorHandlerServlet as in #1 or if its not
> > the
> > approach to take, is there a way to forward processing of the error to
> the
> > default error handler servlet?
> >
> > Thanks
> > Praveen
> >
> >
> >
> >
> >
> > **
> > This e-mail message is intended only for the designated recipient(s)
> named
> > above. The information contained in this e-mail and any attachments may
> be
> > confidential or legally privileged. If you are not the intended
> recipient,
> > you may not review, retain, copy, redistribute or use this e-mail or any
> > attachment for any purpose, or disclose all or any part of its contents.
> If
> > you have received this e-mail in error, please immediately notify the
> sender
> > by reply e-mail and permanently delete this e-mail and any attachments
> from
> > your computer system.
> >
>
>
> ***
> Scanned
>
>
>
> **
> This e-mail message is intended only for the designated recipient(s) named
> above. The information contained in this e-mail and any attachments may be
> confidential or legally privileged. If you are not the intended recipient,
> you may not review, retain, copy, redistribute or use this e-mail or any
> attachment for any purpose, or disclose all or any part of its contents. If
> you have received this e-mail in error, please immediately notify the sender
> by reply e-mail and permanently delete this e-mail and any attachments from
> your computer system.
>
Re: Custom Error Handler servlet
Posted by "Bethoju, Praveen" <Be...@consumer.org>.
I tried using sling.servlet.resourceTypes instead of the slingservlet.paths as suggested but I still have my component's ( CustomExceptionHandlerServlet ) status = "unsatisfied". I think this makes my component unavailable as a replacement to the default error handler.
The CustomExceptionHandlerServlet servlet is a part of my OSGI bundle. And the DefaultErrorHandlerServlet provided by Sling is a part of org.apache.sling.servlets.resolver bundle. Do I need to add org.apache.sling.servlets.resolver.* to the import-package definition of my bundle ?
My Maven bundle plugin configurations for my OSGI bundle (CUUtilities) looks like this ..
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>org.consumersunion.cq.CUUtilities</Bundle-SymbolicName>
<Bundle-Activator>org.consumersunion.cq.Activator</Bundle-Activator>
<Export-Package>
com.day.cu.creator.*,org.consumersunion.*,org.consumerreports.*;version="${project.version}",com.emeta.*,org.cu.*,org.jdom.*,com.opensymphony.oscache.*;version="2.1",com.google.*;version="1.0",org.codehaus.jackson.*,net.sf.ehcache.*
</Export-Package>
<Import-Package>*;resolution:=optional</Import-Package>
<Bundle-License>n/a</Bundle-License>
<Bundle-Copyright>Copyright (c) Consumers Reports 2011. All Rights Reserved.</Bundle-Copyright>
<excludeDependencies>*;scope=provided|runtime</excludeDependencies>
</instructions>
</configuration>
</plugin>
Thanks for any help.
- Praveen
On 7/28/11 8:35 PM, "sam "" <sk...@gmail.com> wrote:
can you try @scr.property sling.servlet.resourceTypes =
"sling/servlet/errorhandler/default"
?
On Thu, Jul 28, 2011 at 4:08 PM, Bethoju, Praveen <Be...@consumer.org>wrote:
> Hi -
>
> I'd like to create a custom error handler that will handle exceptions
> thrown
> from scripts (at a specific path... ex: /content/api/*) and I want
> errors/exceptions from all other servlets/scripts to be handled in the
> default way (when no custom error handlers are set) using
> DefaultErrorHandlerServlet.
>
> For this purpose, I created a Servlet and mapped it to
> "/apps/sling/servlet/errorhandler/default"
>
> /**
> *
> * @scr.component metatype="no" immediate="true"
> * @scr.service interface="javax.servlet.Servlet"
> *
> * This is the custom error handler servlet
> *
> * @scr.property name="sling.servlet.paths"
> value="/apps/sling/servlet/errorhandler/default"
> * @scr.property name="sling.servlet.prefix" value="0"
> *
> *
> */
> public class CustomExceptionHandlerServlet extends GenericServlet {
>
> /**
> * @scr.reference policy="static"
> */
> protected DefaultErrorHandlerServlet theDefaultErrorHandlerServlet;
>
>
> @Override
> public void service(ServletRequest request, ServletResponse response)
> throws IOException {
>
> SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)
> request;
> SlingHttpServletResponse slingResponse = (SlingHttpServletResponse)
> response;
>
> String resourcePath =
> request.getRequestPathInfo().getResourcePath();
> if(resourcePath.contains("/content/api"))
> {
> // perform custom processing.
> }
> else
> {
> // Somehow forward to the default error handler servlet
> // or call the default error handler servlet, may be this way ?
> theDefaultErrorHandlerServlet.service(request, response);
>
> }
>
> }
>
> }
>
>
> I have two questions:
>
> 1. In Felix, I see that there's an active component called - "
>
> org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServ
> let" available. So, I've added a reference to it from my
> CustomExceptionHandlerServlet class. But for some reason, this dependency
> is
> "unsatisfied". Not sure if I am not doing this wiring correctly. Please
> advise.
>
> 2. If I can't wire the DefaultErrorHandlerServlet as in #1 or if its not
> the
> approach to take, is there a way to forward processing of the error to the
> default error handler servlet?
>
> Thanks
> Praveen
>
>
>
>
>
> **
> This e-mail message is intended only for the designated recipient(s) named
> above. The information contained in this e-mail and any attachments may be
> confidential or legally privileged. If you are not the intended recipient,
> you may not review, retain, copy, redistribute or use this e-mail or any
> attachment for any purpose, or disclose all or any part of its contents. If
> you have received this e-mail in error, please immediately notify the sender
> by reply e-mail and permanently delete this e-mail and any attachments from
> your computer system.
>
***
Scanned
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
Re: Custom Error Handler servlet
Posted by sam ” <sk...@gmail.com>.
can you try @scr.property sling.servlet.resourceTypes =
"sling/servlet/errorhandler/default"
?
On Thu, Jul 28, 2011 at 4:08 PM, Bethoju, Praveen <Be...@consumer.org>wrote:
> Hi -
>
> I'd like to create a custom error handler that will handle exceptions
> thrown
> from scripts (at a specific path... ex: /content/api/*) and I want
> errors/exceptions from all other servlets/scripts to be handled in the
> default way (when no custom error handlers are set) using
> DefaultErrorHandlerServlet.
>
> For this purpose, I created a Servlet and mapped it to
> "/apps/sling/servlet/errorhandler/default"
>
> /**
> *
> * @scr.component metatype="no" immediate="true"
> * @scr.service interface="javax.servlet.Servlet"
> *
> * This is the custom error handler servlet
> *
> * @scr.property name="sling.servlet.paths"
> value="/apps/sling/servlet/errorhandler/default"
> * @scr.property name="sling.servlet.prefix" value="0"
> *
> *
> */
> public class CustomExceptionHandlerServlet extends GenericServlet {
>
> /**
> * @scr.reference policy="static"
> */
> protected DefaultErrorHandlerServlet theDefaultErrorHandlerServlet;
>
>
> @Override
> public void service(ServletRequest request, ServletResponse response)
> throws IOException {
>
> SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)
> request;
> SlingHttpServletResponse slingResponse = (SlingHttpServletResponse)
> response;
>
> String resourcePath =
> request.getRequestPathInfo().getResourcePath();
> if(resourcePath.contains("/content/api"))
> {
> // perform custom processing.
> }
> else
> {
> // Somehow forward to the default error handler servlet
> // or call the default error handler servlet, may be this way ?
> theDefaultErrorHandlerServlet.service(request, response);
>
> }
>
> }
>
> }
>
>
> I have two questions:
>
> 1. In Felix, I see that there's an active component called - "
>
> org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServ
> let" available. So, I've added a reference to it from my
> CustomExceptionHandlerServlet class. But for some reason, this dependency
> is
> "unsatisfied". Not sure if I am not doing this wiring correctly. Please
> advise.
>
> 2. If I can't wire the DefaultErrorHandlerServlet as in #1 or if its not
> the
> approach to take, is there a way to forward processing of the error to the
> default error handler servlet?
>
> Thanks
> Praveen
>
>
>
>
>
> **
> This e-mail message is intended only for the designated recipient(s) named
> above. The information contained in this e-mail and any attachments may be
> confidential or legally privileged. If you are not the intended recipient,
> you may not review, retain, copy, redistribute or use this e-mail or any
> attachment for any purpose, or disclose all or any part of its contents. If
> you have received this e-mail in error, please immediately notify the sender
> by reply e-mail and permanently delete this e-mail and any attachments from
> your computer system.
>