Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Miroslav Beranič
Hi,

I am not sure any more ... what it should be used for :) At first I
understood it as a URL, but now, when I was looking at the PAX Web code ...
not quite sure what it is used for.

But either way, as you said, all these different names make in quite
un-clear what they are used for.

Thank you for the support and clearing the fog.

Kind Regards,
Miroslav



V V čet., 6. feb. 2020 ob 13:50 je oseba Grzegorz Grzybek <
gr.grzy...@gmail.com> napisala:

> In Pax Web 8 I'll try to make it clear "what is alias"?
>
> I think it comes from (correct me if I'm wrong) ...
> https://httpd.apache.org/docs/2.4/mod/mod_alias.html#alias meaning a
> "place in URI namespace accessible via HTTP". Http Service spec (chapter
> 102 of OSGi CMPN) confuses "name", "alias" and "URI pattern" heavily...
>
> When I was fixing some bugs in Pax Web some time ago, I found that alias
> SHOULD BE just specialized, single-element array of URI patterns. It helped
> with the tests and general comprehension, but I didn't notice this
> aliasAsUrlPattern() method...
>
> regards
> Grzegorz
>
> czw., 6 lut 2020 o 13:44 Miroslav Beranič 
> napisał(a):
>
>> Hi Grzegorz,
>>
>> so yes, this was it.
>>
>> It can be used:
>>
>> props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, new
>> String[]{"/sl/zdravo", "/en/hello", "/de/halo"});
>>
>> or
>>
>> props.put(ExtenderConstants.PROPERTY_ALIAS, "/sl/zdravo");
>>
>> but can not use both. But, now Alias is missing in the Karaf http:list
>> and some other internal logic, dependant on the alias is also not working,
>> but ... I guess I can work around it.
>>
>> OK, this kind of solved the problem for now. But why it is not allowed to
>> have both? I guess you would want to have alias and n other url patterns
>> for the Servlet, or not?
>>
>>
>> Kind regards,
>> Miroslav
>>
>>
>>
>> V V čet., 6. feb. 2020 ob 13:38 je oseba Miroslav Beranič <
>> miroslav.bera...@mibesis.si> napisala:
>>
>>> Hi Grzegorz,
>>>
>>> I've followed the example provided at GitHub:
>>>
>>>
>>> https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/whiteboard/src/main/java/org/ops4j/pax/web/extender/samples/whiteboard/internal/Activator.java
>>>
>>> Thank you for the notice.
>>>
>>> Kind regards,
>>> Miroslav
>>>
>>>
>>> V V čet., 6. feb. 2020 ob 13:27 je oseba Grzegorz Grzybek <
>>> gr.grzy...@gmail.com> napisala:
>>>
 Hello

 I've checked
 org.ops4j.pax.web.extender.whiteboard.internal.tracker.ServletTracker#createWebElement()
 and indeed - it takes "alias" from "alias" property and may take patterns
 from "urlPatterns" or "osgi.http.whiteboard.servlet.pattern" - but you
 CAN'T specify "alias" property to do it.

 Please don't use:

 props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");

 regards
 Grzegorz

 czw., 6 lut 2020 o 13:07 Miroslav Beranič 
 napisał(a):

> Hi JB,
>
> Took the code from:
>
> https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/whiteboard
>
> to be able to use ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID =>
> Virtual hosts "feature" of Jetty.
>
> {
> Dictionary props;
> props = new Hashtable<>();
>
> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
> props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID,
> "virtualhost");
>
> // Fail with Exception: from inside constructor of class
> org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement
> // props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello");
>
> props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP +
> "exactUrlPattern", Boolean.TRUE);
>
> servletReg = bundleContext.registerService(Servlet.class, new
> WhiteboardServlet("/hello"), props);
> }
>
> Kind Regards,
> Miroslav
>
>
> Dne četrtek, 06. februar 2020 12.50.17 UTC+1 je oseba Jean-Baptiste
> Onofré napisala:
>>
>> Hi
>>
>> Can you please share how you register the servlet ? Via the
>> httpService.register, Servlet service registration or whiteboard ?
>>
>> Thanks,
>> Regards
>> JB
>>
>> On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič <
>> mirosla...@mibesis.si> wrote:
>>
>>> Hi all,
>>>
>>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet
>>> with exact url, but I see url pattern is auto-generated from alias.
>>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>>>
>>> org.ops4j.pax.web.service.spi.model.ServletModel
>>>
>>>
>>> constructor:
>>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
>>> javax.servlet.Servlet, java.lang.String, java.lang.String[],
>>> java.lang.String, java.util.Dictionary,
>>> java.lang.Integer, java.lang.Boolean, 
>>> javax.servlet.MultipartConfigElement)
>>>
>>>
>>> it calles method ( private static )
>>> new 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Grzegorz Grzybek
In Pax Web 8 I'll try to make it clear "what is alias"?

I think it comes from (correct me if I'm wrong) ...
https://httpd.apache.org/docs/2.4/mod/mod_alias.html#alias meaning a "place
in URI namespace accessible via HTTP". Http Service spec (chapter 102 of
OSGi CMPN) confuses "name", "alias" and "URI pattern" heavily...

When I was fixing some bugs in Pax Web some time ago, I found that alias
SHOULD BE just specialized, single-element array of URI patterns. It helped
with the tests and general comprehension, but I didn't notice this
aliasAsUrlPattern() method...

regards
Grzegorz

czw., 6 lut 2020 o 13:44 Miroslav Beranič 
napisał(a):

> Hi Grzegorz,
>
> so yes, this was it.
>
> It can be used:
>
> props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, new
> String[]{"/sl/zdravo", "/en/hello", "/de/halo"});
>
> or
>
> props.put(ExtenderConstants.PROPERTY_ALIAS, "/sl/zdravo");
>
> but can not use both. But, now Alias is missing in the Karaf http:list and
> some other internal logic, dependant on the alias is also not working, but
> ... I guess I can work around it.
>
> OK, this kind of solved the problem for now. But why it is not allowed to
> have both? I guess you would want to have alias and n other url patterns
> for the Servlet, or not?
>
>
> Kind regards,
> Miroslav
>
>
>
> V V čet., 6. feb. 2020 ob 13:38 je oseba Miroslav Beranič <
> miroslav.bera...@mibesis.si> napisala:
>
>> Hi Grzegorz,
>>
>> I've followed the example provided at GitHub:
>>
>>
>> https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/whiteboard/src/main/java/org/ops4j/pax/web/extender/samples/whiteboard/internal/Activator.java
>>
>> Thank you for the notice.
>>
>> Kind regards,
>> Miroslav
>>
>>
>> V V čet., 6. feb. 2020 ob 13:27 je oseba Grzegorz Grzybek <
>> gr.grzy...@gmail.com> napisala:
>>
>>> Hello
>>>
>>> I've checked
>>> org.ops4j.pax.web.extender.whiteboard.internal.tracker.ServletTracker#createWebElement()
>>> and indeed - it takes "alias" from "alias" property and may take patterns
>>> from "urlPatterns" or "osgi.http.whiteboard.servlet.pattern" - but you
>>> CAN'T specify "alias" property to do it.
>>>
>>> Please don't use:
>>>
>>> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
>>>
>>> regards
>>> Grzegorz
>>>
>>> czw., 6 lut 2020 o 13:07 Miroslav Beranič 
>>> napisał(a):
>>>
 Hi JB,

 Took the code from:

 https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/whiteboard

 to be able to use ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID => Virtual
 hosts "feature" of Jetty.

 {
 Dictionary props;
 props = new Hashtable<>();

 props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
 props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID,
 "virtualhost");

 // Fail with Exception: from inside constructor of class
 org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement
 // props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello");

 props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP +
 "exactUrlPattern", Boolean.TRUE);

 servletReg = bundleContext.registerService(Servlet.class, new
 WhiteboardServlet("/hello"), props);
 }

 Kind Regards,
 Miroslav


 Dne četrtek, 06. februar 2020 12.50.17 UTC+1 je oseba Jean-Baptiste
 Onofré napisala:
