You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Cristiano Costantini <cr...@gmail.com> on 2017/03/29 09:10:51 UTC

Best Practices for Web application published by Karaf

Hello all,

which the best practices to publish a web application from Karaf currently
in 2017?

I know that it exists the WebContainer (
https://karaf.apache.org/manual/latest/webcontainer) which supports both
publishing of WABs or WARs to Karaf.

I however see different approaches, used in conjunction with Javascript
frameworks like Angular or Polymer, where the server side logic is reduced
to REST services (no JSP required) which rely simply on the OSGi HTTP
service to serve HTML and JS files.

(one example, I stumbled onto the Openmuc project, it has an Angular
application,
https://github.com/gythialy/openmuc/tree/master/projects/webui/base, which
is published by a regular bundle, its web files are inside the
src/main/resource folder - note: this is a bundle running on felix, does
not need karaf).

I like the second kind of approach and it seems to me more suitable for JS
framework like Polymer which I am studying right now. Also, I've tried the
first approach but it was hard to make it work in Karaf the server side
dependencies we had, so as today, we run our application on a standalone
jetty or glassfish container.

To go back to my initial question, what kind of approach do you recommend?
Are there any recent sample or well made open source project or any maven
archetype to use as starting point reference?

I would like to hear also personal opinions :-)

Thank you very much!
Cristiano

Re: Best Practices for Web application published by Karaf

Posted by Oliver Lietz <ap...@oliverlietz.de>.
On Wednesday 29 March 2017 09:10:51 Cristiano Costantini wrote:
> Hello all,

Hi Cristiano,

> which the best practices to publish a web application from Karaf currently
> in 2017?
> 
> I know that it exists the WebContainer (
> https://karaf.apache.org/manual/latest/webcontainer) which supports both
> publishing of WABs or WARs to Karaf.
> 
> I however see different approaches, used in conjunction with Javascript
> frameworks like Angular or Polymer, where the server side logic is reduced
> to REST services (no JSP required) which rely simply on the OSGi HTTP
> service to serve HTML and JS files.
> 
> (one example, I stumbled onto the Openmuc project, it has an Angular
> application,
> https://github.com/gythialy/openmuc/tree/master/projects/webui/base, which
> is published by a regular bundle, its web files are inside the
> src/main/resource folder - note: this is a bundle running on felix, does
> not need karaf).
> 
> I like the second kind of approach and it seems to me more suitable for JS
> framework like Polymer which I am studying right now. Also, I've tried the
> first approach but it was hard to make it work in Karaf the server side
> dependencies we had, so as today, we run our application on a standalone
> jetty or glassfish container.
> 
> To go back to my initial question, what kind of approach do you recommend?
> Are there any recent sample or well made open source project or any maven
> archetype to use as starting point reference?
> 
> I would like to hear also personal opinions :-)

here is mine: Apache Sling – https://sling.apache.org

Regards,
O.

> Thank you very much!
> Cristiano


Re: Best Practices for Web application published by Karaf

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi,

the Web-ContextPath is a OSGi Header and actually marks a WAR :D
Therefore what Christian just provided is a nice way of using the default
Servlet (Resource-Servlet) to use for static resources.

Another way is to use the following:

@Component(
        service = {Object.class, WhiteboardResource.class}, //
WhiteboardResource only for testing
        property = {
                HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN +
"=/resources",
                HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX +
"=/www"
        }
)
public class WhiteboardResource {
}

details can also be found here: [1]

Or use a Servlet3 annotated Servlet and register it also as a WAB (use the
Web-ContextPath as OSGi header) [2]

@WebServlet(name = "helloWorld", urlPatterns = {"/hello"})
public class HelloWorld extends HttpServlet {
}


Something I haven't tried yet, but which I think could work is to combine
DS and the Servlet3 Annotation:

@Component(service = Servlet.class)
@WebServlet(name = "helloWorld", urlPatterns = {"/hello"})
public class HelloWorld extends HttpServlet {
}


regards, Achim


[1] -
https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/whiteboard-ds/src/main/java/org/ops4j/pax/web/samples/whiteboard/ds/WhiteboardResource.java#L22-L28
[2] -
https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/helloworld-servlet3/src/main/java/org/ops4j/web/samples/helloworld/servlet3/internal/HelloWorld.java#L27-L53

2017-03-30 11:54 GMT+02:00 Christian Schneider <ch...@die-schneider.net>:

> I know Web-ContextPath is implemented by pax-web but I do not know if it
> is part of a standard. I am sure Achim knows this.
>
> Christian
>
> 2017-03-30 11:34 GMT+02:00 Cristiano Costantini <
> cristiano.costantini@gmail.com>:
>
>> Hi All and thank you for your support,
>> the solution suggested by Christian seems to me the simplest at the
>> moment.
>>
>> Where can I find more documentation on how "Web-ContextPath" works?
>> Do "Web-ContextPath" is an OSGi header or is it a Karaf specific header?
>> does it is implemented using some  some sub-project (i.e. Pax Web) ?
>>
>> thank you,
>> Cristiano
>>
>>
>>
>>
>> Il giorno mer 29 mar 2017 alle ore 12:12 Christian Schneider <
>> chris@die-schneider.net> ha scritto:
>>
>>> I used this approach for a small angular UI:
>>> https://github.com/cschneider/Karaf-Tutorial/tree/master/tas
>>> klist-blueprint-cdi/angular-ui
>>>
>>> I just added Web-ContextPath to the Manifest and used the
>>> src/main/resources to deploy the static files.
>>> Web-ContextPath: /tasklist
>>>
>>> Christian
>>>
>>> 2017-03-29 11:10 GMT+02:00 Cristiano Costantini <
>>> cristiano.costantini@gmail.com>:
>>>
>>> Hello all,
>>>
>>> which the best practices to publish a web application from
>>> Karaf currently in 2017?
>>>
>>> I know that it exists the WebContainer (https://karaf.apache.org/manu
>>> al/latest/webcontainer) which supports both publishing of WABs or WARs
>>> to Karaf.
>>>
>>> I however see different approaches, used in conjunction with Javascript
>>> frameworks like Angular or Polymer, where the server side logic is reduced
>>> to REST services (no JSP required) which rely simply on the OSGi HTTP
>>> service to serve HTML and JS files.
>>>
>>> (one example, I stumbled onto the Openmuc project, it has an Angular
>>> application,  https://github.com/gythialy/o
>>> penmuc/tree/master/projects/webui/base, which is published by a regular
>>> bundle, its web files are inside the src/main/resource folder - note: this
>>> is a bundle running on felix, does not need karaf).
>>>
>>> I like the second kind of approach and it seems to me more suitable for
>>> JS framework like Polymer which I am studying right now. Also, I've tried
>>> the first approach but it was hard to make it work in Karaf the server side
>>> dependencies we had, so as today, we run our application on a standalone
>>> jetty or glassfish container.
>>>
>>> To go back to my initial question, what kind of approach do you
>>> recommend?
>>> Are there any recent sample or well made open source project or any
>>> maven archetype to use as starting point reference?
>>>
>>> I would like to hear also personal opinions :-)
>>>
>>> Thank you very much!
>>> Cristiano
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> --
>>> Christian Schneider
>>> http://www.liquid-reality.de
>>> <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de>
>>>
>>> Open Source Architect
>>> http://www.talend.com
>>> <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com>
>>>
>>
>
>
> --
> --
> Christian Schneider
> http://www.liquid-reality.de
> <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de>
>
> Open Source Architect
> http://www.talend.com
> <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com>
>



-- 

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>
Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>

Software Architect / Project Manager / Scrum Master

Re: Best Practices for Web application published by Karaf

Posted by Christian Schneider <ch...@die-schneider.net>.
I know Web-ContextPath is implemented by pax-web but I do not know if it is
part of a standard. I am sure Achim knows this.

Christian

2017-03-30 11:34 GMT+02:00 Cristiano Costantini <
cristiano.costantini@gmail.com>:

