Hello

If you need only static resources, maybe you should simply register
Whiteboard-based resources? Something like this:

register a context to "get" a context path:

Dictionary<String, Object> properties = new Hashtable<>();
properties.put("osgi.http.whiteboard.context.name", "my-context");
properties.put("osgi.http.whiteboard.context.path", "/sample");

ServiceRegistration<ServletContextHelper> reg =
context.registerService(ServletContextHelper.class, new
ServletContextHelper() {}, properties);

register resources into this context path:

Dictionary<String, Object> properties = new Hashtable<>();
properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN,
new String[] { "/static/*" });
properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX,
"/resources");
properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
String.format("(%s=my-context)",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME));

ServiceRegistration<Object> resReg = context.registerService(Object.class,
new Object(), properties);

Then you'll be able to get resources from bundle's "/resources" directory
using URI's like "/sample/static/*"

But sure - your WAR approach should work too.

regards
Grzegorz Grzybek

pon., 13 lut 2023 o 04:49 Andrew Lienhard <andrew.lienh...@gmail.com>
napisaƂ(a):

> This seems to be the most promising approach. Repackage the WAB as a WAR
> then deploy it at runtime as shown below. The URL parameters will assist
> the OSGI Web URL Handler in automagically producing a WAB + MANIFEST.MF
> with the correct web-contextpath header. Only I need to do it using the
> bundleContext.installBundle(String location) API instead of in the console.
> I also need to sort out the URL of the built war itself. Does this sound
> correct?
>
>
>
> karaf@root()> bundle:install -s "webbundle:
> http://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war?Bundle-SymbolicName=tomcat-sample&Web-ContextPath=/sample
> "
>
>
>
> From <https://karaf.apache.org/manual/latest/webcontainer>
>
>
> https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.war.html#i3100445
>
>
>
>
>
>
> On Sun, Feb 12, 2023 at 4:29 PM Andrew Lienhard <alienh...@gmail.com>
> wrote:
>
>> I have a WAB in a karaf container that I need to deploy using a context
>> path based on environment variables (k8s helm). Currently its
>> web-ContextPath is hardcoded in a pom.xml, so it's compile-time only which
>> won't work for our deployments.
>>
>> I'm wondering if it's possible to register this WAB dynamically as one
>> would a servlet using HttpService and/or pax-web. I've been digging through
>> the documentation and examples but so far I haven't been able to work it
>> out. Is this doable? If so, are there any examples of this? Ultimately, I
>> don't care what form the service takes as long as it can serve static files
>> from a directory.
>>
>> clip from the pom.xml
>>       <plugin>
>>                 <groupId>org.apache.felix</groupId>
>>                 <artifactId>maven-bundle-plugin</artifactId>
>>                 <extensions>true</extensions>
>>                 <configuration>
>>                     <instructions>
>>                         <_wab>src/main/webapp</_wab>
>>
>> <Include-Resource>{maven-resources},OSGI-INF/blueprint/blueprint.xml=${project.build.directory}/classes/OSGI-INF/blueprint/blueprint.xml</Include-Resource>
>>
>> <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
>>                         <Embed-Directory>WEB-INF/lib</Embed-Directory>
>>                         <Web-ContextPath>/</Web-ContextPath>
>>                     </instructions>
>>                 </configuration>
>>             </plugin>
>>
>> --
>> --
>> ------------------
>> 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/2e75aacf-be77-4753-a05c-126df2b7f487n%40googlegroups.com
>> <https://groups.google.com/d/msgid/ops4j/2e75aacf-be77-4753-a05c-126df2b7f487n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> --
> ------------------
> 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/CADGfNtp_02pRaMrG7Oj0wJuYKA3O3p0QS6DHa3XSChA0qJNUFA%40mail.gmail.com
> <https://groups.google.com/d/msgid/ops4j/CADGfNtp_02pRaMrG7Oj0wJuYKA3O3p0QS6DHa3XSChA0qJNUFA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
-- 
------------------
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/CAAdXmhpzREW99MVkkyXxg8Bt8Owsyp-iYY26n%2BeiG3F4BEn_eg%40mail.gmail.com.

Reply via email to