Ok, they have different class loaders :(

The Activator has a ContentClassLoader
and the HTTPService the WebAppClassLoader

But, I'm still lost on how to solve this :(

On Tue, Jan 20, 2009 at 10:33 AM, Vinicius Carvalho <
[email protected]> wrote:

> Well digging a little bit more, I found this:
>
> I'm putting the equinox servlet as a bundle: so the class:
>
> org.eclipse.equinox.http.servlet.internal.Activator gets started:
> public void start(BundleContext context) throws Exception {
>         startHttpServiceProxy(context);
>     }
> private static synchronized void startHttpServiceProxy(BundleContext
> bundleContext) {
>         context = bundleContext;
>         Object[] proxyServlets = serviceRegistrations.keySet().toArray();
>         for (int i = 0; i < proxyServlets.length; ++i) {
>             ServiceRegistration registration =
> registerHttpService((ProxyServlet) proxyServlets[i]);
>             serviceRegistrations.put(proxyServlets[i], registration);
>         }
>     }
>
> Well it assigns the bundlecontext to its internal variable, so far so good.
> Problem is when I create the HTTPProxyServlet:
>
>         this.delegatee = new HttpServiceServlet();
>         this.delegatee.init(getServletConfig());
>
> And it gets initiated:
>
> public void init(ServletConfig config) throws ServletException {
>         super.init(config);
>         proxyContext = new ProxyContext(config.getServletContext());
>         Activator.addProxyServlet(this);
>     }
>
> The Activator is called in a static way, the addProxyServlet methods checks
> for a bundlecontext which is null :(, so it never calls the
> registerHttpService, which in turns never triggers the Tracker from the
> webconsole.
>
> Anyone got a solution for this please?
>
> Regards
>
>
>
>
> On Mon, Jan 19, 2009 at 6:48 PM, Vinicius Carvalho <
> [email protected]> wrote:
>
>> Well, I fixed the project a bit, removed the servlet-api and add a
>> property org.osgi.framework.system.packages.extra = javax.servlet,
>> javax.servlet.http to Felix startup properties.
>>
>> But still no success. So I decided to go to the source code.
>>
>> Well, it seems that the webconsole service tracker HttpServiceTracker
>> never gets its addingService method called. So it does not bind itself.
>>
>> One thing I found my self lost (again) is that the Sling implementation
>> starts an HttpService, what about the HttpServiceImpl which register the
>> proxy servlet? Isn't this one the one to be instantiated?
>>
>> Regards
>>
>>
>> On Fri, Jan 16, 2009 at 4:53 PM, Felix Meschberger <[email protected]>wrote:
>>
>>> Hi Vinicius,
>>>
>>> Vinicius Carvalho schrieb:
>>> > Well, still can't get it to work :(
>>>
>>> To bad ...
>>>
>>> >
>>> > Here's my web structure:
>>> >
>>> > web-inf/
>>> >   -web.xml
>>> >   -lib/
>>> >     org.apache.felix.framework-1.4.1.jar
>>> >     org.eclipse.osgi.services.jar
>>> >     org.osgi.compendium.jar
>>> >     org.osgi.core.jar
>>> >     org.osgi.foundation.jar
>>> >     org.eclipse.equinox.servlet-1.0.1.jar
>>> >    -resources/
>>> >     -bundles/
>>> >        org.apache.felix.configadmin.jar
>>> >        org.apache.felix.metatype.jar
>>> >        org.apache.felix.webconsole.jar
>>> >        org.eclipse.osgi.services.jar
>>> >    -corebundles/
>>> >        servlet-api.osg1-2.5.jar
>>>
>>> Notes: servlet-api is not required in a servlet container environment,
>>> since this api is provided by the container and should be injected
>>> through the system bundle. The osgi.services jar should probably not be
>>> place in the lib and the bundles folder, one location should do it.
>>>
>>> I suggest to add an OSGi LogService implementation bundle, such that you
>>> get logging of OSGi events as well as the web console itself (and
>>> others).
>>>
>>> From the classes below, I can unfortunately not tell you exactly, why
>>> this does not work.
>>>
>>> If you could send me your web application directly (off-list), I could
>>> try to find out, what exactly is going on here.
>>>
>>> Regards
>>> Felix
>>>
>>> >
>>> >
>>> > Well, here's the serlvet that boots the system (got it from sling)
>>> >
>>> > package org.openspotlight.core.loader;
>>> >
>>> > import java.io.IOException;
>>> > import java.net.MalformedURLException;
>>> > import java.net.URL;
>>> > import java.util.Collections;
>>> > import java.util.HashMap;
>>> > import java.util.Iterator;
>>> > import java.util.Map;
>>> > import java.util.Set;
>>> >
>>> > import javax.servlet.GenericServlet;
>>> > import javax.servlet.Servlet;
>>> > import javax.servlet.ServletContext;
>>> > import javax.servlet.ServletException;
>>> > import javax.servlet.ServletRequest;
>>> > import javax.servlet.ServletResponse;
>>> > import javax.servlet.http.HttpServletResponse;
>>> >
>>> > import org.apache.felix.framework.Logger;
>>> > import org.eclipse.equinox.http.servlet.HttpServiceServlet;
>>> > import org.osgi.framework.BundleException;
>>> > import org.osgi.framework.ServiceReference;
>>> >
>>> > public class OSLServlet extends GenericServlet {
>>> >
>>> >     private OSL osl;
>>> >     private Servlet delegatee;
>>> >
>>> >     @Override
>>> >     public void service(ServletRequest req, ServletResponse res)
>>> >             throws ServletException, IOException {
>>> >          Servlet delegatee = getDelegatee();
>>> >             if (delegatee == null) {
>>> >                 ((HttpServletResponse)
>>> > res).sendError(HttpServletResponse.SC_NOT_FOUND);
>>> >             } else {
>>> >                 delegatee.service(req, res);
>>> >             }
>>> >     }
>>> >     @Override
>>> >     public void init() throws ServletException {
>>> >         ServletContextResourceProvider rp = new
>>> > ServletContextResourceProvider(getServletContext());
>>> >         Logger logger = new ServletContextLogger(getServletContext());
>>> >         Map<String, String> props = new HashMap<String, String>();
>>> >         this.osl = new OSL(rp,props,logger);
>>> >         this.delegatee = new HttpServiceServlet();
>>> >         this.delegatee.init(getServletConfig());
>>> >         super.init();
>>> >     }
>>> >
>>> >
>>> >     @Override
>>> >     public void destroy() {
>>> >         if(this.delegatee != null){
>>> >             this.delegatee.destroy();
>>> >             this.delegatee = null;
>>> >         }
>>> >
>>> >         if(this.osl != null){
>>> >             osl.destroy();
>>> >             this.osl = null;
>>> >         }
>>> >         super.destroy();
>>> >     }
>>> >
>>> >     public Servlet getDelegatee(){
>>> >         return this.delegatee;
>>> >     }
>>> >
>>> >
>>> >
>>> > }
>>> >
>>> >
>>> > Here's the bridge (OSL) also got from Sling:
>>> >
>>> > package org.openspotlight.core.loader;
>>> >
>>> > import java.util.ArrayList;
>>> > import java.util.HashMap;
>>> > import java.util.List;
>>> > import java.util.Map;
>>> > import java.util.concurrent.locks.ReadWriteLock;
>>> >
>>> > import org.apache.felix.framework.Felix;
>>> > import org.apache.felix.framework.Logger;
>>> > import org.apache.felix.framework.util.FelixConstants;
>>> > import org.eclipse.equinox.http.servlet.internal.Activator;
>>> > import org.osgi.framework.BundleActivator;
>>> > import org.osgi.framework.BundleContext;
>>> > import org.osgi.framework.BundleException;
>>> >
>>> > public class OSL implements BundleActivator {
>>> >
>>> >     private Felix felix;
>>> >     private ReadWriteLock felixLock;
>>> >     private ResourceProvider resourceProvider;
>>> >     private Logger logger;
>>> >     private BundleActivator httpServiceActivator;
>>> >
>>> >     public OSL(ResourceProvider rp, Map<String, String> props, Logger
>>> > logger){
>>> >         this.resourceProvider = rp;
>>> >         this.logger = logger;
>>> >         List<BundleActivator> activators = new
>>> ArrayList<BundleActivator>();
>>> >         activators.add(this);
>>> >         activators.add(new BootstrapInstaller(logger,rp));
>>> >         Map configMap = new HashMap();
>>> >         configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP,
>>> > activators);
>>> >         felix = new Felix(configMap);
>>> >         try {
>>> >             felix.start();
>>> >         } catch (Exception e) {
>>> >             e.printStackTrace();
>>> >         }
>>> >     }
>>> >
>>> >     public void start(BundleContext context) throws Exception {
>>> >         this.httpServiceActivator = new Activator();
>>> >         this.httpServiceActivator.start(context);
>>> >
>>> >     }
>>> >
>>> >     public void stop(BundleContext context) throws Exception {
>>> >         try {
>>> >             this.httpServiceActivator.stop(context);
>>> >         } catch (Exception e) {
>>> >             e.printStackTrace();
>>> >         }
>>> >         this.httpServiceActivator = null;
>>> >     }
>>> >
>>> >     public void destroy(){
>>> >         if (felix != null) {
>>> >             logger.log(Logger.LOG_INFO, "Shutting down OSL");
>>> >             try {
>>> >                 felix.stop();
>>> >             } catch (BundleException e) {
>>> >                 // TODO Auto-generated catch block
>>> >                 e.printStackTrace();
>>> >             }
>>> >             logger.log(Logger.LOG_INFO, "Sling stopped");
>>> >             felix = null;
>>> >         }
>>> >     }
>>> >
>>> > }
>>> >
>>> >
>>> > Well, I get this messages at console when starting up:
>>> >
>>> > 16:14:17,887 ERROR [STDERR] *DEBUG* Scheduling task ManagedService
>>> Update:
>>> > pid=org.apache.felix.webconsole.internal.servlet.OsgiManager
>>> > 16:14:17,888 ERROR [STDERR] *DEBUG* Running task ManagedService Update:
>>> > pid=org.apache.felix.webconsole.internal.servlet.OsgiManager
>>> >
>>> > But when I access: localhost:8080/osl/system/console It does not find
>>> the
>>> > service. Looking at the ServletProxy source I found that there was no
>>> > registrations in the class.
>>> >
>>> > Also, the first time I start the framework (after cleaning the cache
>>> dir) I
>>> > only find the system bundle. If I redeploy the war, it finds all the
>>> bundles
>>> > on the second time.
>>> >
>>> > Any ideas?
>>> >
>>> > Regards
>>> >
>>> >
>>> > On Fri, Jan 16, 2009 at 11:33 AM, Carsten Ziegeler <
>>> [email protected]>wrote:
>>> >
>>> >> Vinicius Carvalho wrote:
>>> >>> Thanks Felix that really helped, just a couple of more questions :)
>>> >>>
>>> >>> 1- Do I need to launch the container from a servlet (I was doing from
>>> a
>>> >>> Listener)
>>> >>> 2- So, this servlet must be mapped to /* url, just like the Sling
>>> does?
>>> >>>
>>> >> You can map the servlet to any path, like /myosgi - the web console is
>>> >> then by default reachable at /myosgi/system/console.
>>> >>
>>> >> HTH
>>> >> Carsten
>>> >> --
>>> >> Carsten Ziegeler
>>> >> [email protected]
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: [email protected]
>>> >> For additional commands, e-mail: [email protected]
>>> >>
>>> >>
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>
>

Reply via email to