You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Gražvydas Valeika <gv...@gmail.com> on 2013/05/07 12:03:32 UTC

Is it possible to override OSGi headers for war?

Hi all,

I'm new to karaf, tried to look at archives but failed to find answer,
sorry if this is kind of faq.

I'm trying to use same war to deploy multiple instances of web application.

So far I succeeded to deploy not-OSGi-fied war file into karaf war feature
using 'install webbundle':

install
webbundle:file:///myApp.war?Bundle-SymbolicName=myApp2&Webapp-Context=/myApp2
install
webbundle:file:///myApp.war?Bundle-SymbolicName=myApp3&Webapp-Context=/myApp3

etc.

This has annoying requirement to put all possible headers into url
parameters.

I also noticed on google that command like:

install war:file:///myApp.war?Webapp-Context=/myApp3

is discussed, and, maybe, worked some time ago in I don't know what version
of karaf.


Is it possible to use OSGi-fied war in such way - use all preconfigured
MANIFEST.MF headers and override only some of them in install url
parameters?

in http://wiki.eclipse.org/Jetty/Feature/Jetty_OSGi#.22war.22_URL_scheme I
found

'The support for this protocol is mostly complete. The query string
parameters that enable overriding the manifest headers and other settings
have not been extensively tested.'

I'm doing it wrong way, or this feature is not supported?


Best regards,
Grazvydas

Re: Is it possible to override OSGi headers for war?

Posted by Gražvydas Valeika <gv...@gmail.com>.
Hi,

On Wed, May 8, 2013 at 9:39 AM, Achim Nierbeck <bc...@googlemail.com>wrote:

> Well if you take a look at the OSGi spec it is allowed only to alter the
> WebApp-Context for a WAB and that's what actually is working, all other
> Manifest entries need to be kept the way they are specified in the
> Manifest. Therefore it works as specified/designed.
> And my personal opinion as the Bundle-SymbolicName is something to
> identify a Bundle with it shouldn't be even thought of changing the
> Bundle-SymbolicName or something the like, it's the same for the Maven
> location it has to be unique.
> If you require to run the same bundle twice, either install two different
> versions of it, or create two seperate Bundles with each having a unique
> Maven location.
>
>
Solution found. Thank you for your time.

According OSGi Service Platform Core Specification (The OSGi Alliance
Release 4, Version 4.3 April 2011):

The bundle symbolic name and bundle version identify a unique bundle. This
does not always imply that this pair is unique in a framework, in certain
cases the same bundle can be installed multiple times in the same framework.

And:

Bundle Symbolic Name and Bundle Version– A name and version assigned by the
developer. The combination of Bundle Version and Bundle Symbolic Name is a
globally unique identifier for a bundle. The getSymbolicName() method
returns the assigned bundle name. The Bundle getVersion() method returns
the version. Though the pair is unique, it is possible to install the same
bundle multiple times if the org.osgi.framework.bsnversion framework
launching property is set to multiple.

I tried to set karaf configuration (in config.properties):

org.osgi.framework.bsnversion=multiple

and it worked. It now allows to install same WAB multiple times and create
side by side web applications using different Web-ContextPath.

Best regards,

Grazvydas

Re: Is it possible to override OSGi headers for war?

Posted by Achim Nierbeck <bc...@googlemail.com>.
Well if you take a look at the OSGi spec it is allowed only to alter the
WebApp-Context for a WAB and that's what actually is working, all other
Manifest entries need to be kept the way they are specified in the
Manifest. Therefore it works as specified/designed.
And my personal opinion as the Bundle-SymbolicName is something to identify
a Bundle with it shouldn't be even thought of changing the
Bundle-SymbolicName or something the like, it's the same for the Maven
location it has to be unique.
If you require to run the same bundle twice, either install two different
versions of it, or create two seperate Bundles with each having a unique
Maven location.

regards, Achim



2013/5/8 Gražvydas Valeika <gv...@gmail.com>