>
> Hi
>
> Can you please share how you register the servlet ? Via the
> httpService.register, Servlet service registration or whiteboard ?
>
> Thanks,
> Regards
> JB
>
> On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič <
> mirosla...@mibesis.si> wrote:
>
>> Hi all,
>>
>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet
>> with exact url, but I see url pattern is auto-generated from alias.
>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>>
>> org.ops4j.pax.web.service.spi.model.ServletModel
>>
>>
>> constructor:
>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
>> javax.servlet.Servlet, java.lang.String, java.lang.String[],
>> java.lang.String, java.util.Dictionary,
>> java.lang.Integer, java.lang.Boolean, 
>> javax.servlet.MultipartConfigElement)
>>
>>
>> it calles method ( private static )
>> new String[]{aliasAsUrlPattern(alias)}
>>
>>
>> private static String aliasAsUrlPattern(final String alias) {
>> String urlPattern = alias;
>> if (urlPattern != null && !urlPattern.equals("/")
>> && !urlPattern.contains("*")) {
>> if (urlPattern.endsWith("/")) {
>> urlPattern = urlPattern + "*";
>> } else {
>> urlPattern = urlPattern + "/*";
>> }
>> }
>> return urlPattern;
>> }
>>
>>
>> so it always creates a url pattern, as 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Miroslav Beranič
Hi Grzegorz,

so yes, this was it.

It can be used:

props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, new
String[]{"/sl/zdravo", "/en/hello", "/de/halo"});

or

props.put(ExtenderConstants.PROPERTY_ALIAS, "/sl/zdravo");

but can not use both. But, now Alias is missing in the Karaf http:list and
some other internal logic, dependant on the alias is also not working, but
... I guess I can work around it.

OK, this kind of solved the problem for now. But why it is not allowed to
have both? I guess you would want to have alias and n other url patterns
for the Servlet, or not?


Kind regards,
Miroslav



V V čet., 6. feb. 2020 ob 13:38 je oseba Miroslav Beranič <
miroslav.bera...@mibesis.si> napisala:

> Hi Grzegorz,
>
> I've followed the example provided at GitHub:
>
>
> https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/whiteboard/src/main/java/org/ops4j/pax/web/extender/samples/whiteboard/internal/Activator.java
>
> Thank you for the notice.
>
> Kind regards,
> Miroslav
>
>
> V V čet., 6. feb. 2020 ob 13:27 je oseba Grzegorz Grzybek <
> gr.grzy...@gmail.com> napisala:
>
>> Hello
>>
>> I've checked
>> org.ops4j.pax.web.extender.whiteboard.internal.tracker.ServletTracker#createWebElement()
>> and indeed - it takes "alias" from "alias" property and may take patterns
>> from "urlPatterns" or "osgi.http.whiteboard.servlet.pattern" - but you
>> CAN'T specify "alias" property to do it.
>>
>> Please don't use:
>>
>> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
>>
>> regards
>> Grzegorz
>>
>> czw., 6 lut 2020 o 13:07 Miroslav Beranič 
>> napisał(a):
>>
>>> Hi JB,
>>>
>>> Took the code from:
>>> https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/whiteboard
>>>
>>> to be able to use ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID => Virtual
>>> hosts "feature" of Jetty.
>>>
>>> {
>>> Dictionary props;
>>> props = new Hashtable<>();
>>>
>>> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
>>> props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "virtualhost");
>>>
>>> // Fail with Exception: from inside constructor of class
>>> org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement
>>> // props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello");
>>>
>>> props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP +
>>> "exactUrlPattern", Boolean.TRUE);
>>>
>>> servletReg = bundleContext.registerService(Servlet.class, new
>>> WhiteboardServlet("/hello"), props);
>>> }
>>>
>>> Kind Regards,
>>> Miroslav
>>>
>>>
>>> Dne četrtek, 06. februar 2020 12.50.17 UTC+1 je oseba Jean-Baptiste
>>> Onofré napisala:

 Hi

 Can you please share how you register the servlet ? Via the
 httpService.register, Servlet service registration or whiteboard ?

 Thanks,
 Regards
 JB

 On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič 
 wrote:

> Hi all,
>
> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet
> with exact url, but I see url pattern is auto-generated from alias.
> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>
> org.ops4j.pax.web.service.spi.model.ServletModel
>
>
> constructor:
> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
> javax.servlet.Servlet, java.lang.String, java.lang.String[],
> java.lang.String, java.util.Dictionary,
> java.lang.Integer, java.lang.Boolean, 
> javax.servlet.MultipartConfigElement)
>
>
> it calles method ( private static )
> new String[]{aliasAsUrlPattern(alias)}
>
>
> private static String aliasAsUrlPattern(final String alias) {
> String urlPattern = alias;
> if (urlPattern != null && !urlPattern.equals("/")
> && !urlPattern.contains("*")) {
> if (urlPattern.endsWith("/")) {
> urlPattern = urlPattern + "*";
> } else {
> urlPattern = urlPattern + "/*";
> }
> }
> return urlPattern;
> }
>
>
> so it always creates a url pattern, as I guess the name suggest, but
> why? I would like to register exact URL, not the pattern. As it looks now,
> this is not possible to do - as there is no argument to pass in to control
> the flow.
>
> As it looks from the git history/log this is quite "old" code - from
> 2008 - 2013, so I guess this is not new and I guess everybody are ok with
> this? So in this case, what is the usecase for it? As for my usecase - 
> this
> is not the required behavior.
>
> For example, Servlet, registered with /hello, also matches /hello/1,
> but I want /hello/1 to return HTTP 404.
>
>
> So for now, only really question is - is this expected behavior or is
> there a room to change this? If so, how can one, with existing solution,
> register Servlet with exact URL?
>
> 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Miroslav Beranič
Hi Grzegorz,

I've followed the example provided at GitHub:

https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/whiteboard/src/main/java/org/ops4j/pax/web/extender/samples/whiteboard/internal/Activator.java

Thank you for the notice.

Kind regards,
Miroslav


V V čet., 6. feb. 2020 ob 13:27 je oseba Grzegorz Grzybek <
gr.grzy...@gmail.com> napisala:

> Hello
>
> I've checked
> org.ops4j.pax.web.extender.whiteboard.internal.tracker.ServletTracker#createWebElement()
> and indeed - it takes "alias" from "alias" property and may take patterns
> from "urlPatterns" or "osgi.http.whiteboard.servlet.pattern" - but you
> CAN'T specify "alias" property to do it.
>
> Please don't use:
>
> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
>
> regards
> Grzegorz
>
> czw., 6 lut 2020 o 13:07 Miroslav Beranič 
> napisał(a):
>
>> Hi JB,
>>
>> Took the code from:
>> https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/whiteboard
>>
>> to be able to use ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID => Virtual
>> hosts "feature" of Jetty.
>>
>> {
>> Dictionary props;
>> props = new Hashtable<>();
>>
>> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
>> props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "virtualhost");
>>
>> // Fail with Exception: from inside constructor of class
>> org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement
>> // props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello");
>>
>> props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP +
>> "exactUrlPattern", Boolean.TRUE);
>>
>> servletReg = bundleContext.registerService(Servlet.class, new
>> WhiteboardServlet("/hello"), props);
>> }
>>
>> Kind Regards,
>> Miroslav
>>
>>
>> Dne četrtek, 06. februar 2020 12.50.17 UTC+1 je oseba Jean-Baptiste
>> Onofré napisala:
>>>
>>> Hi
>>>
>>> Can you please share how you register the servlet ? Via the
>>> httpService.register, Servlet service registration or whiteboard ?
>>>
>>> Thanks,
>>> Regards
>>> JB
>>>
>>> On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič 
>>> wrote:
>>>
 Hi all,

 I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet
 with exact url, but I see url pattern is auto-generated from alias.
 I look at the current master branch - version 8.0.0-SNAPSHOT. Class:

 org.ops4j.pax.web.service.spi.model.ServletModel


 constructor:
 #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
 javax.servlet.Servlet, java.lang.String, java.lang.String[],
 java.lang.String, java.util.Dictionary,
 java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)


 it calles method ( private static )
 new String[]{aliasAsUrlPattern(alias)}


 private static String aliasAsUrlPattern(final String alias) {
 String urlPattern = alias;
 if (urlPattern != null && !urlPattern.equals("/")
 && !urlPattern.contains("*")) {
 if (urlPattern.endsWith("/")) {
 urlPattern = urlPattern + "*";
 } else {
 urlPattern = urlPattern + "/*";
 }
 }
 return urlPattern;
 }


 so it always creates a url pattern, as I guess the name suggest, but
 why? I would like to register exact URL, not the pattern. As it looks now,
 this is not possible to do - as there is no argument to pass in to control
 the flow.

 As it looks from the git history/log this is quite "old" code - from
 2008 - 2013, so I guess this is not new and I guess everybody are ok with
 this? So in this case, what is the usecase for it? As for my usecase - this
 is not the required behavior.

 For example, Servlet, registered with /hello, also matches /hello/1,
 but I want /hello/1 to return HTTP 404.


 So for now, only really question is - is this expected behavior or is
 there a room to change this? If so, how can one, with existing solution,
 register Servlet with exact URL?

 Exact strack of calls looks like this:

 :53, ServletModel (org.ops4j.pax.web.service.spi.model)
 registerServlet:224, HttpServiceStarted
 (org.ops4j.pax.web.service.internal)
 registerServlet:210, HttpServiceStarted
 (org.ops4j.pax.web.service.internal)
 registerServlet:69, HttpServiceProxy
 (org.ops4j.pax.web.service.internal)
 register:97, ServletWebElement
 (org.ops4j.pax.web.extender.whiteboard.internal.element)
 registerWebElement:392, WebApplication
 (org.ops4j.pax.web.extender.whiteboard.internal)
 addWebElement:188, WebApplication
 (org.ops4j.pax.web.extender.whiteboard.internal)
 addingService:193, AbstractTracker
 (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
 addingService:46, AbstractTracker
 (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Grzegorz Grzybek
Hello

I've checked
org.ops4j.pax.web.extender.whiteboard.internal.tracker.ServletTracker#createWebElement()
and indeed - it takes "alias" from "alias" property and may take patterns
from "urlPatterns" or "osgi.http.whiteboard.servlet.pattern" - but you
CAN'T specify "alias" property to do it.

Please don't use:

props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");

regards
Grzegorz

czw., 6 lut 2020 o 13:07 Miroslav Beranič 
napisał(a):

> Hi JB,
>
> Took the code from:
> https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/whiteboard
>
> to be able to use ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID => Virtual
> hosts "feature" of Jetty.
>
> {
> Dictionary props;
> props = new Hashtable<>();
>
> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
> props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "virtualhost");
>
> // Fail with Exception: from inside constructor of class
> org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement
> // props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello");
>
> props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP +
> "exactUrlPattern", Boolean.TRUE);
>
> servletReg = bundleContext.registerService(Servlet.class, new
> WhiteboardServlet("/hello"), props);
> }
>
> Kind Regards,
> Miroslav
>
>
> Dne četrtek, 06. februar 2020 12.50.17 UTC+1 je oseba Jean-Baptiste Onofré
> napisala:
>>
>> Hi
>>
>> Can you please share how you register the servlet ? Via the
>> httpService.register, Servlet service registration or whiteboard ?
>>
>> Thanks,
>> Regards
>> JB
>>
>> On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič 
>> wrote:
>>
>>> Hi all,
>>>
>>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with
>>> exact url, but I see url pattern is auto-generated from alias.
>>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>>>
>>> org.ops4j.pax.web.service.spi.model.ServletModel
>>>
>>>
>>> constructor:
>>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
>>> javax.servlet.Servlet, java.lang.String, java.lang.String[],
>>> java.lang.String, java.util.Dictionary,
>>> java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)
>>>
>>>
>>> it calles method ( private static )
>>> new String[]{aliasAsUrlPattern(alias)}
>>>
>>>
>>> private static String aliasAsUrlPattern(final String alias) {
>>> String urlPattern = alias;
>>> if (urlPattern != null && !urlPattern.equals("/")
>>> && !urlPattern.contains("*")) {
>>> if (urlPattern.endsWith("/")) {
>>> urlPattern = urlPattern + "*";
>>> } else {
>>> urlPattern = urlPattern + "/*";
>>> }
>>> }
>>> return urlPattern;
>>> }
>>>
>>>
>>> so it always creates a url pattern, as I guess the name suggest, but
>>> why? I would like to register exact URL, not the pattern. As it looks now,
>>> this is not possible to do - as there is no argument to pass in to control
>>> the flow.
>>>
>>> As it looks from the git history/log this is quite "old" code - from
>>> 2008 - 2013, so I guess this is not new and I guess everybody are ok with
>>> this? So in this case, what is the usecase for it? As for my usecase - this
>>> is not the required behavior.
>>>
>>> For example, Servlet, registered with /hello, also matches /hello/1, but
>>> I want /hello/1 to return HTTP 404.
>>>
>>>
>>> So for now, only really question is - is this expected behavior or is
>>> there a room to change this? If so, how can one, with existing solution,
>>> register Servlet with exact URL?
>>>
>>> Exact strack of calls looks like this:
>>>
>>> :53, ServletModel (org.ops4j.pax.web.service.spi.model)
>>> registerServlet:224, HttpServiceStarted
>>> (org.ops4j.pax.web.service.internal)
>>> registerServlet:210, HttpServiceStarted
>>> (org.ops4j.pax.web.service.internal)
>>> registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
>>> register:97, ServletWebElement
>>> (org.ops4j.pax.web.extender.whiteboard.internal.element)
>>> registerWebElement:392, WebApplication
>>> (org.ops4j.pax.web.extender.whiteboard.internal)
>>> addWebElement:188, WebApplication
>>> (org.ops4j.pax.web.extender.whiteboard.internal)
>>> addingService:193, AbstractTracker
>>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>>> addingService:46, AbstractTracker
>>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>>> customizerAdding:941, ServiceTracker$Tracked (org.osgi.util.tracker)
>>> customizerAdding:870, ServiceTracker$Tracked (org.osgi.util.tracker)
>>> trackAdding:256, AbstractTracked (org.osgi.util.tracker)
>>> track:229, AbstractTracked (org.osgi.util.tracker)
>>> serviceChanged:901, ServiceTracker$Tracked (org.osgi.util.tracker)
>>> invokeServiceListenerCallback:990, EventDispatcher
>>> (org.apache.felix.framework)
>>> fireEventImmediately:838, EventDispatcher (org.apache.felix.framework)
>>> fireServiceEvent:545, 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Miroslav Beranič
Hi Grzegorz,

I can "confirm" now,
either:

props.put("urlPatterns", new String[] { "/hello" }); // old Pax Web approach

or:

props.put("osgi.http.whiteboard.servlet.pattern", new String[] { "/hello" 
}); // new R6+ Whiteboard approach (chapter 140.4 "Registering Servlets").