> Hi All and thank you for your support,
> the solution suggested by Christian seems to me the simplest at the moment.
>
> Where can I find more documentation on how "Web-ContextPath" works?
> Do "Web-ContextPath" is an OSGi header or is it a Karaf specific header?
> does it is implemented using some  some sub-project (i.e. Pax Web) ?
>
> thank you,
> Cristiano
>
>
>
>
> Il giorno mer 29 mar 2017 alle ore 12:12 Christian Schneider <
> chris@die-schneider.net> ha scritto:
>
>> I used this approach for a small angular UI:
>> https://github.com/cschneider/Karaf-Tutorial/tree/master/
>> tasklist-blueprint-cdi/angular-ui
>>
>> I just added Web-ContextPath to the Manifest and used the
>> src/main/resources to deploy the static files.
>> Web-ContextPath: /tasklist
>>
>> Christian
>>
>> 2017-03-29 11:10 GMT+02:00 Cristiano Costantini <
>> cristiano.costantini@gmail.com>:
>>
>> Hello all,
>>
>> which the best practices to publish a web application from
>> Karaf currently in 2017?
>>
>> I know that it exists the WebContainer (https://karaf.apache.org/
>> manual/latest/webcontainer) which supports both publishing of WABs or
>> WARs to Karaf.
>>
>> I however see different approaches, used in conjunction with Javascript
>> frameworks like Angular or Polymer, where the server side logic is reduced
>> to REST services (no JSP required) which rely simply on the OSGi HTTP
>> service to serve HTML and JS files.
>>
>> (one example, I stumbled onto the Openmuc project, it has an Angular
>> application,  https://github.com/gythialy/openmuc/tree/master/projects/
>> webui/base, which is published by a regular bundle, its web files are
>> inside the src/main/resource folder - note: this is a bundle running on
>> felix, does not need karaf).
>>
>> I like the second kind of approach and it seems to me more suitable for
>> JS framework like Polymer which I am studying right now. Also, I've tried
>> the first approach but it was hard to make it work in Karaf the server side
>> dependencies we had, so as today, we run our application on a standalone
>> jetty or glassfish container.
>>
>> To go back to my initial question, what kind of approach do you
>> recommend?
>> Are there any recent sample or well made open source project or any maven
>> archetype to use as starting point reference?
>>
>> I would like to hear also personal opinions :-)
>>
>> Thank you very much!
>> Cristiano
>>
>>
>>
>>
>>
>>
>>
>> --
>> --
>> Christian Schneider
>> http://www.liquid-reality.de
>> <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de>
>>
>> Open Source Architect
>> http://www.talend.com
>> <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com>
>>
>


-- 
-- 
Christian Schneider
http://www.liquid-reality.de
<https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de>

Open Source Architect
http://www.talend.com
<https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com>

Re: Best Practices for Web application published by Karaf

Posted by Cristiano Costantini <cr...@gmail.com>.
Hi All and thank you for your support,
the solution suggested by Christian seems to me the simplest at the moment.

Where can I find more documentation on how "Web-ContextPath" works?
Do "Web-ContextPath" is an OSGi header or is it a Karaf specific header?
does it is implemented using some  some sub-project (i.e. Pax Web) ?

thank you,
Cristiano




Il giorno mer 29 mar 2017 alle ore 12:12 Christian Schneider <
chris@die-schneider.net> ha scritto:

> I used this approach for a small angular UI:
>
> https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-blueprint-cdi/angular-ui
>
> I just added Web-ContextPath to the Manifest and used the
> src/main/resources to deploy the static files.
> Web-ContextPath: /tasklist
>
> Christian
>
> 2017-03-29 11:10 GMT+02:00 Cristiano Costantini <
> cristiano.costantini@gmail.com>:
>
> Hello all,
>
> which the best practices to publish a web application from Karaf currently
> in 2017?
>
> I know that it exists the WebContainer (
> https://karaf.apache.org/manual/latest/webcontainer) which supports both
> publishing of WABs or WARs to Karaf.
>
> I however see different approaches, used in conjunction with Javascript
> frameworks like Angular or Polymer, where the server side logic is reduced
> to REST services (no JSP required) which rely simply on the OSGi HTTP
> service to serve HTML and JS files.
>
> (one example, I stumbled onto the Openmuc project, it has an Angular
> application,
> https://github.com/gythialy/openmuc/tree/master/projects/webui/base,
> which is published by a regular bundle, its web files are inside the
> src/main/resource folder - note: this is a bundle running on felix, does
> not need karaf).
>
> I like the second kind of approach and it seems to me more suitable for JS
> framework like Polymer which I am studying right now. Also, I've tried the
> first approach but it was hard to make it work in Karaf the server side
> dependencies we had, so as today, we run our application on a standalone
> jetty or glassfish container.
>
> To go back to my initial question, what kind of approach do you recommend?
> Are there any recent sample or well made open source project or any maven
> archetype to use as starting point reference?
>
> I would like to hear also personal opinions :-)
>
> Thank you very much!
> Cristiano
>
>
>
>
>
>
>
> --
> --
> Christian Schneider
> http://www.liquid-reality.de
> <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de>
>
> Open Source Architect
> http://www.talend.com
> <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com>
>