> Hi,
>
> Ensure you have a quote for the 'webbundle:path…'
>> Something like
>> install -s
>> 'webbundle:file:///home/gv/work/experiments/ttt/CamelTest/target/CamelTest.wab?Web-ContextPath=/CT222&Bundle-SymbolicName=CamelTestSymbolicName2'
>>
>> doesn't help. Doesn't work with
> '&Bundle-SymbolicName=CamelTestSymbolicName2' part and works without it.
> Causes the same exception.
>
> G.
>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
Commiter & Project Lead
blog <http://notizblog.nierbeck.de/>

Re: Is it possible to override OSGi headers for war?

Posted by Gražvydas Valeika <gv...@gmail.com>.
Hi,

Ensure you have a quote for the 'webbundle:path…'
> Something like
> install -s
> 'webbundle:file:///home/gv/work/experiments/ttt/CamelTest/target/CamelTest.wab?Web-ContextPath=/CT222&Bundle-SymbolicName=CamelTestSymbolicName2'
>
> doesn't help. Doesn't work with
'&Bundle-SymbolicName=CamelTestSymbolicName2' part and works without it.
Causes the same exception.

G.

Re: Is it possible to override OSGi headers for war?

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

Ensure you have a quote for the 'webbundle:path…'
Something like
install -s 'webbundle:file:///home/gv/work/experiments/ttt/CamelTest/target/CamelTest.wab?Web-ContextPath=/CT222&Bundle-SymbolicName=CamelTestSymbolicName2'
-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: @Freeman小屋

On 2013-5-8, at 下午1:46, Gražvydas Valeika wrote:

> Hi,
> 
> ok, one step further. Now I can define Web-ContextPath in install url.
> 
> But this doesn't allow to define Bundle-SymbolicName in the install url and because of this (not unique symbolic name) I can't deploy 2 web applications side by side. It says: 
> 
> 2013-05-08 08:33:16,183 | INFO  | e ssh user karaf | ShellUtil                        | 48 - org.apache.karaf.shell.console - 3.0.0.RC1 | Exception caught while executing command
> org.apache.karaf.shell.console.MultiException: Error installing bundles:
> 	Unable to install bundle webbundle:file:///home/gv/work/experiments/ttt/CamelTest/target/CamelTest.wab?Web-ContextPath=/CT222&Bundle-SymbolicName=CamelTestSymbolicName2
>  ...
> Caused by: java.net.MalformedURLException: The webbundle URL handler can not be used with bundles
> 	at org.ops4j.pax.url.war.internal.WebBundleConnection.createBundle(WebBundleConnection.java:82)
> 	at org.ops4j.pax.url.war.internal.AbstractConnection.getInputStream(AbstractConnection.java:143)
> ...
> 
> Any workaround for this?
> 
> Best regards,
> 
> Grazvydas
> 
> 


Re: Is it possible to override OSGi headers for war?

Posted by Gražvydas Valeika <gv...@gmail.com>.
Hi,

ok, one step further. Now I can define Web-ContextPath in install url.

But this doesn't allow to define Bundle-SymbolicName in the install url and
because of this (not unique symbolic name) I can't deploy 2 web
applications side by side. It says:

2013-05-08 08:33:16,183 | INFO  | e ssh user karaf | ShellUtil
           | 48 - org.apache.karaf.shell.console - 3.0.0.RC1 | Exception
caught while executing command
org.apache.karaf.shell.console.MultiException: Error installing bundles:
Unable to install bundle
webbundle:file:///home/gv/work/experiments/ttt/CamelTest/target/CamelTest.wab?Web-ContextPath=/CT222&Bundle-SymbolicName=CamelTestSymbolicName2
 ...
Caused by: java.net.MalformedURLException: The webbundle URL handler can
not be used with bundles
at
org.ops4j.pax.url.war.internal.WebBundleConnection.createBundle(WebBundleConnection.java:82)
at
org.ops4j.pax.url.war.internal.AbstractConnection.getInputStream(AbstractConnection.java:143)
...

Any workaround for this?

Best regards,

Grazvydas

Re: Is it possible to override OSGi headers for war?

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

