You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by "Leschke, Scott" <SL...@medline.com> on 2018/10/22 21:04:50 UTC

Http Whiteboard

I've in the process of trying to convert a couple of servlets over to user HttpWhiteboard. I looked online for an example and it seemed pretty straight forward.
Based on my understanding, I came up with the following but it doesn't work. Jetty doesn't have a myApp context. I assume there is something missing?

Help?

Scott


@Component(
       property  = {
              HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME,
              HTTP_WHITEBOARD_CONTEXT_PATH + '=' + ContextHelper.CTX_PATH
       }
)
public class ContextHelper
       extends org.osgi.service.http.context.ServletContextHelper
{
       public static final String CTX_NAME = "myApp";
       public static final String CTX_PATH = '/' + CTX_NAME;
}


@Component(
       name      = "myApp.listings",
       property  = {
              HTTP_WHITEBOARD_CONTEXT_SELECT  + "=(" + HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME + ')',
              HTTP_WHITEBOARD_SERVLET_NAME    + '=' + "MyApp Listings",
              HTTP_WHITEBOARD_SERVLET_PATTERN + '=' + "/list/*"
       },
       service   = Servlet.class,
       immediate = true)
@Designate(
       ocd = AppConfig.class)
public class Listings
       implements HttpServlet
{...}

Re: Http Whiteboard

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> Here is a working example:

One thing I forgot about the working example:
 - I need to have HTTP whiteboard loaded when I start the servlet
   components

I accomplish this by adding a dependency to the pax-http-whiteboard
feature in the template karaf feature files of the bundles holding the
DS components that contain services that want to register with the HTTP
whiteboad:
  https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.security/src/main/feature/feature.xml#L21

>  1. This defines the web context "/ukelonn" (and attaches a shiro filter
>     to the web context)
>      https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnServletContextHelper.java#L7
>      https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java#L42

>  2. Here are servlets that register with the webcontext
>      https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.services/src/main/java/no/priv/bang/ukelonn/api/UkelonnRestApiServlet.java#L37
>      https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.frontend/src/main/java/no/priv/bang/ukelonn/web/frontend/UkelonnServlet.java#L36

> The syntax for registering with the context ie.
>        HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +"=ukelonn)",
> is a bit clumsy, but it works.

> (I have on my todo list to figure out if the servlet API 3.0 annotations
> can be used instead...)




Re: Http Whiteboard

Posted by Steinar Bang <sb...@dod.no>.
>>>>> "Leschke, Scott" <SL...@medline.com>:

> Thanks Tim,
> That’s exactly what I thought but without it I get the following from Jetty.
> HTTP ERROR 404
> Problem accessing /myApp/. Reason:
>     Not Found

> Perhaps that’s related to something else and the presence/absence of
> Web-ContextPath is triggering the other issue.  I’ll see what I can
> figure out in that regard.

Here is a working example:
 1. This defines the web context "/ukelonn" (and attaches a shiro filter
    to the web context)
     https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnServletContextHelper.java#L7
     https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java#L42

 2. Here are servlets that register with the webcontext
     https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.services/src/main/java/no/priv/bang/ukelonn/api/UkelonnRestApiServlet.java#L37
     https://github.com/steinarb/ukelonn/blob/8442f5df62bc973902085705c637e65c3bc00f8c/ukelonn.web.frontend/src/main/java/no/priv/bang/ukelonn/web/frontend/UkelonnServlet.java#L36

The syntax for registering with the context ie.
       HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +"=ukelonn)",
is a bit clumsy, but it works.

(I have on my todo list to figure out if the servlet API 3.0 annotations
can be used instead...)


RE: Http Whiteboard

Posted by "Leschke, Scott" <SL...@medline.com>.
OK, got it.  Sorry I realize now that’s what you were trying to tell me but I was slow on the uptake.

Thanks

From: Tim Ward <ti...@paremus.com>
Sent: Tuesday, October 23, 2018 11:14 AM
To: user@karaf.apache.org
Subject: Re: Http Whiteboard

You should be able to do:

HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_1,
HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_2,
HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_3,
HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_4,
...


Sent from my iPhone

On 23 Oct 2018, at 18:06, Leschke, Scott <SL...@medline.com>> wrote:
HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_LIST

Re: Http Whiteboard

Posted by Tim Ward <ti...@paremus.com>.
You should be able to do:

HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_1,
HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_2,
HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_3,
HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_4,
...


Sent from my iPhone

> On 23 Oct 2018, at 18:06, Leschke, Scott <SL...@medline.com> wrote:
> 
> HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_LIST

RE: Http Whiteboard

Posted by "Leschke, Scott" <SL...@medline.com>.
I’m a bit confused.  I’m doing this with OSGi R6 so the URL pattern list has to be the latter part of the string created by:

HTTP_WHITEBOARD_SERVLET_PATTERN + ‘=’  + PATTERN_LIST

does it not?

From: Tim Ward <ti...@paremus.com>
Sent: Tuesday, October 23, 2018 10:58 AM
To: user@karaf.apache.org
Subject: Re: Http Whiteboard

You can have multiple patterns just by adding the property as a String[]/Collection. See https://osgi.org/javadoc/osgi.cmpn/7.0.0/org/osgi/service/http/whiteboard/propertytypes/HttpWhiteboardServletPattern.html#value-- which is the component property type for that whiteboard property.

If you can’t use component property types then repeated single value entries in the property element get aggregated into an array.

Tim


On 23 Oct 2018, at 17:32, Leschke, Scott <SL...@medline.com>> wrote:

Thanks Tim,

That’s exactly what I thought but without it I get the following from Jetty.
HTTP ERROR 404
Problem accessing /myApp/. Reason:
    Not Found

Perhaps that’s related to something else and the presence/absence of Web-ContextPath is triggering the other issue.  I’ll see what I can figure out in that regard.

I do have one last question though. I’m wondering what the syntax is to associate multiple URL patterns with a single servlet.  I assume I can use wildcarding and stuff like that but can I use a Java RE?  How about a URL list?  Comma separated, bounded by braces, brackets?

I’m thought I had a copy of the R6 compendium squirreled away so that I could just look it up but it may be on my machine at home and for some reason I’m not seeing it at osgi.org<http://osgi.org/> even though I’m sure it’s there somewhere.

Scott

From: Tim Ward <ti...@paremus.com>>
Sent: Tuesday, October 23, 2018 10:09 AM
To: user@karaf.apache.org<ma...@karaf.apache.org>
Subject: Re: Http Whiteboard

I wouldn’t expect you to need anything specific in your bnd file. Web-ContextPath is part of a different OSGi specification (the Web Application Bundle spec) so there shouldn’t be any need for that at all.

Best Regards,

Tim



On 23 Oct 2018, at 17:06, Leschke, Scott <SL...@medline.com>> wrote:

Thanks Tim.  That was the problem. I noticed that just after I sent the email but hadn’t had a chance to try it yet.  I pulled that from a YouTube video Ray Auge did way back in 2014 and sort of blindly regurgitated what I saw.

There’s something else I noticed though.  It would seem that it’s still necessary to define
Web-ContextPath .bnd file as it doesn’t appear to work without that.  Is that right?

From: Tim Ward <ti...@paremus.com>>
Sent: Monday, October 22, 2018 4:28 PM
To: user@karaf.apache.org<ma...@karaf.apache.org>
Subject: Re: Http Whiteboard

I’m pretty sure that your ServletContextHelper isn’t advertised as a service and is therefore invisible to the whiteboard. ServletContextHelper is not an interface so you need to be explicit.

Tim
Sent from my iPhone

On 22 Oct 2018, at 23:04, Leschke, Scott <SL...@medline.com>> wrote:

I’ve in the process of trying to convert a couple of servlets over to user HttpWhiteboard. I looked online for an example and it seemed pretty straight forward.
Based on my understanding, I came up with the following but it doesn’t work. Jetty doesn’t have a myApp context. I assume there is something missing?

Help?

Scott


@Component(
       property  = {
              HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME,
              HTTP_WHITEBOARD_CONTEXT_PATH + '=' + ContextHelper.CTX_PATH
       }
)
public class ContextHelper
       extends org.osgi.service.http.context.ServletContextHelper
{
       public static final String CTX_NAME = "myApp";
       public static final String CTX_PATH = '/' + CTX_NAME;
}


