Moving from web.xml to configuration by code: how to set the Web-ContextPath?

51 views
Skip to first unread message

Steinar Bang

unread,
Apr 30, 2017, 7:08:29 AM4/30/17
to op...@googlegroups.com
I'm in the process of transforming my sample webapp from an OSGi-fied
war to a plain OSGi bundle(*).
https://github.com/steinarb/ukelonn/tree/using-vaadin/ukelonn.bundle

What I've done so far has the webapp working on "/", but I've lost the
"/ukelonn" web-contextpath.

Ie. it used to be http://localhost:8181/ukelonn but is now http://localhost:8181/

Is there a way to bring the web-context path back? Or will the
web-context path only work when using an OSGi-war?

This is what I've done so far:
- Changed the packaging in the POM from "war" to "bundle"
- Removed the following from the bundle config in the POM
- The <_wab> element
- The <Bundle-Classpath> element
- The <Web-ContextPath> element (this is the element that contained
the string I would like to get back)
- Removed bundle:bundle from packaging
- In the bundle activator
- Wait for a WebContainer service, and then:
- create a default HTTP context
- register a Shiro event listener
- register a Shiro filter
- register the VAADIN servlet

For the VAADIN servlet to work, it has to be registered with the path
"/*" (if not it can't fetch its CSS and .js files and images). Ie. I
can't register the servlet as "/ukelonn/*".

This is what I've tried to get the web-contextpath back, and that has
had no effect:
- Create the httpcontext with the ID "ukelonn", ie.
httpContext = webContainer.createDefaultHttpContext("ukelonne");
- Add a context parameter (I have tried "path" as well as
"context-path"):
httpContext = webContainer.createDefaultHttpContext();
Dictionary<String, Object> contextParams = new Hashtable<String, Object>();
contextParams.put("context-path", "ukelonn");
webContainer.setContextParam(contextParams, httpContext);
- Putting the <Web-ContextPath> element back into the bundle config in
the POM


(*) The next step after this will be to invert things and use the
whiteboard pattern. But I would like the registration-by-code way
to work first

Steinar Bang

unread,
Apr 30, 2017, 1:09:52 PM4/30/17
to op...@googlegroups.com
>>>>> Steinar Bang <s...@dod.no>:

> Is there a way to bring the web-context path back? Or will the
> web-context path only work when using an OSGi-war?

It's possible that the web-contextpath only has meaning in the war
extender...?

The value of the Web-ContextPath ends up in the
org.ops4j.pax.web.extender.war.internal.WebApp class and it only used
inside it, as far as I can tell...?

Steinar Bang

unread,
Apr 30, 2017, 3:40:13 PM4/30/17
to op...@googlegroups.com
>>>>> Steinar Bang <s...@dod.no>:

> Ie. it used to be http://localhost:8181/ukelonn but is now http://localhost:8181/

> Is there a way to bring the web-context path back? Or will the
> web-context path only work when using an OSGi-war?
[snip!]
> For the VAADIN servlet to work, it has to be registered with the path
> "/*" (if not it can't fetch its CSS and .js files and images). Ie. I
> can't register the servlet as "/ukelonn/*".

Now I'm back in http://localhost:8181/ukelonn
(and I'm running from a jar OSGi bundle without a web.xml and without
the war layout)
https://github.com/steinarb/ukelonn/tree/using-vaadin/ukelonn.bundle

What I did was register the following paths:
final String registrationPath = "/ukelonn/*";
final String[] urlPatterns = { registrationPath, "/VAADIN/*" };

On my first try I had used "/ukelonn*", "/VAADIN*", and that didn't
work. But putting the * behind a "/" worked.

Achim Nierbeck

unread,
May 1, 2017, 1:06:36 AM5/1/17
to op...@googlegroups.com
Hi, 

you might want to take a look at the whiteboard samples at [1]. 

regards, Achim 



--
--
------------------
OPS4J - http://www.ops4j.org - op...@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

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 

Reply all
Reply to author
Forward
0 new messages