karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5672) Servlets urls are displayed without the http context path
Date Tue, 20 Mar 2018 16:16:00 GMT

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

ASF GitHub Bot commented on KARAF-5672:
---------------------------------------

gnodet closed pull request #473: [KARAF-5672] Servlets urls are displayed without the http
context path
URL: https://github.com/apache/karaf/pull/473
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/http/src/main/java/org/apache/karaf/http/core/internal/ServletEventHandler.java
b/http/src/main/java/org/apache/karaf/http/core/internal/ServletEventHandler.java
index 21f72536d0..479a0c57fd 100644
--- a/http/src/main/java/org/apache/karaf/http/core/internal/ServletEventHandler.java
+++ b/http/src/main/java/org/apache/karaf/http/core/internal/ServletEventHandler.java
@@ -17,9 +17,9 @@
 package org.apache.karaf.http.core.internal;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.ops4j.pax.web.service.spi.ServletEvent;
@@ -37,7 +37,7 @@ public synchronized void servletEvent(ServletEvent event) {
 	/**
 	 * @return the servletEvents
 	 */
-	public synchronized Collection<ServletEvent> getServletEvents() {
+	public synchronized List<ServletEvent> getServletEvents() {
 		return new ArrayList<>(servletEvents.values());
 	}
 
diff --git a/http/src/main/java/org/apache/karaf/http/core/internal/ServletServiceImpl.java
b/http/src/main/java/org/apache/karaf/http/core/internal/ServletServiceImpl.java
index 2ed842e1c3..59f25490a6 100644
--- a/http/src/main/java/org/apache/karaf/http/core/internal/ServletServiceImpl.java
+++ b/http/src/main/java/org/apache/karaf/http/core/internal/ServletServiceImpl.java
@@ -17,7 +17,7 @@
 package org.apache.karaf.http.core.internal;
 
 import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Comparator;
 import java.util.List;
 
 import javax.servlet.Servlet;
@@ -36,7 +36,9 @@ public ServletServiceImpl(ServletEventHandler servletEventHandler) {
     @Override
     public List<ServletInfo> getServlets() {
         List<ServletInfo> servletInfos = new ArrayList<>();
-        Collection<ServletEvent> events = servletEventHandler.getServletEvents();
+        List<ServletEvent> events = servletEventHandler.getServletEvents();
+        events.sort(Comparator.<ServletEvent>comparingLong(s -> s.getBundle().getBundleId())
+                .thenComparing(ServletEvent::getServletName));
         for (ServletEvent event : events) {
             Servlet servlet = event.getServlet();
             String servletClassName = " ";
@@ -50,16 +52,40 @@ public ServletServiceImpl(ServletEventHandler servletEventHandler) {
                 servletName = servletName.substring(servletName.lastIndexOf(".") + 1, servletName.length());
             }
 
-            String alias = event.getAlias() != null ? event.getAlias() : " ";
+            String alias = event.getAlias();
+            String[] urls = event.getUrlParameter();
+
+            String contextPath = event.getBundle().getHeaders().get("Web-ContextPath");
+            if (contextPath == null) {
+                contextPath = event.getBundle().getHeaders().get("Webapp-Context"); // this
one used by pax-web but is deprecated
+            }
+            if (contextPath != null) {
+                contextPath = contextPath.trim();
+                if (!contextPath.startsWith("/")) {
+                    contextPath = "/" + contextPath;
+                }
+                if (alias != null) {
+                    alias = contextPath + alias;
+                }
+                if (urls != null) {
+                    urls = urls.clone();
+                    for (int i = 0; i < urls.length; i++) {
+                        if (urls[i].startsWith("/")) {
+                            urls[i] = contextPath + urls[i];
+                        } else {
+                            urls[i] = contextPath + "/" + urls[i];
+                        }
+                    }
+                }
+            }
 
-            String[] urls = event.getUrlParameter() != null ? event.getUrlParameter() : new
String[] {""};
             ServletInfo info = new ServletInfo();
             info.setBundleId(event.getBundle().getBundleId());
             info.setName(servletName);
             info.setClassName(servletClassName);
             info.setState(event.getType());
-            info.setAlias(alias);
-            info.setUrls(urls);
+            info.setAlias(alias != null ? alias : " ");
+            info.setUrls(urls != null ? urls : new String[] {""});
             servletInfos.add(info);
         }
         return servletInfos;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Servlets urls are displayed without the http context path
> ---------------------------------------------------------
>
>                 Key: KARAF-5672
>                 URL: https://issues.apache.org/jira/browse/KARAF-5672
>             Project: Karaf
>          Issue Type: Bug
>            Reporter: Guillaume Nodet
>            Assignee: Guillaume Nodet
>            Priority: Major
>             Fix For: 4.2.0
>
>
> Deploying {{webconsole}} and {{hawtio}} features, we see that the servlets are accessible
at {{/hawtio/auth/login}} but only {{/auth/login}} is displayed.
> {code}
> karaf@root()> http:list 
> ID  │ Servlet           │ Servlet-Name             │ State       │ Alias    
          │ Url
> ────┼───────────────────┼──────────────────────────┼─────────────┼─────────────────────┼─────────────────────────────────────────────────────────────
> 111 │                   │ keycloak                 │ Deployed    │          
          │ [/keycloak/*]
> 111 │ JspServletWrapper │ jsp                      │ Deployed    │          
          │ [*.jsp, *.jspx, *.jspf, *.xsp, *.JSP, *.JSPX, *.JSPF, *.XSP]
> 111 │                   │ jolokia-proxy            │ Deployed    │          
          │ [/proxy/*]
> 67  │ ResourceServlet   │ /system/console/res:/res │ Deployed    │ /system/console/res
│ [/system/console/res/*]
> 111 │                   │ login                    │ Deployed    │          
          │ [/auth/login]
> 111 │                   │ jolokia-agent            │ Deployed    │          
          │ [/jolokia/*]
> 111 │                   │ contextFormatter         │ Deployed    │          
          │ [/contextFormatter/*]
> 67  │ KarafOsgiManager  │ ServletModel-19          │ Deployed    │ /system/console
    │ [/system/console/*]
> 111 │ ResourceServlet   │ default                  │ Deployed    │ /        
          │ [/]
> 111 │                   │ maven-source             │ Deployed    │          
          │ [/javadoc/*]
> 111 │                   │ logout                   │ Deployed    │          
          │ [/auth/logout]
> 67  │ KarafOsgiManager  │ ServletModel-7           │ Undeployed  │ /system/console
    │ [/system/console/*]
> 111 │                   │ plugin                   │ Deployed    │          
          │ [/plugin/*]
> 111 │                   │ exportContext            │ Deployed    │          
          │ [/exportContext/*]
> 111 │                   │ user                     │ Deployed    │          
          │ [/user/*]
> karaf@root()> war:list                                                           
                                                                     
> Command not found: war:list
> karaf@root()> web:list
> ID  │ State       │ Web-State   │ Level │ Web-ContextPath │ Name
> ────┼─────────────┼─────────────┼───────┼─────────────────┼───────────────────────────────────────
> 111 │ Active      │ Deployed    │ 80    │ /hawtio         │ hawtio :: Web Console
(2.0.0.SNAPSHOT)
> karaf@root()>                                                                    
                                                                     
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message