@Component(
       name      = “myApp.listings",
       property  = {
              HTTP_WHITEBOARD_CONTEXT_SELECT  + "=(" + HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME + ')',
              HTTP_WHITEBOARD_SERVLET_NAME    + '=' + "MyApp Listings",
              HTTP_WHITEBOARD_SERVLET_PATTERN + '=' + "/list/*"
       },
       service   = Servlet.class,
       immediate = true)
@Designate(
       ocd = AppConfig.class)
public class Listings
       implements HttpServlet
{…}


Re: Http Whiteboard

Posted by Tim Ward <ti...@paremus.com>.
You can have multiple patterns just by adding the property as a String[]/Collection. See https://osgi.org/javadoc/osgi.cmpn/7.0.0/org/osgi/service/http/whiteboard/propertytypes/HttpWhiteboardServletPattern.html#value-- <https://osgi.org/javadoc/osgi.cmpn/7.0.0/org/osgi/service/http/whiteboard/propertytypes/HttpWhiteboardServletPattern.html#value--> which is the component property type for that whiteboard property.

If you can’t use component property types then repeated single value entries in the property element get aggregated into an array.

Tim

> On 23 Oct 2018, at 17:32, Leschke, Scott <SL...@medline.com> wrote:
> 
> Thanks Tim,
>  
> That’s exactly what I thought but without it I get the following from Jetty.
> HTTP ERROR 404
> Problem accessing /myApp/. Reason:
>     Not Found
>  
> Perhaps that’s related to something else and the presence/absence of Web-ContextPath is triggering the other issue.  I’ll see what I can figure out in that regard.
>  
> I do have one last question though. I’m wondering what the syntax is to associate multiple URL patterns with a single servlet.  I assume I can use wildcarding and stuff like that but can I use a Java RE?  How about a URL list?  Comma separated, bounded by braces, brackets?
>  
> I’m thought I had a copy of the R6 compendium squirreled away so that I could just look it up but it may be on my machine at home and for some reason I’m not seeing it at osgi.org <http://osgi.org/> even though I’m sure it’s there somewhere.
>  
> Scott
>  
> From: Tim Ward <ti...@paremus.com> 
> Sent: Tuesday, October 23, 2018 10:09 AM
> To: user@karaf.apache.org
> Subject: Re: Http Whiteboard
>  
> I wouldn’t expect you to need anything specific in your bnd file. Web-ContextPath is part of a different OSGi specification (the Web Application Bundle spec) so there shouldn’t be any need for that at all.
>  
> Best Regards,
>  
> Tim
> 
> 
> On 23 Oct 2018, at 17:06, Leschke, Scott <SLeschke@medline.com <ma...@medline.com>> wrote:
>  
> Thanks Tim.  That was the problem. I noticed that just after I sent the email but hadn’t had a chance to try it yet.  I pulled that from a YouTube video Ray Auge did way back in 2014 and sort of blindly regurgitated what I saw.  
>  
> There’s something else I noticed though.  It would seem that it’s still necessary to define
> Web-ContextPath .bnd file as it doesn’t appear to work without that.  Is that right?
>  
> From: Tim Ward <tim.ward@paremus.com <ma...@paremus.com>> 
> Sent: Monday, October 22, 2018 4:28 PM
> To: user@karaf.apache.org <ma...@karaf.apache.org>
> Subject: Re: Http Whiteboard
>  
> I’m pretty sure that your ServletContextHelper isn’t advertised as a service and is therefore invisible to the whiteboard. ServletContextHelper is not an interface so you need to be explicit. 
>  
> Tim
> 
> Sent from my iPhone
> 
> On 22 Oct 2018, at 23:04, Leschke, Scott <SLeschke@medline.com <ma...@medline.com>> wrote:
> 
>  
> I’ve in the process of trying to convert a couple of servlets over to user HttpWhiteboard. I looked online for an example and it seemed pretty straight forward.
> Based on my understanding, I came up with the following but it doesn’t work. Jetty doesn’t have a myApp context. I assume there is something missing?
>  
> Help?
>  
> Scott
>  
>  
> @Component(
>        property  = {
>               HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME,
>               HTTP_WHITEBOARD_CONTEXT_PATH + '=' + ContextHelper.CTX_PATH
>        }
> )
> public class ContextHelper
>        extends org.osgi.service.http.context.ServletContextHelper
> {
>        public static final String CTX_NAME = "myApp";
>        public static final String CTX_PATH = '/' + CTX_NAME;
> }
>  
>  
> @Component(
>        name      = “myApp.listings",
>        property  = {
>               HTTP_WHITEBOARD_CONTEXT_SELECT  + "=(" + HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME + ')',
>               HTTP_WHITEBOARD_SERVLET_NAME    + '=' + "MyApp Listings",
>               HTTP_WHITEBOARD_SERVLET_PATTERN + '=' + "/list/*"
>        },
>        service   = Servlet.class,
>        immediate = true)
> @Designate(
>        ocd = AppConfig.class)
> public class Listings
>        implements HttpServlet
> {…}