added some comments to the issue,
even though you're deploying a WAB you need to add the webbundle -
urlHandler to it and add your desired WebApp-Context to it. It'll do a
repackaging of the war with a new manifest.
Regards, Achim




2013/5/7 Achim Nierbeck <bc...@googlemail.com>

> Ok, thanks, gonna see to it :)
> regards, Achim
>
>
> 2013/5/7 Gražvydas Valeika <gv...@gmail.com>
>
>>
>> install -s mvn:groupId/artifactId/version/war?WebApp-Context=/webApp
>>>
>>> Did you test this already?
>>>
>>
>> Yes, tested on apache-karaf-3.0.0.RC1, apache-servicemix-4.5.0,
>> fuse-esb-7.1.0.fuse-047. Doesn't work everywhere.
>>
>>
>>> If it doesn't work, plz open a issue at either pax-web or pax-url-web
>>> cause in this case it's a bug :-)
>>>
>>> Done, PAXWEB-564 <https://ops4j1.jira.com/browse/PAXWEB-564>.
>>
>> Best regards,
>>
>> Grazvydas
>>
>
>
>
> --
>
> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
> Project Lead
> OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
> Commiter & Project Lead
> blog <http://notizblog.nierbeck.de/>
>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
Commiter & Project Lead
blog <http://notizblog.nierbeck.de/>

Re: Is it possible to override OSGi headers for war?

Posted by Achim Nierbeck <bc...@googlemail.com>.
Ok, thanks, gonna see to it :)
regards, Achim


2013/5/7 Gražvydas Valeika <gv...@gmail.com>

>
> install -s mvn:groupId/artifactId/version/war?WebApp-Context=/webApp
>>
>> Did you test this already?
>>
>
> Yes, tested on apache-karaf-3.0.0.RC1, apache-servicemix-4.5.0,
> fuse-esb-7.1.0.fuse-047. Doesn't work everywhere.
>
>
>> If it doesn't work, plz open a issue at either pax-web or pax-url-web
>> cause in this case it's a bug :-)
>>
>> Done, PAXWEB-564 <https://ops4j1.jira.com/browse/PAXWEB-564>.
>
> Best regards,
>
> Grazvydas
>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
Commiter & Project Lead
blog <http://notizblog.nierbeck.de/>

Re: Is it possible to override OSGi headers for war?

Posted by Gražvydas Valeika <gv...@gmail.com>.
> install -s mvn:groupId/artifactId/version/war?WebApp-Context=/webApp
>
> Did you test this already?
>

Yes, tested on apache-karaf-3.0.0.RC1, apache-servicemix-4.5.0,
fuse-esb-7.1.0.fuse-047. Doesn't work everywhere.


> If it doesn't work, plz open a issue at either pax-web or pax-url-web
> cause in this case it's a bug :-)
>
> Done, PAXWEB-564 <https://ops4j1.jira.com/browse/PAXWEB-564>.

Best regards,

Grazvydas

Re: Is it possible to override OSGi headers for war?

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hmm, ok got me there, it's been quite a while since I looked at it, sorry
:-)

Well if it's in the spec it should work already, afaik Pax-Web has once
been tested if it matches the TCK.
So you might just install it by using:

install -s mvn:groupId/artifactId/version/war?WebApp-Context=/webApp

Did you test this already?
If it doesn't work, plz open a issue at either pax-web or pax-url-web cause
in this case it's a bug :-)

Regards, Achim


2013/5/7 Gražvydas Valeika <gv...@gmail.com>

