Well, this is not working for me.  Following the provided example, I am 
registering the servlet:

public class Activator implements BundleActivator {

        private static final String ID = "admin-jolokia";
        private static final String PATH = "/jolokia";
        private ServiceRegistration<HttpContextMapping> httpContextMappingReg;
        private ServiceRegistration<Servlet> servletReg;

        @Override
        public void start(final BundleContext bundleContext) throws Exception {
                Dictionary<String, String> props = new Hashtable<>();
                props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, ID);

                HashMap<String, String> contextMappingParams = new HashMap<>();
                
contextMappingParams.put(ExtenderConstants.PROPERTY_HTTP_CONNECTORS, 
"internalConnector");

                httpContextMappingReg = bundleContext.registerService(
                                HttpContextMapping.class, new 
WhiteboardHttpContextMapping(
                                                ID,
                                                PATH,
                                                contextMappingParams),
                                props);

                props = new Hashtable<>();
                props.put(ExtenderConstants.PROPERTY_ALIAS, PATH);
                props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, ID);
                props.put(WebContainerConstants.SERVLET_NAME, "JolokiaServlet");
                servletReg = bundleContext.registerService(Servlet.class, new 
JolokiaServlet(bundleContext), props);
        }

        @Override
        public void stop(BundleContext bundleContext) throws Exception {
                if (servletReg != null) {
                        servletReg.unregister();
                        servletReg = null;
                }
                if (httpContextMappingReg != null) {
                        httpContextMappingReg.unregister();
                        httpContextMappingReg = null;
                }
        }
}

To avoid automatic registration by Jolokia, I configure Jolokia to not register 
the Servlet:

                <config name="org.jolokia.osgi">
                        org.jolokia.realm=karaf
                        org.jolokia.listenForHttpService=false
                </config>

The servlet appears to be registered:


karaf@root()> service:list Servlet
[javax.servlet.Servlet]
-----------------------
 alias = /jolokia
 httpContext.id = admin-jolokia
 service.bundleid = 38
 service.id = 379
 service.scope = singleton
 servlet-name = JolokiaServlet
Provided by : 
 EncryptedQuery :: Responder :: Admin (38)
Used by: 
 OPS4J Pax Web - Extender - Whiteboard (317)


And:

karaf@root()> http:list
ID  │ Servlet                   │ Servlet-Name                 │ State       │ 
Alias                     │ Url
────┼───────────────────────────┼──────────────────────────────┼─────────────┼───────────────────────────┼─
38  │ JolokiaServlet            │ JolokiaServlet               │ Deployed    │ 
/jolokia                  │ [/jolokia/*]


However, a GET request always returns error 404 in all ports.
If I remove the configuration and the Activator, then Jolokia is bound to all 
interfaces, but the it is not prompting for authentication. 

Any ideas about what I may be doing wrong?

Best regards,
Alex soto




> On Feb 4, 2020, at 6:17 AM, Markus Rathgeb <[email protected]> wrote:
> 
> Hi all,
> 
> the both examples and its mechanism differs (thanks for providing it).
> 
> The one JB refers to is using a bundle header. This example has (the
> time I tested it) not worked for me. My research (at the time I
> comment this the first time) has been that this works for the usage of
> the "Web Application Specification" only. I did not check it again,
> but I was not aware that something has been changed.
> 
> The one Achim refers to uses a HttpContextMapping service additional
> to the Servlet service and sets the necessary properties.
> Achim, thanks a lot for your example. This one is working for me!
> 
>> https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/whiteboard-extended/src/main/java/org/ops4j/pax/web/extender/samples/whiteboard/internal/Activator.java
> 
> As it is only an example, it does not matter, but there is a bug in
> this example.
> All the http context mapping service registrations are assigned to
> "httpContextMappingReg" and all servlet registrations to "servletReg".
> The respective ...2 and ...3 variables are not used.
> So, there is only one of each service unregistered and freed.
> 
> Best regards,
> Markus

Reply via email to