will not work. Servlet is not registered. As constructor of class 
org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement 
will mark Servlet as valid = false, and warning log is written. Code is:
if (alias != null && urlPatterns != null && urlPatterns.length != 0) {
 LOG.warn("Registered servlet [{}] cannot have both alias and url 
patterns.", getServiceID());
valid = false;
}

And somwhere down the pipeline, Servlet is not registered. I do not have 
exact location with me now.


Kind Regards,
Miroslav






Dne četrtek, 06. februar 2020 13.07.01 UTC+1 je oseba Miroslav Beranič 
napisala:
>
> Hi JB,
>
> Took the code from:
> https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/whiteboard
>
> to be able to use ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID => Virtual 
> hosts "feature" of Jetty.
>
> {
> Dictionary props;
> props = new Hashtable<>();
>
> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
> props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "virtualhost");
>
> // Fail with Exception: from inside constructor of class 
> org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement
> // props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello");
>
> props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP + 
> "exactUrlPattern", Boolean.TRUE);
>
> servletReg = bundleContext.registerService(Servlet.class, new 
> WhiteboardServlet("/hello"), props);
> }
>
> Kind Regards,
> Miroslav
>
>
> Dne četrtek, 06. februar 2020 12.50.17 UTC+1 je oseba Jean-Baptiste Onofré 
> napisala:
>>
>> Hi
>>
>> Can you please share how you register the servlet ? Via the 
>> httpService.register, Servlet service registration or whiteboard ?
>>
>> Thanks,
>> Regards
>> JB
>>
>> On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič  
>> wrote:
>>
>>> Hi all,
>>>
>>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with 
>>> exact url, but I see url pattern is auto-generated from alias.
>>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>>>
>>> org.ops4j.pax.web.service.spi.model.ServletModel
>>>
>>>
>>> constructor:
>>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel, 
>>> javax.servlet.Servlet, java.lang.String, java.lang.String[], 
>>> java.lang.String, java.util.Dictionary, 
>>> java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)
>>>
>>>
>>> it calles method ( private static )
>>> new String[]{aliasAsUrlPattern(alias)}
>>>
>>>
>>> private static String aliasAsUrlPattern(final String alias) {
>>> String urlPattern = alias;
>>> if (urlPattern != null && !urlPattern.equals("/")
>>> && !urlPattern.contains("*")) {
>>> if (urlPattern.endsWith("/")) {
>>> urlPattern = urlPattern + "*";
>>> } else {
>>> urlPattern = urlPattern + "/*";
>>> }
>>> }
>>> return urlPattern;
>>> }
>>>
>>>
>>> so it always creates a url pattern, as I guess the name suggest, but 
>>> why? I would like to register exact URL, not the pattern. As it looks now, 
>>> this is not possible to do - as there is no argument to pass in to control 
>>> the flow.
>>>
>>> As it looks from the git history/log this is quite "old" code - from 
>>> 2008 - 2013, so I guess this is not new and I guess everybody are ok with 
>>> this? So in this case, what is the usecase for it? As for my usecase - this 
>>> is not the required behavior.
>>>
>>> For example, Servlet, registered with /hello, also matches /hello/1, but 
>>> I want /hello/1 to return HTTP 404.
>>>
>>>
>>> So for now, only really question is - is this expected behavior or is 
>>> there a room to change this? If so, how can one, with existing solution, 
>>> register Servlet with exact URL?
>>>
>>> Exact strack of calls looks like this:
>>>
>>> :53, ServletModel (org.ops4j.pax.web.service.spi.model)
>>> registerServlet:224, HttpServiceStarted 
>>> (org.ops4j.pax.web.service.internal)
>>> registerServlet:210, HttpServiceStarted 
>>> (org.ops4j.pax.web.service.internal)
>>> registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
>>> register:97, ServletWebElement 
>>> (org.ops4j.pax.web.extender.whiteboard.internal.element)
>>> registerWebElement:392, WebApplication 
>>> (org.ops4j.pax.web.extender.whiteboard.internal)
>>> addWebElement:188, WebApplication 
>>> (org.ops4j.pax.web.extender.whiteboard.internal)
>>> addingService:193, AbstractTracker 
>>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>>> addingService:46, AbstractTracker 
>>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>>> customizerAdding:941, 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Miroslav Beranič
Hi JB,

Took the code from:
https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/whiteboard

to be able to use ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID => Virtual 
hosts "feature" of Jetty.

{
Dictionary props;
props = new Hashtable<>();

props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello");
props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "virtualhost");

// Fail with Exception: from inside constructor of class 
org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement
// props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello");

props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP + 
"exactUrlPattern", Boolean.TRUE);

servletReg = bundleContext.registerService(Servlet.class, new 
WhiteboardServlet("/hello"), props);
}

Kind Regards,
Miroslav


Dne četrtek, 06. februar 2020 12.50.17 UTC+1 je oseba Jean-Baptiste Onofré 
napisala:
>
> Hi
>
> Can you please share how you register the servlet ? Via the 
> httpService.register, Servlet service registration or whiteboard ?
>
> Thanks,
> Regards
> JB
>
> On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič  > wrote:
>
>> Hi all,
>>
>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with 
>> exact url, but I see url pattern is auto-generated from alias.
>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>>
>> org.ops4j.pax.web.service.spi.model.ServletModel
>>
>>
>> constructor:
>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel, 
>> javax.servlet.Servlet, java.lang.String, java.lang.String[], 
>> java.lang.String, java.util.Dictionary, 
>> java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)
>>
>>
>> it calles method ( private static )
>> new String[]{aliasAsUrlPattern(alias)}
>>
>>
>> private static String aliasAsUrlPattern(final String alias) {
>> String urlPattern = alias;
>> if (urlPattern != null && !urlPattern.equals("/")
>> && !urlPattern.contains("*")) {
>> if (urlPattern.endsWith("/")) {
>> urlPattern = urlPattern + "*";
>> } else {
>> urlPattern = urlPattern + "/*";
>> }
>> }
>> return urlPattern;
>> }
>>
>>
>> so it always creates a url pattern, as I guess the name suggest, but why? 
>> I would like to register exact URL, not the pattern. As it looks now, this 
>> is not possible to do - as there is no argument to pass in to control the 
>> flow.
>>
>> As it looks from the git history/log this is quite "old" code - from 2008 
>> - 2013, so I guess this is not new and I guess everybody are ok with this? 
>> So in this case, what is the usecase for it? As for my usecase - this is 
>> not the required behavior.
>>
>> For example, Servlet, registered with /hello, also matches /hello/1, but 
>> I want /hello/1 to return HTTP 404.
>>
>>
>> So for now, only really question is - is this expected behavior or is 
>> there a room to change this? If so, how can one, with existing solution, 
>> register Servlet with exact URL?
>>
>> Exact strack of calls looks like this:
>>
>> :53, ServletModel (org.ops4j.pax.web.service.spi.model)
>> registerServlet:224, HttpServiceStarted 
>> (org.ops4j.pax.web.service.internal)
>> registerServlet:210, HttpServiceStarted 
>> (org.ops4j.pax.web.service.internal)
>> registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
>> register:97, ServletWebElement 
>> (org.ops4j.pax.web.extender.whiteboard.internal.element)
>> registerWebElement:392, WebApplication 
>> (org.ops4j.pax.web.extender.whiteboard.internal)
>> addWebElement:188, WebApplication 
>> (org.ops4j.pax.web.extender.whiteboard.internal)
>> addingService:193, AbstractTracker 
>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>> addingService:46, AbstractTracker 
>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>> customizerAdding:941, ServiceTracker$Tracked (org.osgi.util.tracker)
>> customizerAdding:870, ServiceTracker$Tracked (org.osgi.util.tracker)
>> trackAdding:256, AbstractTracked (org.osgi.util.tracker)
>> track:229, AbstractTracked (org.osgi.util.tracker)
>> serviceChanged:901, ServiceTracker$Tracked (org.osgi.util.tracker)
>> invokeServiceListenerCallback:990, EventDispatcher 
>> (org.apache.felix.framework)
>> fireEventImmediately:838, EventDispatcher (org.apache.felix.framework)
>> fireServiceEvent:545, EventDispatcher (org.apache.felix.framework)
>> fireServiceEvent:4595, Felix (org.apache.felix.framework)
>> registerService:3587, Felix (org.apache.felix.framework)
>> registerService:348, BundleContextImpl (org.apache.felix.framework)
>> registerService:355, BundleContextImpl (org.apache.felix.framework)
>>
>> I've changed this in my branch, added additional method with same name 
>> and initParams:
>>
>> private static String aliasAsUrlPattern(final String alias, final 
>> Dictionary initParams) {
>>final Object exactUrlPatternFromAliasParam = 
>> 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Miroslav Beranič
Hi Grzegorz,

I am using bundleContext "BundleContext.registerService(Servlet.class, 
servlet, props)", not the httpService ( httpService.registerServlet() )

I've tried props.put("urlPatterns", new String[] { "/hello" }); // old Pax 
Web approach , as it was one of my first tries to make it work, but ... 
only properties with "init." prefix are passed on to the creation of 
Element. But with that, Exception is thrown, saying that urlPattern and 
alias can not exist at the same time.

I did not try the props.put("osgi.http.whiteboard.servlet.pattern", new 
String[] { "/hello" }); // new R6+ Whiteboard approach (chapter 140.4 
"Registering Servlets"), but did not see in the code, where this is picked 
up. Will try this now.

So, I see JB is also asking .. I use OSGi Service registration of Servlet 
interface and implementation.

Kind Regards,
Miroslav



Dne četrtek, 06. februar 2020 12.48.49 UTC+1 je oseba Grzegorz Grzybek 
napisala:
>
> Hello
>
> Yes - this is all confusing... I'm just in the process of reviewing master 
> branch (pax web 8.0.0-SNAPSHOT) to check R7 (and even R6) compliance 
> There's really lot to do still...
>
> Indeed - I checked 
> org.ops4j.pax.web.service.spi.model.ServletModel#aliasAsUrlPattern() and it 
> really changes alias like "/something" into "/something/*", but Http 
> Service specification explicitly says (102.2 Registering Servlets):
>
> For example, if the Http Service implementation is listening to port 80 on 
> the machine www.acme.com and the Servlet object is registered with the 
> *name* "/servlet" [...]
>
> I noticed that the spec is not clear about "name" vs. "alias" vs. "URI 
> pattern"... And I believe your interpretation is the correct one - "alias" 
> is "exact URI pattern"... Of course it still doesn't tell anything about 
> actual context to use for servlet registration (I'm just working on making 
> it less confusing in pax web 8).
>
> So the only recommendation I have for you is not to use direct 
> registration (httpService.registerServlet()), but to use whiteboard 
> approach and register Servlet.class OSGi service using 
> "BundleContext.registerService(Servlet.class, servlet, props)" where 
> properties include either:
>
> props.put("urlPatterns", new String[] { "/hello" }); // old Pax Web 
> approach
>
> or:
>
> props.put("osgi.http.whiteboard.servlet.pattern", new String[] { "/hello" 
> }); // new R6+ Whiteboard approach (chapter 140.4 "Registering Servlets").
>
> I hope this helps and explains the confusion.
>
> regards
> Grzegorz Grzybek
>
> czw., 6 lut 2020 o 12:14 Miroslav Beranič  > napisał(a):
>
>> Hi all,
>>
>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with 
>> exact url, but I see url pattern is auto-generated from alias.
>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>>
>> org.ops4j.pax.web.service.spi.model.ServletModel
>>
>>
>> constructor:
>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel, 
>> javax.servlet.Servlet, java.lang.String, java.lang.String[], 
>> java.lang.String, java.util.Dictionary, 
>> java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)
>>
>>
>> it calles method ( private static )
>> new String[]{aliasAsUrlPattern(alias)}
>>
>>
>> private static String aliasAsUrlPattern(final String alias) {
>> String urlPattern = alias;
>> if (urlPattern != null && !urlPattern.equals("/")
>> && !urlPattern.contains("*")) {
>> if (urlPattern.endsWith("/")) {
>> urlPattern = urlPattern + "*";
>> } else {
>> urlPattern = urlPattern + "/*";
>> }
>> }
>> return urlPattern;
>> }
>>
>>
>> so it always creates a url pattern, as I guess the name suggest, but why? 
>> I would like to register exact URL, not the pattern. As it looks now, this 
>> is not possible to do - as there is no argument to pass in to control the 
>> flow.
>>
>> As it looks from the git history/log this is quite "old" code - from 2008 
>> - 2013, so I guess this is not new and I guess everybody are ok with this? 
>> So in this case, what is the usecase for it? As for my usecase - this is 
>> not the required behavior.
>>
>> For example, Servlet, registered with /hello, also matches /hello/1, but 
>> I want /hello/1 to return HTTP 404.
>>
>>
>> So for now, only really question is - is this expected behavior or is 
>> there a room to change this? If so, how can one, with existing solution, 
>> register Servlet with exact URL?
>>
>> Exact strack of calls looks like this:
>>
>> :53, ServletModel (org.ops4j.pax.web.service.spi.model)
>> registerServlet:224, HttpServiceStarted 
>> (org.ops4j.pax.web.service.internal)
>> registerServlet:210, HttpServiceStarted 
>> (org.ops4j.pax.web.service.internal)
>> registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
>> register:97, ServletWebElement 
>> (org.ops4j.pax.web.extender.whiteboard.internal.element)

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Grzegorz Grzybek
Hello

czw., 6 lut 2020 o 12:50 Jean-Baptiste Onofré 
napisał(a):

> Hi Grzegorz,
>
> Let's sync together about action plan as I started some changes as well.
>

Sure - I started a thread named "Pax Web 8 and beyond" ;) And I'm on IRC as
always.

regards
Grzegorz


