You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Richard Hierlmeier <rh...@googlemail.com> on 2022/08/08 06:23:31 UTC

PAX-WEB does not register servlet

I upgraded last week a system to Karaf 4.4.1. I have a sporadic problem
with this system.

The system contains a small bundle with this default servlet:

@Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE)
@HttpWhiteboardServletPattern("/")
@HttpWhiteboardContextSelect("(osgi.http.whiteboard.context.path=/)")
public class RootServlet extends HttpServlet {

    @Override
    protected void doGet(final HttpServletRequest req, final
HttpServletResponse resp)
            throws ServletException, IOException {
        resp.sendRedirect("/welcome/welcome.html");
    }
}

However sometimes after the start of Karaf the bundle is active but this
servlet is not available:

de@root()> la -u | grep  web-root
 37 | Active   |  80 | 1.0.0.SNAPSHOT                      |
mvn:de.hierlmeier.testPaxWeb8/web-root/1.0.0-SNAPSHOT

de@root()> ls javax.servlet.Servlet
[javax.servlet.Servlet]
-----------------------
 component.id = 20
 component.name = de.hierlmeier.testPaxWeb8.webRoot.RootServlet
 osgi.ds.satisfying.condition.target = (osgi.condition.id=true)
 osgi.http.whiteboard.context.select = (osgi.http.whiteboard.context.path=/)
 osgi.http.whiteboard.servlet.pattern = [/]
 service.bundleid = 37
 service.id = 206
 service.scope = prototype
Provided by :
  web-root  (37)
Used by:
  web-root  (37)

de@root()> web:servlet-list | grep RootServlet
de@root()>

How can I diagnose this problem?

I am running Karaf 4.4.1 with PAX-WEB 8.0.6 on Java 8.

Regards

  Richard

Re: PAX-WEB does not register servlet

Posted by Grzegorz Grzybek <gr...@gmail.com>.
Hello

When installing (for example in Whiteboard) two servlets with the same
name, you should see something like this:

2022-08-22T08:43:10,664 | WARN  | paxweb-config-1-thread-1 | ServerModel
                   | 83 - org.ops4j.pax.web.pax-web-spi - 8.0.6 | *Skipped
registration* of
ServletModel{id=ServletModel-6,name='s1',urlPatterns=[/s2],contexts=[{WB,OCM-1,default,/}]}
because of existing servlets with name s1. *Servlet will be added as
"awaiting registration"*.

Then, after first servlet is uninstalled, the awaiting one should be
registered. This is 100% compliant to Whiteboard specification. Also what
the specification assumes is that if you don't specify the name of the
servlets, its FQCN should be used instead...

regards
Grzegorz Grzybek

pon., 22 sie 2022 o 08:32 Richard Hierlmeier <rh...@googlemail.com>
napisał(a):

> Hi Thomas and Grzegorz,
>
> I cannot say whether this problem still exists, because I rolled back the
> affected installation to Karaf 4.3.
> I hope I can find this week some time to reproduce the problem (and to
> test your proposed fix).
>
> Does PAX-WEB 8 produce a warning in the logs when such a situation is
> detected (two or or more servlets with the same name in the same context)?
>
> Is it possible that PAX-WEB generates an unique name for servlets without
> a servlet name?
>
> Sorry for the delayed answer, I was also on holiday.
>
> Thank you
>
>   Richard
>
>
> Am Do., 18. Aug. 2022 um 11:34 Uhr schrieb Thomas Driessen <
> thomas.driessen.td@gmail.com>:
>
>> Hi Richard,
>>
>> not sure if this issue is still open for you, but what I observed in a
>> similar case is, that if there are two servlets with the same name in the
>> same context, this leads to one of them not being registered.
>> As the default name for your servlet would be javax.servlet.Servlet this
>> might cause your observed behavior.
>>
>> In my case I solved this, by explicitly naming all my Servlets
>> via @HttpWhiteboardServletName("my-unique-name")
>>
>> Hope that helps.
>>
>> Kind regards,
>> Thomas
>>
>> Am Di., 16. Aug. 2022 um 12:50 Uhr schrieb Grzegorz Grzybek <
>> gr.grzybek@gmail.com>:
>>
>>> Hello
>>>
>>> If you set DEBUG logging level for org.ops4j.pax.web logger, you should
>>> see A LOT of information about how servlets are discovered and registered
>>> into the runtime. Without the logs, I can't tell much - especially if (as
>>> you've mentioned) it's sporadic problem...
>>>
>>> regards
>>> Grzegorz Grzybek
>>>
>>> pon., 8 sie 2022 o 08:23 Richard Hierlmeier <rh...@googlemail.com>
>>> napisał(a):
>>>
>>>>
>>>> I upgraded last week a system to Karaf 4.4.1. I have a sporadic problem
>>>> with this system.
>>>>
>>>> The system contains a small bundle with this default servlet:
>>>>
>>>> @Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE)
>>>> @HttpWhiteboardServletPattern("/")
>>>> @HttpWhiteboardContextSelect("(osgi.http.whiteboard.context.path=/)")
>>>> public class RootServlet extends HttpServlet {
>>>>
>>>>     @Override
>>>>     protected void doGet(final HttpServletRequest req, final
>>>> HttpServletResponse resp)
>>>>             throws ServletException, IOException {
>>>>         resp.sendRedirect("/welcome/welcome.html");
>>>>     }
>>>> }
>>>>
>>>> However sometimes after the start of Karaf the bundle is active but
>>>> this servlet is not available:
>>>>
>>>> de@root()> la -u | grep  web-root
>>>>  37 | Active   |  80 | 1.0.0.SNAPSHOT                      |
>>>> mvn:de.hierlmeier.testPaxWeb8/web-root/1.0.0-SNAPSHOT
>>>>
>>>> de@root()> ls javax.servlet.Servlet
>>>> [javax.servlet.Servlet]
>>>> -----------------------
>>>>  component.id = 20
>>>>  component.name = de.hierlmeier.testPaxWeb8.webRoot.RootServlet
>>>>  osgi.ds.satisfying.condition.target = (osgi.condition.id=true)
>>>>  osgi.http.whiteboard.context.select =
>>>> (osgi.http.whiteboard.context.path=/)
>>>>  osgi.http.whiteboard.servlet.pattern = [/]
>>>>  service.bundleid = 37
>>>>  service.id = 206
>>>>  service.scope = prototype
>>>> Provided by :
>>>>   web-root  (37)
>>>> Used by:
>>>>   web-root  (37)
>>>>
>>>> de@root()> web:servlet-list | grep RootServlet
>>>> de@root()>
>>>>
>>>> How can I diagnose this problem?
>>>>
>>>> I am running Karaf 4.4.1 with PAX-WEB 8.0.6 on Java 8.
>>>>
>>>> Regards
>>>>
>>>>   Richard
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>

Re: PAX-WEB does not register servlet

Posted by Richard Hierlmeier <rh...@googlemail.com>.
Hi Thomas and Grzegorz,

I cannot say whether this problem still exists, because I rolled back the
affected installation to Karaf 4.3.
I hope I can find this week some time to reproduce the problem (and to test
your proposed fix).

Does PAX-WEB 8 produce a warning in the logs when such a situation is
detected (two or or more servlets with the same name in the same context)?

Is it possible that PAX-WEB generates an unique name for servlets without a
servlet name?

Sorry for the delayed answer, I was also on holiday.

Thank you

  Richard


Am Do., 18. Aug. 2022 um 11:34 Uhr schrieb Thomas Driessen <
thomas.driessen.td@gmail.com>:

> Hi Richard,
>
> not sure if this issue is still open for you, but what I observed in a
> similar case is, that if there are two servlets with the same name in the
> same context, this leads to one of them not being registered.
> As the default name for your servlet would be javax.servlet.Servlet this
> might cause your observed behavior.
>
> In my case I solved this, by explicitly naming all my Servlets
> via @HttpWhiteboardServletName("my-unique-name")
>
> Hope that helps.
>
> Kind regards,
> Thomas
>
> Am Di., 16. Aug. 2022 um 12:50 Uhr schrieb Grzegorz Grzybek <
> gr.grzybek@gmail.com>:
>
>> Hello
>>
>> If you set DEBUG logging level for org.ops4j.pax.web logger, you should
>> see A LOT of information about how servlets are discovered and registered
>> into the runtime. Without the logs, I can't tell much - especially if (as
>> you've mentioned) it's sporadic problem...
>>
>> regards
>> Grzegorz Grzybek
>>
>> pon., 8 sie 2022 o 08:23 Richard Hierlmeier <rh...@googlemail.com>
>> napisał(a):
>>
>>>
>>> I upgraded last week a system to Karaf 4.4.1. I have a sporadic problem
>>> with this system.
>>>
>>> The system contains a small bundle with this default servlet:
>>>
>>> @Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE)
>>> @HttpWhiteboardServletPattern("/")
>>> @HttpWhiteboardContextSelect("(osgi.http.whiteboard.context.path=/)")
>>> public class RootServlet extends HttpServlet {
>>>
>>>     @Override
>>>     protected void doGet(final HttpServletRequest req, final
>>> HttpServletResponse resp)
>>>             throws ServletException, IOException {
>>>         resp.sendRedirect("/welcome/welcome.html");
>>>     }
>>> }
>>>
>>> However sometimes after the start of Karaf the bundle is active but this
>>> servlet is not available:
>>>
>>> de@root()> la -u | grep  web-root
>>>  37 | Active   |  80 | 1.0.0.SNAPSHOT                      |
>>> mvn:de.hierlmeier.testPaxWeb8/web-root/1.0.0-SNAPSHOT
>>>
>>> de@root()> ls javax.servlet.Servlet
>>> [javax.servlet.Servlet]
>>> -----------------------
>>>  component.id = 20
>>>  component.name = de.hierlmeier.testPaxWeb8.webRoot.RootServlet
>>>  osgi.ds.satisfying.condition.target = (osgi.condition.id=true)
>>>  osgi.http.whiteboard.context.select =
>>> (osgi.http.whiteboard.context.path=/)
>>>  osgi.http.whiteboard.servlet.pattern = [/]
>>>  service.bundleid = 37
>>>  service.id = 206
>>>  service.scope = prototype
>>> Provided by :
>>>   web-root  (37)
>>> Used by:
>>>   web-root  (37)
>>>
>>> de@root()> web:servlet-list | grep RootServlet
>>> de@root()>
>>>
>>> How can I diagnose this problem?
>>>
>>> I am running Karaf 4.4.1 with PAX-WEB 8.0.6 on Java 8.
>>>
>>> Regards
>>>
>>>   Richard
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>

Re: PAX-WEB does not register servlet

Posted by Thomas Driessen <th...@gmail.com>.
Hi Richard,

not sure if this issue is still open for you, but what I observed in a
similar case is, that if there are two servlets with the same name in the
same context, this leads to one of them not being registered.
As the default name for your servlet would be javax.servlet.Servlet this
might cause your observed behavior.

In my case I solved this, by explicitly naming all my Servlets
via @HttpWhiteboardServletName("my-unique-name")

Hope that helps.

Kind regards,
Thomas

Am Di., 16. Aug. 2022 um 12:50 Uhr schrieb Grzegorz Grzybek <
gr.grzybek@gmail.com>:

