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