> As I mentioned earlier I'm completely new to osgi/karaf. So my confidence
> level is not enough to contribute much ;)
> You said that it's not backed by the OSGi spec.
>
> As I read:
> http://www.osgi.org/download/osgi-4.2-early-draft3.pdf
> (RFC 66 - OSGi and Web Applications Page 11 of 19 Draft March 6, 2009)
>
> 5.2.1.1 WAR manifest processing
> An implementation must register a URL handler for processing
> implementation specific WAR URLs. When a
> deployer invokes installBundle to install WARs using the URL generated by
> createWarURL method, the
> URL handler gets control, and examines the input URL and adds several
> manifest entries on the fly based
> deployer specified options. The URL handler uses the following while
> computing manifest header values:
> • WAR file manifest entries – developer defaults
> • Properties supplied by deployer via install URL (e.g., query string) -
> deployer defaults
> • Compute based on additional criteria, e.g., other artifacts in the
> archive.
> The WAR manifest headers are modified as described below:
> ...
> 3. Bundle-SymbolicName: Required
> If Constants.Bundle_SymbolicName deployer option is specified in the URL,
> it will be used. All Page within this Box
> Otherwise, if Bundle-SymbolicName header already exists in the manifest,
> it will be preserved.
> ...
> 7. Web-ContextPath: Optional
> Specifies the context path of the web application.
> If WebContainer.Web_ContextPath deployer option is specified, it will be
> used.
> Otherwise, if the header exists in the manifest, it will be preserved.
> Otherwise, if WebContainer.Web_ContextPath deployer default option is
> specified in the URL, it
> will be used.
> Otherwise, a unique context path value is derived in implementation
> specific ways.
>
>
> Or I totally missed context?
>
>
> Grazvydas
>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
Commiter & Project Lead
blog <http://notizblog.nierbeck.de/>

Re: Is it possible to override OSGi headers for war?

Posted by Gražvydas Valeika <gv...@gmail.com>.
As I mentioned earlier I'm completely new to osgi/karaf. So my confidence
level is not enough to contribute much ;)
You said that it's not backed by the OSGi spec.

As I read:
http://www.osgi.org/download/osgi-4.2-early-draft3.pdf
(RFC 66 - OSGi and Web Applications Page 11 of 19 Draft March 6, 2009)

5.2.1.1 WAR manifest processing
An implementation must register a URL handler for processing implementation
specific WAR URLs. When a
deployer invokes installBundle to install WARs using the URL generated by
createWarURL method, the
URL handler gets control, and examines the input URL and adds several
manifest entries on the fly based
deployer specified options. The URL handler uses the following while
computing manifest header values:
• WAR file manifest entries – developer defaults
• Properties supplied by deployer via install URL (e.g., query string) -
deployer defaults
• Compute based on additional criteria, e.g., other artifacts in the
archive.
The WAR manifest headers are modified as described below:
...
3. Bundle-SymbolicName: Required
If Constants.Bundle_SymbolicName deployer option is specified in the URL,
it will be used. All Page within this Box
Otherwise, if Bundle-SymbolicName header already exists in the manifest, it
will be preserved.
...
7. Web-ContextPath: Optional
Specifies the context path of the web application.
If WebContainer.Web_ContextPath deployer option is specified, it will be
used.
Otherwise, if the header exists in the manifest, it will be preserved.
Otherwise, if WebContainer.Web_ContextPath deployer default option is
specified in the URL, it
will be used.
Otherwise, a unique context path value is derived in implementation
specific ways.


Or I totally missed context?


Grazvydas

Re: Is it possible to override OSGi headers for war?

Posted by Achim Nierbeck <bc...@googlemail.com>.
Well, it's not backed by the OSGi spec to do so :-)
If you really need it, open a issue either at Karaf/Pax-Web or Pax-Url
(it's the actual URL-handler) and maybe provide some contribution ;)
That's the most easiest way of getting rid of disappointments.

regards, Achim


2013/5/7 Gražvydas Valeika <gv...@gmail.com>

> Hi,
>
> On Tue, May 7, 2013 at 2:45 PM, Achim Nierbeck <bc...@googlemail.com>wrote:
>
>>
>> well if you don't have an osgi-war and want to deploy it, you either need
>> to add the Webapp-Context yourself or the deployer does it for you :) if
>> not given, so regarding this you are doing everything right. The war:
>> url-handler is equivalent to webbundle: though webbundle is the official
>> OSGi spec conforming url-handler for non-osgi wars.
>> If you want to deploy a osgi-fied war you just need to install it as
>> install -s file://location/blubb.war or better from a maven repo install -s
>> mvn:groupId/artifactId/version/war. It's that easy. Btw. Karaf uses Pax-Web
>> as sophisticated OSGi Web-Container, which again uses Jetty as serving
>> container. For more information of Pax-Web take a look at [1].
>>
>
> Osgi-fied war deployment works.
> My wish is to override *Bundle-SymbolicName *and* **Web-ContextPath *defined
> in MANIFEST.MF at install time.
> As I understand, this is not possible? Little bit dissapointing, because
> while installing not-osgi-fied war this can be done using url parameters.
>
>
> Thanks,
>
> G.
>
>


-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
Commiter & Project Lead
blog <http://notizblog.nierbeck.de/>

Re: Is it possible to override OSGi headers for war?

Posted by Gražvydas Valeika <gv...@gmail.com>.
Hi,

On Tue, May 7, 2013 at 2:45 PM, Achim Nierbeck <bc...@googlemail.com>wrote:

>
> well if you don't have an osgi-war and want to deploy it, you either need
> to add the Webapp-Context yourself or the deployer does it for you :) if
> not given, so regarding this you are doing everything right. The war:
> url-handler is equivalent to webbundle: though webbundle is the official
> OSGi spec conforming url-handler for non-osgi wars.
> If you want to deploy a osgi-fied war you just need to install it as
> install -s file://location/blubb.war or better from a maven repo install -s
> mvn:groupId/artifactId/version/war. It's that easy. Btw. Karaf uses Pax-Web
> as sophisticated OSGi Web-Container, which again uses Jetty as serving
> container. For more information of Pax-Web take a look at [1].
>

Osgi-fied war deployment works.
My wish is to override *Bundle-SymbolicName *and* **Web-ContextPath *defined
in MANIFEST.MF at install time.
As I understand, this is not possible? Little bit dissapointing, because
while installing not-osgi-fied war this can be done using url parameters.


Thanks,

G.

Re: Is it possible to override OSGi headers for war?

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

well if you don't have an osgi-war and want to deploy it, you either need
to add the Webapp-Context yourself or the deployer does it for you :) if
not given, so regarding this you are doing everything right. The war:
url-handler is equivalent to webbundle: though webbundle is the official
OSGi spec conforming url-handler for non-osgi wars.
If you want to deploy a osgi-fied war you just need to install it as
install -s file://location/blubb.war or better from a maven repo install -s
mvn:groupId/artifactId/version/war. It's that easy. Btw. Karaf uses Pax-Web
as sophisticated OSGi Web-Container, which again uses Jetty as serving
container. For more information of Pax-Web take a look at [1].

regards, Achim

[1] - https://ops4j1.jira.com/wiki/display/paxweb/Pax+Web



2013/5/7 Gražvydas Valeika <gv...@gmail.com>

> Hi all,
>
> I'm new to karaf, tried to look at archives but failed to find answer,
> sorry if this is kind of faq.
>
> I'm trying to use same war to deploy multiple instances of web application.
>
> So far I succeeded to deploy not-OSGi-fied war file into karaf war feature
> using 'install webbundle':
>
> install
> webbundle:file:///myApp.war?Bundle-SymbolicName=myApp2&Webapp-Context=/myApp2
> install
> webbundle:file:///myApp.war?Bundle-SymbolicName=myApp3&Webapp-Context=/myApp3
>
> etc.
>
> This has annoying requirement to put all possible headers into url
> parameters.
>
> I also noticed on google that command like:
>
> install war:file:///myApp.war?Webapp-Context=/myApp3
>
> is discussed, and, maybe, worked some time ago in I don't know what
> version of karaf.
>
>
> Is it possible to use OSGi-fied war in such way - use all preconfigured
> MANIFEST.MF headers and override only some of them in install url
> parameters?
>
> in http://wiki.eclipse.org/Jetty/Feature/Jetty_OSGi#.22war.22_URL_scheme I
> found
>
> 'The support for this protocol is mostly complete. The query string
> parameters that enable overriding the manifest headers and other settings
> have not been extensively tested.'
>
> I'm doing it wrong way, or this feature is not supported?
>
>
> Best regards,
> Grazvydas
>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
Commiter & Project Lead
blog <http://notizblog.nierbeck.de/>