> Regards
> JB
>
> On Thu, Feb 6, 2020 at 12:48 PM Grzegorz Grzybek 
> wrote:
>
>> Hello
>>
>> Yes - this is all confusing... I'm just in the process of reviewing
>> master branch (pax web 8.0.0-SNAPSHOT) to check R7 (and even R6)
>> compliance There's really lot to do still...
>>
>> Indeed - I checked
>> org.ops4j.pax.web.service.spi.model.ServletModel#aliasAsUrlPattern() and it
>> really changes alias like "/something" into "/something/*", but Http
>> Service specification explicitly says (102.2 Registering Servlets):
>>
>> For example, if the Http Service implementation is listening to port 80
>> on the machine www.acme.com and the Servlet object is registered with
>> the *name* "/servlet" [...]
>>
>> I noticed that the spec is not clear about "name" vs. "alias" vs. "URI
>> pattern"... And I believe your interpretation is the correct one - "alias"
>> is "exact URI pattern"... Of course it still doesn't tell anything about
>> actual context to use for servlet registration (I'm just working on making
>> it less confusing in pax web 8).
>>
>> So the only recommendation I have for you is not to use direct
>> registration (httpService.registerServlet()), but to use whiteboard
>> approach and register Servlet.class OSGi service using
>> "BundleContext.registerService(Servlet.class, servlet, props)" where
>> properties include either:
>>
>> props.put("urlPatterns", new String[] { "/hello" }); // old Pax Web
>> approach
>>
>> or:
>>
>> props.put("osgi.http.whiteboard.servlet.pattern", new String[] { "/hello"
>> }); // new R6+ Whiteboard approach (chapter 140.4 "Registering Servlets").
>>
>> I hope this helps and explains the confusion.
>>
>> regards
>> Grzegorz Grzybek
>>
>> czw., 6 lut 2020 o 12:14 Miroslav Beranič 
>> napisał(a):
>>
>>> Hi all,
>>>
>>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with
>>> exact url, but I see url pattern is auto-generated from alias.
>>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>>>
>>> org.ops4j.pax.web.service.spi.model.ServletModel
>>>
>>>
>>> constructor:
>>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
>>> javax.servlet.Servlet, java.lang.String, java.lang.String[],
>>> java.lang.String, java.util.Dictionary,
>>> java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)
>>>
>>>
>>> it calles method ( private static )
>>> new String[]{aliasAsUrlPattern(alias)}
>>>
>>>
>>> private static String aliasAsUrlPattern(final String alias) {
>>> String urlPattern = alias;
>>> if (urlPattern != null && !urlPattern.equals("/")
>>> && !urlPattern.contains("*")) {
>>> if (urlPattern.endsWith("/")) {
>>> urlPattern = urlPattern + "*";
>>> } else {
>>> urlPattern = urlPattern + "/*";
>>> }
>>> }
>>> return urlPattern;
>>> }
>>>
>>>
>>> so it always creates a url pattern, as I guess the name suggest, but
>>> why? I would like to register exact URL, not the pattern. As it looks now,
>>> this is not possible to do - as there is no argument to pass in to control
>>> the flow.
>>>
>>> As it looks from the git history/log this is quite "old" code - from
>>> 2008 - 2013, so I guess this is not new and I guess everybody are ok with
>>> this? So in this case, what is the usecase for it? As for my usecase - this
>>> is not the required behavior.
>>>
>>> For example, Servlet, registered with /hello, also matches /hello/1, but
>>> I want /hello/1 to return HTTP 404.
>>>
>>>
>>> So for now, only really question is - is this expected behavior or is
>>> there a room to change this? If so, how can one, with existing solution,
>>> register Servlet with exact URL?
>>>
>>> Exact strack of calls looks like this:
>>>
>>> :53, ServletModel (org.ops4j.pax.web.service.spi.model)
>>> registerServlet:224, HttpServiceStarted
>>> (org.ops4j.pax.web.service.internal)
>>> registerServlet:210, HttpServiceStarted
>>> (org.ops4j.pax.web.service.internal)
>>> registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
>>> register:97, ServletWebElement
>>> (org.ops4j.pax.web.extender.whiteboard.internal.element)
>>> registerWebElement:392, WebApplication
>>> (org.ops4j.pax.web.extender.whiteboard.internal)
>>> addWebElement:188, WebApplication
>>> (org.ops4j.pax.web.extender.whiteboard.internal)
>>> addingService:193, AbstractTracker
>>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>>> addingService:46, AbstractTracker
>>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>>> customizerAdding:941, ServiceTracker$Tracked (org.osgi.util.tracker)
>>> customizerAdding:870, ServiceTracker$Tracked (org.osgi.util.tracker)

Pax Web 8 and beyond

2020-02-06 Thread Grzegorz Grzybek
Hello

It's an information e-mail about the review I'm doing for Pax Web 8
(current master branch). The goal is to have working OSGi CMPN R7
implementation of:
 - Http Service specification, chapter 102 (no changes after R6)
 - Http Whiteboard specification, chapter 140 (changed after R6)

What I found is that Pax Web is not handling _contexts_ properly. It uses
confusing approach to "shared" context (with potential security
vulnerability), duplicates some interfaces, mixes Http Service and
Whiteboard APIs, doesn't handle properly properties like:

osgi.http.whiteboard.context.select = (osgi.http.whiteboard.context.name
=my-context)

or (allowed by specification):

osgi.http.whiteboard.context.select = (osgi.http.whiteboard.context.name=*)

or even (defined by specification):

osgi.http.whiteboard.context.select = (&(osgi.http.whiteboard.context.name
=*)(any.other=value1))

for whiteboard registration.

