alias: '/errorServlet' is already in use in this or another context when register more than one errorPage servlet

17 views
Skip to first unread message

Nhut Thai Le

unread,
Aug 6, 2019, 1:28:13 PM8/6/19
to OPS4J
Hello,

I have a few error page servlets to handle 403, 404 and 500 errors. They are annotated according to osgi cmpn R6  as  follow:
@Component(
service = Servlet.class,
enabled=true,
property = {
"osgi.http.whiteboard.servlet.errorPage=403",
"osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=WebviewerServletContextHelper)"
},
scope = ServiceScope.PROTOTYPE
)
public final class Error403Servlet extends HttpServlet {...}

@Component(
service = Servlet.class,
enabled=true,
property = {
"osgi.http.whiteboard.servlet.errorPage=404",
"osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=WebviewerServletContextHelper)"
},
scope = ServiceScope.PROTOTYPE
)
public final class Error404Servlet extends HttpServlet {..}

@Component(
service = Servlet.class,
enabled=true,
property = {
"osgi.http.whiteboard.servlet.errorPage=500",
"osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=WebviewerServletContextHelper)"
},
scope = ServiceScope.PROTOTYPE
)
public final class Error500Servlet extends HttpServlet {..}

When i start the server, i got this error:
13:13:53.716 [paxweb-config-1-thread-1] ERROR o.o.p.w.e.w.i.WebApplication - Registration skipped for [ServletWebElement{mapping=DefaultServletMapping{httpContextId=WebviewerServletContextHelper,urlPatterns=null,initParams={},servlet=com.castortech.iris.ba.webviewer.internal.Error500Servlet@1399c32a, alias=/errorServlet, servletNameError500Servlet}}] due to error during registration
org.osgi.service.http.NamespaceException: alias: '/errorServlet' is already in use in this or another context
at org.ops4j.pax.web.service.spi.model.ServerModel.addServletModel(ServerModel.java:124)
at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerServlet(HttpServiceStarted.java:243)
at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerServlet(HttpServiceStarted.java:223)
at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerServlet(HttpServiceStarted.java:207)
at org.ops4j.pax.web.service.internal.HttpServiceProxy.registerServlet(HttpServiceProxy.java:69)
at org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement.register(ServletWebElement.java:88)
Tracing the code to the ServletWebElement.register(), i see that all my error page servlets above have the same alias (/errorServlet) which cause pax.web to throw exception and skip registration when it encounter the 2nd error page servlet. Is this a known bug and how do I get around this?
I am using pax-web-extender-whiteboard 7.2.4

Thai Le

Grzegorz Grzybek

unread,
Sep 10, 2019, 3:00:43 AM9/10/19
to op...@googlegroups.com
Hello

The error is correct - you didn't specify the patterns for error servlets, thus "/errorServlet" was assumed.

You have two options:

1. add @javax.servlet.annotation.WebServlet annotation and use "value" or "urlPatterns" params of this annotation - these will be used instead of "/errorServlet"
2. use "alias" or "urlPatterns" service properties on @Component annotation

I hope this helps.
regards
Grzegorz Grzybek

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/b5bf8863-4c95-4471-a46d-5ed004c2491f%40googlegroups.com.

Nhut Thai Le

unread,
Sep 10, 2019, 10:25:49 AM9/10/19
to OPS4J
Thank you Grzegorz,

I did what you said and the error does go away but from time to time i got this:

java.lang.IllegalArgumentException: Error page for [403] already registered.
	at org.ops4j.pax.web.service.spi.model.ServiceModel.addErrorPageModel(ServiceModel.java:315)
	at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerErrorPage(HttpServiceStarted.java:961)
	at org.ops4j.pax.web.service.internal.HttpServiceProxy.registerErrorPage(HttpServiceProxy.java:343)
	at org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement.register(ServletWebElement.java:107)
	at org.ops4j.pax.web.extender.whiteboard.internal.WebApplication.registerWebElement(WebApplication.java:392)

Is it possible that this is due to race condition in scr?

Thai

Grzegorz Grzybek

unread,
Sep 10, 2019, 10:27:31 AM9/10/19
to op...@googlegroups.com
Hello

So back to the case you've described in your email "error page servlet register twice" ;)

Is there a chance to get some logs?

regards
Grzegorz Grzybek

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.

Nhut Thai Le

unread,
Sep 10, 2019, 10:29:20 AM9/10/19
to OPS4J
Yes, I'll update the other question with logs

Thai

On Tuesday, August 6, 2019 at 1:28:13 PM UTC-4, Nhut Thai Le wrote:
Reply all
Reply to author
Forward
0 new messages