Re: Best Practices for Web application published by Karaf

Posted by Christian Schneider <ch...@die-schneider.net>.
I used this approach for a small angular UI:
https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-blueprint-cdi/angular-ui

I just added Web-ContextPath to the Manifest and used the
src/main/resources to deploy the static files.
Web-ContextPath: /tasklist

Christian

2017-03-29 11:10 GMT+02:00 Cristiano Costantini <
cristiano.costantini@gmail.com>:

> Hello all,
>
> which the best practices to publish a web application from Karaf currently
> in 2017?
>
> I know that it exists the WebContainer (https://karaf.apache.org/
> manual/latest/webcontainer) which supports both publishing of WABs or
> WARs to Karaf.
>
> I however see different approaches, used in conjunction with Javascript
> frameworks like Angular or Polymer, where the server side logic is reduced
> to REST services (no JSP required) which rely simply on the OSGi HTTP
> service to serve HTML and JS files.
>
> (one example, I stumbled onto the Openmuc project, it has an Angular
> application,  https://github.com/gythialy/openmuc/tree/master/projects/
> webui/base, which is published by a regular bundle, its web files are
> inside the src/main/resource folder - note: this is a bundle running on
> felix, does not need karaf).
>
> I like the second kind of approach and it seems to me more suitable for JS
> framework like Polymer which I am studying right now. Also, I've tried the
> first approach but it was hard to make it work in Karaf the server side
> dependencies we had, so as today, we run our application on a standalone
> jetty or glassfish container.
>
> To go back to my initial question, what kind of approach do you recommend?
> Are there any recent sample or well made open source project or any maven
> archetype to use as starting point reference?
>
> I would like to hear also personal opinions :-)
>
> Thank you very much!
> Cristiano
>
>
>
>



-- 
-- 
Christian Schneider
http://www.liquid-reality.de
<https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de>

Open Source Architect
http://www.talend.com
<https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com>

Re: Best Practices for Web application published by Karaf

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi Cristiano,

as with any Web Container, you can use any approach you like.
Actually you have much more approaches you can use.

For example if you just want a JS/REST frontend, register your REST servlet
as a Servlet Service, Pax Web will pick it up.
That's the Whiteboard approach. As with Karaf 4.1.x and Pax Web 6.x you
have not only the Pax-Web Whiteboard Extension mechanism, but also the
OSGi spec compliant one. So you don't end up in a "vendor" lock in.
Another approach is to actually just register your annotated servlet as
Service, with that you have the least OSGi "overhead".

So actually the webcontainer of Pax Web isn't only about WARs and WABs.

BTW. you can also register JSPs etc. via the Whiteboard Approach, but that
is a Pax Web speciality ;)

regards, Achim





2017-03-29 11:10 GMT+02:00 Cristiano Costantini <
cristiano.costantini@gmail.com>:

> Hello all,
>
> which the best practices to publish a web application from Karaf currently
> in 2017?
>
> I know that it exists the WebContainer (https://karaf.apache.org/
> manual/latest/webcontainer) which supports both publishing of WABs or
> WARs to Karaf.
>
> I however see different approaches, used in conjunction with Javascript
> frameworks like Angular or Polymer, where the server side logic is reduced
> to REST services (no JSP required) which rely simply on the OSGi HTTP
> service to serve HTML and JS files.
>
> (one example, I stumbled onto the Openmuc project, it has an Angular
> application,  https://github.com/gythialy/openmuc/tree/master/projects/
> webui/base, which is published by a regular bundle, its web files are
> inside the src/main/resource folder - note: this is a bundle running on
> felix, does not need karaf).
>
> I like the second kind of approach and it seems to me more suitable for JS
> framework like Polymer which I am studying right now. Also, I've tried the
> first approach but it was hard to make it work in Karaf the server side
> dependencies we had, so as today, we run our application on a standalone
> jetty or glassfish container.
>
> To go back to my initial question, what kind of approach do you recommend?
> Are there any recent sample or well made open source project or any maven
> archetype to use as starting point reference?
>
> I would like to hear also personal opinions :-)
>
> Thank you very much!
> Cristiano
>
>
>
>



-- 

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>
Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>

Software Architect / Project Manager / Scrum Master