RE: Http Whiteboard

Posted by "Leschke, Scott" <SL...@medline.com>.
Thanks Tim,

That’s exactly what I thought but without it I get the following from Jetty.
HTTP ERROR 404
Problem accessing /myApp/. Reason:
    Not Found

Perhaps that’s related to something else and the presence/absence of Web-ContextPath is triggering the other issue.  I’ll see what I can figure out in that regard.

I do have one last question though. I’m wondering what the syntax is to associate multiple URL patterns with a single servlet.  I assume I can use wildcarding and stuff like that but can I use a Java RE?  How about a URL list?  Comma separated, bounded by braces, brackets?

I’m thought I had a copy of the R6 compendium squirreled away so that I could just look it up but it may be on my machine at home and for some reason I’m not seeing it at osgi.org even though I’m sure it’s there somewhere.

Scott

From: Tim Ward <ti...@paremus.com>
Sent: Tuesday, October 23, 2018 10:09 AM
To: user@karaf.apache.org
Subject: Re: Http Whiteboard

I wouldn’t expect you to need anything specific in your bnd file. Web-ContextPath is part of a different OSGi specification (the Web Application Bundle spec) so there shouldn’t be any need for that at all.

Best Regards,

Tim


On 23 Oct 2018, at 17:06, Leschke, Scott <SL...@medline.com>> wrote:

Thanks Tim.  That was the problem. I noticed that just after I sent the email but hadn’t had a chance to try it yet.  I pulled that from a YouTube video Ray Auge did way back in 2014 and sort of blindly regurgitated what I saw.

There’s something else I noticed though.  It would seem that it’s still necessary to define
Web-ContextPath .bnd file as it doesn’t appear to work without that.  Is that right?

From: Tim Ward <ti...@paremus.com>>
Sent: Monday, October 22, 2018 4:28 PM
To: user@karaf.apache.org<ma...@karaf.apache.org>
Subject: Re: Http Whiteboard

I’m pretty sure that your ServletContextHelper isn’t advertised as a service and is therefore invisible to the whiteboard. ServletContextHelper is not an interface so you need to be explicit.

Tim
Sent from my iPhone

On 22 Oct 2018, at 23:04, Leschke, Scott <SL...@medline.com>> wrote:

I’ve in the process of trying to convert a couple of servlets over to user HttpWhiteboard. I looked online for an example and it seemed pretty straight forward.
Based on my understanding, I came up with the following but it doesn’t work. Jetty doesn’t have a myApp context. I assume there is something missing?

Help?

Scott


@Component(
       property  = {
              HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME,
              HTTP_WHITEBOARD_CONTEXT_PATH + '=' + ContextHelper.CTX_PATH
       }
)
public class ContextHelper
       extends org.osgi.service.http.context.ServletContextHelper
{
       public static final String CTX_NAME = "myApp";
       public static final String CTX_PATH = '/' + CTX_NAME;
}


@Component(
       name      = “myApp.listings",
       property  = {
              HTTP_WHITEBOARD_CONTEXT_SELECT  + "=(" + HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME + ')',
              HTTP_WHITEBOARD_SERVLET_NAME    + '=' + "MyApp Listings",
              HTTP_WHITEBOARD_SERVLET_PATTERN + '=' + "/list/*"
       },
       service   = Servlet.class,
       immediate = true)
@Designate(
       ocd = AppConfig.class)
public class Listings
       implements HttpServlet
{…}


Re: Http Whiteboard

Posted by Tim Ward <ti...@paremus.com>.
I wouldn’t expect you to need anything specific in your bnd file. Web-ContextPath is part of a different OSGi specification (the Web Application Bundle spec) so there shouldn’t be any need for that at all.

Best Regards,

Tim

> On 23 Oct 2018, at 17:06, Leschke, Scott <SL...@medline.com> wrote:
> 
> Thanks Tim.  That was the problem. I noticed that just after I sent the email but hadn’t had a chance to try it yet.  I pulled that from a YouTube video Ray Auge did way back in 2014 and sort of blindly regurgitated what I saw.  
>  
> There’s something else I noticed though.  It would seem that it’s still necessary to define
> Web-ContextPath .bnd file as it doesn’t appear to work without that.  Is that right?
>  
> From: Tim Ward <ti...@paremus.com> 
> Sent: Monday, October 22, 2018 4:28 PM
> To: user@karaf.apache.org
> Subject: Re: Http Whiteboard
>  
> I’m pretty sure that your ServletContextHelper isn’t advertised as a service and is therefore invisible to the whiteboard. ServletContextHelper is not an interface so you need to be explicit. 
>  
> Tim
> 
> Sent from my iPhone
> 
> On 22 Oct 2018, at 23:04, Leschke, Scott <SLeschke@medline.com <ma...@medline.com>> wrote:
> 
>  
> I’ve in the process of trying to convert a couple of servlets over to user HttpWhiteboard. I looked online for an example and it seemed pretty straight forward.
> Based on my understanding, I came up with the following but it doesn’t work. Jetty doesn’t have a myApp context. I assume there is something missing?
>  
> Help?
>  
> Scott
>  
>  
> @Component(
>        property  = {
>               HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME,
>               HTTP_WHITEBOARD_CONTEXT_PATH + '=' + ContextHelper.CTX_PATH
>        }
> )
> public class ContextHelper
>        extends org.osgi.service.http.context.ServletContextHelper
> {
>        public static final String CTX_NAME = "myApp";
>        public static final String CTX_PATH = '/' + CTX_NAME;
> }
>  
>  
> @Component(
>        name      = “myApp.listings",
>        property  = {
>               HTTP_WHITEBOARD_CONTEXT_SELECT  + "=(" + HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME + ')',
>               HTTP_WHITEBOARD_SERVLET_NAME    + '=' + "MyApp Listings",
>               HTTP_WHITEBOARD_SERVLET_PATTERN + '=' + "/list/*"
>        },
>        service   = Servlet.class,
>        immediate = true)
> @Designate(
>        ocd = AppConfig.class)
> public class Listings
>        implements HttpServlet
> {…}


RE: Http Whiteboard

Posted by "Leschke, Scott" <SL...@medline.com>.
Thanks Tim.  That was the problem. I noticed that just after I sent the email but hadn’t had a chance to try it yet.  I pulled that from a YouTube video Ray Auge did way back in 2014 and sort of blindly regurgitated what I saw.

There’s something else I noticed though.  It would seem that it’s still necessary to define
Web-ContextPath .bnd file as it doesn’t appear to work without that.  Is that right?

From: Tim Ward <ti...@paremus.com>
Sent: Monday, October 22, 2018 4:28 PM
To: user@karaf.apache.org
Subject: Re: Http Whiteboard

I’m pretty sure that your ServletContextHelper isn’t advertised as a service and is therefore invisible to the whiteboard. ServletContextHelper is not an interface so you need to be explicit.

Tim
Sent from my iPhone

On 22 Oct 2018, at 23:04, Leschke, Scott <SL...@medline.com>> wrote:

I’ve in the process of trying to convert a couple of servlets over to user HttpWhiteboard. I looked online for an example and it seemed pretty straight forward.
Based on my understanding, I came up with the following but it doesn’t work. Jetty doesn’t have a myApp context. I assume there is something missing?

Help?

Scott


@Component(
       property  = {
              HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME,
              HTTP_WHITEBOARD_CONTEXT_PATH + '=' + ContextHelper.CTX_PATH
       }
)
public class ContextHelper
       extends org.osgi.service.http.context.ServletContextHelper
{
       public static final String CTX_NAME = "myApp";
       public static final String CTX_PATH = '/' + CTX_NAME;
}


@Component(
       name      = “myApp.listings",
       property  = {
              HTTP_WHITEBOARD_CONTEXT_SELECT  + "=(" + HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME + ')',
              HTTP_WHITEBOARD_SERVLET_NAME    + '=' + "MyApp Listings",
              HTTP_WHITEBOARD_SERVLET_PATTERN + '=' + "/list/*"
       },
       service   = Servlet.class,
       immediate = true)
