Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-7804

Cannot register more than one HTTP proxy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 4.5.0, 4.4.6
    • karaf
    • None

    Description

      When you register more than one proxy into ProxyService, it crashes with the following exception:

       

      org.osgi.service.http.NamespaceException: ServletModel{id=ServletModel-49,name='org.apache.karaf.http.core.internal.proxy.ProxyServlet',alias='/kb',urlPatterns=[/kb/*],servlet=org.apache.karaf.http.core.internal.proxy.ProxyServlet@6bad2ac1,contexts=[
      
      {HS,OCM-48,default,/}]} can't be registered. ServletContextModel\{id=ServletContextModel-2,contextPath='/'} already contains servlet named org.apache.karaf.http.core.internal.proxy.ProxyServlet: ServletModel{id=ServletModel-47,name='org.apache.karaf.http.core.internal.proxy.ProxyServlet',alias='/webconsole',urlPatterns=[/webconsole/*],servlet=org.apache.karaf.http.core.internal.proxy.ProxyServlet@4ce53d9c,contexts=[\{HS,OCM-48,default,/}
      
      ]}
      

       

      The important part: already contains servlet named org.apache.karaf.http.core.internal.proxy.ProxyServlet

       

      This is because servlet-name is not specified when registering a new ProxyServlet into HttpService. So PAX-WEB defaults to the fully qualified class name, as specified in HTTP whiteboard spec section 140.4. (https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard-i21223311). But the class name is the same for subsequent Servlets, so there is a conflict.

      This is also easy to see when you modify org.apache.karaf.itests.HttpTest.testProxy to register two proxies and check if both are registered:

      @Test
      public void testProxy() throws Exception {
      executeCommand("http:proxy-add /test1 http://karaf.apache.org");
      executeCommand("http:proxy-add /test2 http://karaf.apache.org"); // not added
      
      String output = executeCommand("http:proxy-balancing-list");
      System.out.println(output);
      assertContains("random", output);
      assertContains("round-robin", output);
      
      output = executeCommand("http:proxy-list");
      System.out.println(output);
      assertContains("/test1", output);
      assertContains("/test2", output); // fails
      }
      

       

      Attachments

        Activity

          People

            jbonofre Jean-Baptiste Onofré
            aleksy.wroblewski Aleksy Wróblewski
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: