[ 
https://issues.apache.org/jira/browse/KARAF-7774?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17776767#comment-17776767
 ] 

Grzegorz Grzybek commented on KARAF-7774:
-----------------------------------------

Mind that in [Whiteboard 
Specification|https://docs.osgi.org/specification/osgi.cmpn/8.0.0/service.http.whiteboard.html#d0e88397]
 we have:
{quote}
140.2.6 Behavior of the Servlet Context 
getServletContextName() - The name of the {{ServletContextHelper}} provided via 
the {{osgi.http.whiteboard.context.name}} service property. 
{quote}

So Pax Web [implements it 
with|https://github.com/ops4j/org.ops4j.pax.web/blob/web-8.0.22/pax-web-spi/src/main/java/org/ops4j/pax/web/service/spi/servlet/OsgiServletContext.java#L801]:
{code:java}
@Override
public String getServletContextName() {
        return osgiContextModel.getName();
}
{code}

But you are right - it should be {{<display-name>}} when in WAB. And now I [set 
it to 
contextpath|https://github.com/ops4j/org.ops4j.pax.web/blob/web-8.0.22/pax-web-spi/src/main/java/org/ops4j/pax/web/service/spi/model/ServerModel.java#L1341-L1343]:
{code:java}
// do NOT use "default" as the name of the context, so it's NOT matched by
// 
osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=default)
ocm.setName(contextPath);
{code}

I should simply (one of these - I'll check tomorrow):
{noformat}
--- 
a/pax-web-extender-war/src/main/java/org/ops4j/pax/web/extender/war/internal/model/BundleWebApplication.java
+++ 
b/pax-web-extender-war/src/main/java/org/ops4j/pax/web/extender/war/internal/model/BundleWebApplication.java
@@ -1296,6 +1296,9 @@ public class BundleWebApplication {
                // we simply take the allocated (and associated with our bundle 
and our bundle's Web-ContextPath) context
                final OsgiContextModel ocm = allocatedOsgiContextModel;
 
+               ocm.setName(mainWebXml.getName());
+               ocm.setName(mainWebXml.getDisplayName());
+
                ocm.setWab(true);
                ocm.setServiceId(0);
                ocm.setServiceRank(Integer.MAX_VALUE);
{noformat}

> ServletContext.getServletContextName() returns wrong value
> ----------------------------------------------------------
>
>                 Key: KARAF-7774
>                 URL: https://issues.apache.org/jira/browse/KARAF-7774
>             Project: Karaf
>          Issue Type: Bug
>          Components: karaf
>    Affects Versions: 4.4.3
>            Reporter: Amichai Rothman
>            Priority: Major
>
> The ServletContext.getServletContextName() interface javadoc says:
> {noformat}
> Returns the name of this web application corresponding to this ServletContext 
> as specified in the deployment descriptor for this web application by the 
> display-name element.
> {noformat}
> In my app, I drop into karaf's deploy folder a WAB bundle with a web.xml 
> containing only display-name (human-readable string) and listener-class with 
> a ServletContextListener implementation class name. The listener's 
> contextInitialized method is invoked, but 
> event.getServletContext().getServletContextName() returns what appears to be 
> the context path (e.g. "/") instead of the display name.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to