Ok, so I tried deploying  the unmodified Whiteboard extended sample (version 
7.2.14) from 
https://github.com/ops4j/org.ops4j.pax.web/tree/web-7.2.14/samples/whiteboard-extended
 
<https://github.com/ops4j/org.ops4j.pax.web/tree/web-7.2.14/samples/whiteboard-extended>
 in Karaf 4.2.8.
I made sure my jetty xml has the jettyConn1 connection:

        <Call name="addConnector">
                <Arg>
                        <New class="org.eclipse.jetty.server.ServerConnector">
                                <Arg name="server">
                                        <Ref refid="Server" />
                                </Arg>
                                <Arg name="factories">
                                        <Array 
type="org.eclipse.jetty.server.ConnectionFactory">
                                                <Item>
                                                        <New 
class="org.eclipse.jetty.server.HttpConnectionFactory">
                                                                <Arg 
name="config">
                                                                        <Ref 
refid="httpConfig" />
                                                                </Arg>
                                                        </New>
                                                </Item>
                                        </Array>
                                </Arg>
                                <Set name="host">
                                        <Property name="jetty.host" 
default="localhost" />
                                </Set>
                                <Set name="port">
                                        <Property name="jetty.port" 
default="8282" />
                                </Set>
                                <Set name="idleTimeout">
                                        <Property name="http.timeout" 
default="30000" />
                                </Set>
                                <Set name="name">jettyConn1</Set>
                        </New>
                </Arg>
        </Call>

I can see the servlets are deployed:

karaf@root()> http:list                                                         
                                                                                
            
ID  │ Servlet                   │ Servlet-Name                 │ State       │ 
Alias                     │ Url
───┼──────────────────────┼──────────────────────────────┼─────────────┼───────────────────────────┼─
309 │ WhiteboardServlet         │ ServletModel-26              │ Deployed    │ 
/whiteboard               │ [/whiteboard/*]
309 │ WhiteboardServlet         │ ServletModel-28              │ Deployed    │ 
/whiteboard2              │ [/whiteboard2/*]
309 │ WhiteboardServlet         │ ServletModel-30              │ Deployed    │ 
/whiteboard3              │ [/whiteboard3/*]
309 │ WhiteboardServlet         │ ServletModel-32              │ Deployed    │ 
/whiteboard4              │ [/whiteboard4/*]

But Jetty is responding 404 to GET on  http://localhost:8282/whiteboard 
<http://localhost:8282/whiteboard> , same for all other ports.

I see this warning in the log file:

2020-03-10T10:12:07,497 | WARN  | features-3-thread-1 | ContextHandler          
         | 245 - org.eclipse.jetty.util - 9.4.22.v20191022 | ContextHandler 
[localhost, @jettyConn1] has a connector only entry e.g. "@connector" and one 
or more host only entries. 
The host entries will be ignored to match legacy behavior.  To clear this 
warning remove the host entries or update to use at least one host@connector 
syntax entry that will match a host for an specific connector


What does this warning means?
Why is Jetty responding with a 404?


Best regards,
Alex soto




> On Mar 9, 2020, at 4:52 PM, Alex Soto <[email protected]> wrote:
> 
> 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 <http://httpcontext.id/> = admin-jolokia
>  service.bundleid = 38
>  service.id <http://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] 
>> <mailto:[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
>>>  
>>> <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