I'm not going to throw away any legacy code and even I don't want to touch
(much) existing interfaces (though they're almost begging to do it ;)). I'm
working in similar way to what I did with Pax Logging - review everything,
provide integration tests showing specification compliance and consult with
you - the community.

JBO - we can always share the working branches. My current work for now
mainly consists of:
 - providing javadocs
 - collecting strange and illegal scenarios allowed for now by Pax Web
 - collecting scenarios which should work, but don't work

regards
Grzegorz Grzybek

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ops4j/CAAdXmhrGmCL5KkYDC4o%3Dynrw-MpjWydRETQbiDQWLqk9am%2B7sw%40mail.gmail.com.


Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Jean-Baptiste Onofré
Hi

Can you please share how you register the servlet ? Via the
httpService.register, Servlet service registration or whiteboard ?

Thanks,
Regards
JB

On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič <
miroslav.bera...@mibesis.si> wrote:

> Hi all,
>
> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with
> exact url, but I see url pattern is auto-generated from alias.
> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>
> org.ops4j.pax.web.service.spi.model.ServletModel
>
>
> constructor:
> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
> javax.servlet.Servlet, java.lang.String, java.lang.String[],
> java.lang.String, java.util.Dictionary,
> java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)
>
>
> it calles method ( private static )
> new String[]{aliasAsUrlPattern(alias)}
>
>
> private static String aliasAsUrlPattern(final String alias) {
> String urlPattern = alias;
> if (urlPattern != null && !urlPattern.equals("/")
> && !urlPattern.contains("*")) {
> if (urlPattern.endsWith("/")) {
> urlPattern = urlPattern + "*";
> } else {
> urlPattern = urlPattern + "/*";
> }
> }
> return urlPattern;
> }
>
>
> so it always creates a url pattern, as I guess the name suggest, but why?
> I would like to register exact URL, not the pattern. As it looks now, this
> is not possible to do - as there is no argument to pass in to control the
> flow.
>
> As it looks from the git history/log this is quite "old" code - from 2008
> - 2013, so I guess this is not new and I guess everybody are ok with this?
> So in this case, what is the usecase for it? As for my usecase - this is
> not the required behavior.
>
> For example, Servlet, registered with /hello, also matches /hello/1, but I
> want /hello/1 to return HTTP 404.
>
>
> So for now, only really question is - is this expected behavior or is
> there a room to change this? If so, how can one, with existing solution,
> register Servlet with exact URL?
>
> Exact strack of calls looks like this:
>
> :53, ServletModel (org.ops4j.pax.web.service.spi.model)
> registerServlet:224, HttpServiceStarted
> (org.ops4j.pax.web.service.internal)
> registerServlet:210, HttpServiceStarted
> (org.ops4j.pax.web.service.internal)
> registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
> register:97, ServletWebElement
> (org.ops4j.pax.web.extender.whiteboard.internal.element)
> registerWebElement:392, WebApplication
> (org.ops4j.pax.web.extender.whiteboard.internal)
> addWebElement:188, WebApplication
> (org.ops4j.pax.web.extender.whiteboard.internal)
> addingService:193, AbstractTracker
> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
> addingService:46, AbstractTracker
> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
> customizerAdding:941, ServiceTracker$Tracked (org.osgi.util.tracker)
> customizerAdding:870, ServiceTracker$Tracked (org.osgi.util.tracker)
> trackAdding:256, AbstractTracked (org.osgi.util.tracker)
> track:229, AbstractTracked (org.osgi.util.tracker)
> serviceChanged:901, ServiceTracker$Tracked (org.osgi.util.tracker)
> invokeServiceListenerCallback:990, EventDispatcher
> (org.apache.felix.framework)
> fireEventImmediately:838, EventDispatcher (org.apache.felix.framework)
> fireServiceEvent:545, EventDispatcher (org.apache.felix.framework)
> fireServiceEvent:4595, Felix (org.apache.felix.framework)
> registerService:3587, Felix (org.apache.felix.framework)
> registerService:348, BundleContextImpl (org.apache.felix.framework)
> registerService:355, BundleContextImpl (org.apache.felix.framework)
>
> I've changed this in my branch, added additional method with same name and
> initParams:
>
> private static String aliasAsUrlPattern(final String alias, final
> Dictionary initParams) {
>final Object exactUrlPatternFromAliasParam =
> initParams.get("exactUrlPattern");
>Boolean exactUrlPatternFromAlias = Boolean.FALSE;
>if (null != exactUrlPatternFromAliasParam) {
>   if (exactUrlPatternFromAliasParam instanceof String) {
>  final String flag = ((String)
> exactUrlPatternFromAliasParam).toLowerCase();
>  exactUrlPatternFromAlias = Boolean.parseBoolean(flag);
>} else if(exactUrlPatternFromAliasParam instanceof Boolean) {
>  final Boolean flag = (Boolean) exactUrlPatternFromAliasParam;
>  exactUrlPatternFromAlias = flag;
>   } else if (exactUrlPatternFromAliasParam instanceof Serializable) {
>  final String flag =
> exactUrlPatternFromAliasParam.toString().toLowerCase();
>  exactUrlPatternFromAlias = Boolean.parseBoolean(flag);
>}
>}
>final String result;
>if (Boolean.TRUE.equals(exactUrlPatternFromAlias)) {
>   // Break the reference
>   result = alias.toString();
>} else {
>   result = aliasAsUrlPattern(alias);
>}
>return 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Jean-Baptiste Onofré
Hi Grzegorz,

Let's sync together about action plan as I started some changes as well.

Regards
JB

On Thu, Feb 6, 2020 at 12:48 PM Grzegorz Grzybek 
wrote:

> Hello
>
> Yes - this is all confusing... I'm just in the process of reviewing master
> branch (pax web 8.0.0-SNAPSHOT) to check R7 (and even R6) compliance
> There's really lot to do still...
>
> Indeed - I checked
> org.ops4j.pax.web.service.spi.model.ServletModel#aliasAsUrlPattern() and it
> really changes alias like "/something" into "/something/*", but Http
> Service specification explicitly says (102.2 Registering Servlets):
>
> For example, if the Http Service implementation is listening to port 80 on
> the machine www.acme.com and the Servlet object is registered with the
> *name* "/servlet" [...]
>
> I noticed that the spec is not clear about "name" vs. "alias" vs. "URI
> pattern"... And I believe your interpretation is the correct one - "alias"
> is "exact URI pattern"... Of course it still doesn't tell anything about
> actual context to use for servlet registration (I'm just working on making
> it less confusing in pax web 8).
>
> So the only recommendation I have for you is not to use direct
> registration (httpService.registerServlet()), but to use whiteboard
> approach and register Servlet.class OSGi service using
> "BundleContext.registerService(Servlet.class, servlet, props)" where
> properties include either:
>
> props.put("urlPatterns", new String[] { "/hello" }); // old Pax Web
> approach
>
> or:
>
> props.put("osgi.http.whiteboard.servlet.pattern", new String[] { "/hello"
> }); // new R6+ Whiteboard approach (chapter 140.4 "Registering Servlets").
>
> I hope this helps and explains the confusion.
>
> regards
> Grzegorz Grzybek
>
> czw., 6 lut 2020 o 12:14 Miroslav Beranič 
> napisał(a):
>
>> Hi all,
>>
>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with
>> exact url, but I see url pattern is auto-generated from alias.
>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>>
>> org.ops4j.pax.web.service.spi.model.ServletModel
>>
>>
>> constructor:
>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
>> javax.servlet.Servlet, java.lang.String, java.lang.String[],
>> java.lang.String, java.util.Dictionary,
>> java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)
>>
>>
>> it calles method ( private static )
>> new String[]{aliasAsUrlPattern(alias)}
>>
>>
>> private static String aliasAsUrlPattern(final String alias) {
>> String urlPattern = alias;
>> if (urlPattern != null && !urlPattern.equals("/")
>> && !urlPattern.contains("*")) {
>> if (urlPattern.endsWith("/")) {
>> urlPattern = urlPattern + "*";
>> } else {
>> urlPattern = urlPattern + "/*";
>> }
>> }
>> return urlPattern;
>> }
>>
>>
>> so it always creates a url pattern, as I guess the name suggest, but why?
>> I would like to register exact URL, not the pattern. As it looks now, this
>> is not possible to do - as there is no argument to pass in to control the
>> flow.
>>
>> As it looks from the git history/log this is quite "old" code - from 2008
>> - 2013, so I guess this is not new and I guess everybody are ok with this?
>> So in this case, what is the usecase for it? As for my usecase - this is
>> not the required behavior.
>>
>> For example, Servlet, registered with /hello, also matches /hello/1, but
>> I want /hello/1 to return HTTP 404.
>>
>>
>> So for now, only really question is - is this expected behavior or is
>> there a room to change this? If so, how can one, with existing solution,
>> register Servlet with exact URL?
>>
>> Exact strack of calls looks like this:
>>
>> :53, ServletModel (org.ops4j.pax.web.service.spi.model)
>> registerServlet:224, HttpServiceStarted
>> (org.ops4j.pax.web.service.internal)
>> registerServlet:210, HttpServiceStarted
>> (org.ops4j.pax.web.service.internal)
>> registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
>> register:97, ServletWebElement
>> (org.ops4j.pax.web.extender.whiteboard.internal.element)
>> registerWebElement:392, WebApplication
>> (org.ops4j.pax.web.extender.whiteboard.internal)
>> addWebElement:188, WebApplication
>> (org.ops4j.pax.web.extender.whiteboard.internal)
>> addingService:193, AbstractTracker
>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>> addingService:46, AbstractTracker
>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
>> customizerAdding:941, ServiceTracker$Tracked (org.osgi.util.tracker)
>> customizerAdding:870, ServiceTracker$Tracked (org.osgi.util.tracker)
>> trackAdding:256, AbstractTracked (org.osgi.util.tracker)
>> track:229, AbstractTracked (org.osgi.util.tracker)
>> serviceChanged:901, ServiceTracker$Tracked (org.osgi.util.tracker)
>> invokeServiceListenerCallback:990, EventDispatcher
>> (org.apache.felix.framework)
>> fireEventImmediately:838, 