> Hello
>
> If you set DEBUG logging level for org.ops4j.pax.web logger, you should
> see A LOT of information about how servlets are discovered and registered
> into the runtime. Without the logs, I can't tell much - especially if (as
> you've mentioned) it's sporadic problem...
>
> regards
> Grzegorz Grzybek
>
> pon., 8 sie 2022 o 08:23 Richard Hierlmeier <rh...@googlemail.com>
> napisał(a):
>
>>
>> I upgraded last week a system to Karaf 4.4.1. I have a sporadic problem
>> with this system.
>>
>> The system contains a small bundle with this default servlet:
>>
>> @Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE)
>> @HttpWhiteboardServletPattern("/")
>> @HttpWhiteboardContextSelect("(osgi.http.whiteboard.context.path=/)")
>> public class RootServlet extends HttpServlet {
>>
>>     @Override
>>     protected void doGet(final HttpServletRequest req, final
>> HttpServletResponse resp)
>>             throws ServletException, IOException {
>>         resp.sendRedirect("/welcome/welcome.html");
>>     }
>> }
>>
>> However sometimes after the start of Karaf the bundle is active but this
>> servlet is not available:
>>
>> de@root()> la -u | grep  web-root
>>  37 | Active   |  80 | 1.0.0.SNAPSHOT                      |
>> mvn:de.hierlmeier.testPaxWeb8/web-root/1.0.0-SNAPSHOT
>>
>> de@root()> ls javax.servlet.Servlet
>> [javax.servlet.Servlet]
>> -----------------------
>>  component.id = 20
>>  component.name = de.hierlmeier.testPaxWeb8.webRoot.RootServlet
>>  osgi.ds.satisfying.condition.target = (osgi.condition.id=true)
>>  osgi.http.whiteboard.context.select =
>> (osgi.http.whiteboard.context.path=/)
>>  osgi.http.whiteboard.servlet.pattern = [/]
>>  service.bundleid = 37
>>  service.id = 206
>>  service.scope = prototype
>> Provided by :
>>   web-root  (37)
>> Used by:
>>   web-root  (37)
>>
>> de@root()> web:servlet-list | grep RootServlet
>> de@root()>
>>
>> How can I diagnose this problem?
>>
>> I am running Karaf 4.4.1 with PAX-WEB 8.0.6 on Java 8.
>>
>> Regards
>>
>>   Richard
>>
>>
>>
>>
>>
>>
>>
>>
>>

Re: PAX-WEB does not register servlet

Posted by Grzegorz Grzybek <gr...@gmail.com>.
Hello

If you set DEBUG logging level for org.ops4j.pax.web logger, you should see
A LOT of information about how servlets are discovered and registered into
the runtime. Without the logs, I can't tell much - especially if (as you've
mentioned) it's sporadic problem...

regards
Grzegorz Grzybek

pon., 8 sie 2022 o 08:23 Richard Hierlmeier <rh...@googlemail.com>
napisał(a):

>
> I upgraded last week a system to Karaf 4.4.1. I have a sporadic problem
> with this system.
>
> The system contains a small bundle with this default servlet:
>
> @Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE)
> @HttpWhiteboardServletPattern("/")
> @HttpWhiteboardContextSelect("(osgi.http.whiteboard.context.path=/)")
> public class RootServlet extends HttpServlet {
>
>     @Override
>     protected void doGet(final HttpServletRequest req, final
> HttpServletResponse resp)
>             throws ServletException, IOException {
>         resp.sendRedirect("/welcome/welcome.html");
>     }
> }
>
> However sometimes after the start of Karaf the bundle is active but this
> servlet is not available:
>
> de@root()> la -u | grep  web-root
>  37 | Active   |  80 | 1.0.0.SNAPSHOT                      |
> mvn:de.hierlmeier.testPaxWeb8/web-root/1.0.0-SNAPSHOT
>
> de@root()> ls javax.servlet.Servlet
> [javax.servlet.Servlet]
> -----------------------
>  component.id = 20
>  component.name = de.hierlmeier.testPaxWeb8.webRoot.RootServlet
>  osgi.ds.satisfying.condition.target = (osgi.condition.id=true)
>  osgi.http.whiteboard.context.select =
> (osgi.http.whiteboard.context.path=/)
>  osgi.http.whiteboard.servlet.pattern = [/]
>  service.bundleid = 37
>  service.id = 206
>  service.scope = prototype
> Provided by :
>   web-root  (37)
> Used by:
>   web-root  (37)
>
> de@root()> web:servlet-list | grep RootServlet
> de@root()>
>
> How can I diagnose this problem?
>
> I am running Karaf 4.4.1 with PAX-WEB 8.0.6 on Java 8.
>
> Regards
>
>   Richard
>
>
>
>
>
>
>
>
>