@Designate(
       ocd = AppConfig.class)
public class Listings
       implements HttpServlet
{…}

Re: Http Whiteboard

Posted by Tim Ward <ti...@paremus.com>.
I’m pretty sure that your ServletContextHelper isn’t advertised as a service and is therefore invisible to the whiteboard. ServletContextHelper is not an interface so you need to be explicit. 

Tim

Sent from my iPhone

> On 22 Oct 2018, at 23:04, Leschke, Scott <SL...@medline.com> wrote:
> 
>  
> I’ve in the process of trying to convert a couple of servlets over to user HttpWhiteboard. I looked online for an example and it seemed pretty straight forward.
> Based on my understanding, I came up with the following but it doesn’t work. Jetty doesn’t have a myApp context. I assume there is something missing?
>  
> Help?
>  
> Scott
>  
>  
> @Component(
>        property  = {
>               HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME,
>               HTTP_WHITEBOARD_CONTEXT_PATH + '=' + ContextHelper.CTX_PATH
>        }
> )
> public class ContextHelper
>        extends org.osgi.service.http.context.ServletContextHelper
> {
>        public static final String CTX_NAME = "myApp";
>        public static final String CTX_PATH = '/' + CTX_NAME;
> }
>  
>  
> @Component(
>        name      = “myApp.listings",
>        property  = {
>               HTTP_WHITEBOARD_CONTEXT_SELECT  + "=(" + HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME + ')',
>               HTTP_WHITEBOARD_SERVLET_NAME    + '=' + "MyApp Listings",
>               HTTP_WHITEBOARD_SERVLET_PATTERN + '=' + "/list/*"
>        },
>        service   = Servlet.class,
>        immediate = true)
> @Designate(
>        ocd = AppConfig.class)
> public class Listings
>        implements HttpServlet
> {…}

Re: Http Whiteboard

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Scott,

sorry for the later answer, I was traveling yesterday.

You have an example in the Karaf distribution:

https://github.com/apache/karaf/tree/master/examples/karaf-servlet-example/karaf-servlet-example-annotation

We also have an example in Winegrower:

https://github.com/jbonofre/winegrower/tree/master/winegrower-examples/http

Basically, if you register a Servlet service with name and urlPatterns
as service properties, and you have the http-whiteboard feature
installed, it should work straight forward.

Regards
JB

On 22/10/2018 23:04, Leschke, Scott wrote:
>  
> 
> I’ve in the process of trying to convert a couple of servlets over to
> user HttpWhiteboard. I looked online for an example and it seemed pretty
> straight forward.
> 
> Based on my understanding, I came up with the following but it doesn’t
> work. Jetty doesn’t have a myApp context. I assume there is something
> missing?
> 
>  
> 
> Help?
> 
>  
> 
> Scott
> 
>  
> 
>  
> 
> @Component(
> 
>        property  = {
> 
>               HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME,
> 
>               HTTP_WHITEBOARD_CONTEXT_PATH + '=' + ContextHelper.CTX_PATH
> 
>        }
> 
> )
> 
> public class ContextHelper
> 
>        extends org.osgi.service.http.context.ServletContextHelper
> 
> {
> 
>        public static final String CTX_NAME = "myApp";
> 
>        public static final String CTX_PATH = '/' + CTX_NAME;
> 
> }
> 
>  
> 
>  
> 
> @Component(
> 
>        name      = “myApp.listings",
> 
>        property  = {
> 
>               HTTP_WHITEBOARD_CONTEXT_SELECT  + "=(" +
> HTTP_WHITEBOARD_CONTEXT_NAME + '=' + ContextHelper.CTX_NAME + ')',
> 
>               HTTP_WHITEBOARD_SERVLET_NAME    + '=' + "MyApp Listings",
> 
>               HTTP_WHITEBOARD_SERVLET_PATTERN + '=' + "/list/*"
> 
>        },
> 
>        service   = Servlet.class,
> 
>        immediate = true)
> 
> @Designate(
> 
>        ocd = AppConfig.class)
> 
> public class Listings
> 
>        implements HttpServlet
> 
> {…}
>