Re: [PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Grzegorz Grzybek
Hello

Yes - this is all confusing... I'm just in the process of reviewing master
branch (pax web 8.0.0-SNAPSHOT) to check R7 (and even R6) compliance
There's really lot to do still...

Indeed - I checked
org.ops4j.pax.web.service.spi.model.ServletModel#aliasAsUrlPattern() and it
really changes alias like "/something" into "/something/*", but Http
Service specification explicitly says (102.2 Registering Servlets):

For example, if the Http Service implementation is listening to port 80 on
the machine www.acme.com and the Servlet object is registered with the
*name* "/servlet" [...]

I noticed that the spec is not clear about "name" vs. "alias" vs. "URI
pattern"... And I believe your interpretation is the correct one - "alias"
is "exact URI pattern"... Of course it still doesn't tell anything about
actual context to use for servlet registration (I'm just working on making
it less confusing in pax web 8).

So the only recommendation I have for you is not to use direct registration
(httpService.registerServlet()), but to use whiteboard approach and
register Servlet.class OSGi service using
"BundleContext.registerService(Servlet.class, servlet, props)" where
properties include either:

props.put("urlPatterns", new String[] { "/hello" }); // old Pax Web approach

or:

props.put("osgi.http.whiteboard.servlet.pattern", new String[] { "/hello"
}); // new R6+ Whiteboard approach (chapter 140.4 "Registering Servlets").

I hope this helps and explains the confusion.

regards
Grzegorz Grzybek

czw., 6 lut 2020 o 12:14 Miroslav Beranič 
napisał(a):

> Hi all,
>
> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with
> exact url, but I see url pattern is auto-generated from alias.
> I look at the current master branch - version 8.0.0-SNAPSHOT. Class:
>
> org.ops4j.pax.web.service.spi.model.ServletModel
>
>
> constructor:
> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel,
> javax.servlet.Servlet, java.lang.String, java.lang.String[],
> java.lang.String, java.util.Dictionary,
> java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)
>
>
> it calles method ( private static )
> new String[]{aliasAsUrlPattern(alias)}
>
>
> private static String aliasAsUrlPattern(final String alias) {
> String urlPattern = alias;
> if (urlPattern != null && !urlPattern.equals("/")
> && !urlPattern.contains("*")) {
> if (urlPattern.endsWith("/")) {
> urlPattern = urlPattern + "*";
> } else {
> urlPattern = urlPattern + "/*";
> }
> }
> return urlPattern;
> }
>
>
> so it always creates a url pattern, as I guess the name suggest, but why?
> I would like to register exact URL, not the pattern. As it looks now, this
> is not possible to do - as there is no argument to pass in to control the
> flow.
>
> As it looks from the git history/log this is quite "old" code - from 2008
> - 2013, so I guess this is not new and I guess everybody are ok with this?
> So in this case, what is the usecase for it? As for my usecase - this is
> not the required behavior.
>
> For example, Servlet, registered with /hello, also matches /hello/1, but I
> want /hello/1 to return HTTP 404.
>
>
> So for now, only really question is - is this expected behavior or is
> there a room to change this? If so, how can one, with existing solution,
> register Servlet with exact URL?
>
> Exact strack of calls looks like this:
>
> :53, ServletModel (org.ops4j.pax.web.service.spi.model)
> registerServlet:224, HttpServiceStarted
> (org.ops4j.pax.web.service.internal)
> registerServlet:210, HttpServiceStarted
> (org.ops4j.pax.web.service.internal)
> registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
> register:97, ServletWebElement
> (org.ops4j.pax.web.extender.whiteboard.internal.element)
> registerWebElement:392, WebApplication
> (org.ops4j.pax.web.extender.whiteboard.internal)
> addWebElement:188, WebApplication
> (org.ops4j.pax.web.extender.whiteboard.internal)
> addingService:193, AbstractTracker
> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
> addingService:46, AbstractTracker
> (org.ops4j.pax.web.extender.whiteboard.internal.tracker)
> customizerAdding:941, ServiceTracker$Tracked (org.osgi.util.tracker)
> customizerAdding:870, ServiceTracker$Tracked (org.osgi.util.tracker)
> trackAdding:256, AbstractTracked (org.osgi.util.tracker)
> track:229, AbstractTracked (org.osgi.util.tracker)
> serviceChanged:901, ServiceTracker$Tracked (org.osgi.util.tracker)
> invokeServiceListenerCallback:990, EventDispatcher
> (org.apache.felix.framework)
> fireEventImmediately:838, EventDispatcher (org.apache.felix.framework)
> fireServiceEvent:545, EventDispatcher (org.apache.felix.framework)
> fireServiceEvent:4595, Felix (org.apache.felix.framework)
> registerService:3587, Felix (org.apache.felix.framework)
> registerService:348, BundleContextImpl (org.apache.felix.framework)
> 

[PAX WEB] Url Pattern is auto-generated from Alias and how to register exact url pattern

2020-02-06 Thread Miroslav Beranič
Hi all,

I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet with 
exact url, but I see url pattern is auto-generated from alias.
I look at the current master branch - version 8.0.0-SNAPSHOT. Class:

org.ops4j.pax.web.service.spi.model.ServletModel


constructor:
#ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel, 
javax.servlet.Servlet, java.lang.String, java.lang.String[], 
java.lang.String, java.util.Dictionary, 
java.lang.Integer, java.lang.Boolean, javax.servlet.MultipartConfigElement)


it calles method ( private static )
new String[]{aliasAsUrlPattern(alias)}


private static String aliasAsUrlPattern(final String alias) {
String urlPattern = alias;
if (urlPattern != null && !urlPattern.equals("/")
&& !urlPattern.contains("*")) {
if (urlPattern.endsWith("/")) {
urlPattern = urlPattern + "*";
} else {
urlPattern = urlPattern + "/*";
}
}
return urlPattern;
}


so it always creates a url pattern, as I guess the name suggest, but why? I 
would like to register exact URL, not the pattern. As it looks now, this is 
not possible to do - as there is no argument to pass in to control the flow.

As it looks from the git history/log this is quite "old" code - from 2008 - 
2013, so I guess this is not new and I guess everybody are ok with this? So 
in this case, what is the usecase for it? As for my usecase - this is not 
the required behavior.

For example, Servlet, registered with /hello, also matches /hello/1, but I 
want /hello/1 to return HTTP 404.


So for now, only really question is - is this expected behavior or is there 
a room to change this? If so, how can one, with existing solution, register 
Servlet with exact URL?

Exact strack of calls looks like this:

:53, ServletModel (org.ops4j.pax.web.service.spi.model)
registerServlet:224, HttpServiceStarted (org.ops4j.pax.web.service.internal)
registerServlet:210, HttpServiceStarted (org.ops4j.pax.web.service.internal)
registerServlet:69, HttpServiceProxy (org.ops4j.pax.web.service.internal)
register:97, ServletWebElement 
(org.ops4j.pax.web.extender.whiteboard.internal.element)
registerWebElement:392, WebApplication 
(org.ops4j.pax.web.extender.whiteboard.internal)
addWebElement:188, WebApplication 
(org.ops4j.pax.web.extender.whiteboard.internal)
addingService:193, AbstractTracker 
(org.ops4j.pax.web.extender.whiteboard.internal.tracker)
addingService:46, AbstractTracker 
(org.ops4j.pax.web.extender.whiteboard.internal.tracker)
customizerAdding:941, ServiceTracker$Tracked (org.osgi.util.tracker)
customizerAdding:870, ServiceTracker$Tracked (org.osgi.util.tracker)
trackAdding:256, AbstractTracked (org.osgi.util.tracker)
track:229, AbstractTracked (org.osgi.util.tracker)
serviceChanged:901, ServiceTracker$Tracked (org.osgi.util.tracker)
invokeServiceListenerCallback:990, EventDispatcher 
(org.apache.felix.framework)
fireEventImmediately:838, EventDispatcher (org.apache.felix.framework)
fireServiceEvent:545, EventDispatcher (org.apache.felix.framework)
fireServiceEvent:4595, Felix (org.apache.felix.framework)
registerService:3587, Felix (org.apache.felix.framework)
registerService:348, BundleContextImpl (org.apache.felix.framework)
registerService:355, BundleContextImpl (org.apache.felix.framework)

I've changed this in my branch, added additional method with same name and 
initParams:

private static String aliasAsUrlPattern(final String alias, final 
Dictionary initParams) {
   final Object exactUrlPatternFromAliasParam = 
initParams.get("exactUrlPattern");
   Boolean exactUrlPatternFromAlias = Boolean.FALSE;
   if (null != exactUrlPatternFromAliasParam) {
  if (exactUrlPatternFromAliasParam instanceof String) {
 final String flag = ((String) 
exactUrlPatternFromAliasParam).toLowerCase();
 exactUrlPatternFromAlias = Boolean.parseBoolean(flag);
   } else if(exactUrlPatternFromAliasParam instanceof Boolean) {
 final Boolean flag = (Boolean) exactUrlPatternFromAliasParam;
 exactUrlPatternFromAlias = flag;
  } else if (exactUrlPatternFromAliasParam instanceof Serializable) {
 final String flag = 
exactUrlPatternFromAliasParam.toString().toLowerCase();
 exactUrlPatternFromAlias = Boolean.parseBoolean(flag);
   }
   }
   final String result;
   if (Boolean.TRUE.equals(exactUrlPatternFromAlias)) {
  // Break the reference
  result = alias.toString();
   } else {
  result = aliasAsUrlPattern(alias);
   }
   return result;
}


This calls original unmodified version of method aliasAsUrlPattern.

Caller has to pass additional init parameter "exactUrlPattern". I usually 
call it with Boolean.TRUE. I guess flag could/should be added into 
org.ops4j.pax.web.extender.whiteboard.ExtenderConstants.

To note one other thing -- this is " one of the use cases ", I as see there 
is also construction, that allows to pass in defined url patterns, but I