Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[virgo-dev] problem registering HttpServlet using Equinox HttpService using Gemini Blueprint

Hi,
Using Eclipse Virgo Tooling, I have created a Bundle project which is not a web application bundle the runtime environment JRE 7.0.
The following project facet are selected

Java 1.6

I am trying to register a HttpServlet using Equinox HttpService using Gemini Blueprint and then deploy it Virgo Jetty Server 3.6.0. Below I have provided the details of the project I had created along with the exception that I get. Not sure what is causing the class loading issue. How I can fix this issue ? I am new to OSGI and Virgo  please can you provide me some details and possible solution to the issue.
thanks.
Johnson Abraham


///---------------------------------------SimpleBean-------------------------------------------------------

import java.util.logging.Level;
import java.util.logging.Logger;

import org.osgi.service.http.HttpService;

public class SimpleBean {
   
    private static final String SERVLET_ALIAS = "/hellods";
    private HttpService httpService;
    private static final Logger _logger = Logger.getLogger(SimpleBean.class.getName());


        public void setHttpService (HttpService httpService) {
            this.httpService = httpService;
           
        }
       
        public void start(){
            SimpleServlet rs = new SimpleServlet();
            ClassLoader old = Thread.currentThread().getContextClassLoader();
           
            try {
                Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
                httpService.registerServlet(SERVLET_ALIAS,rs, null, null);
            } catch (Exception se) {
                se.printStackTrace();
                _logger.log(Level.SEVERE, "SimpleBean unable to register servlet", se);
            }finally{
                Thread.currentThread().setContextClassLoader(old);
            }
            System.out.println ("SimpleServlet registered at /hellods");
        }
       
        public void stop(){
            httpService.unregister(SERVLET_ALIAS);
            httpService.unregister("/*");

        }
   
}

///------------------------------------SimpleServlet----------------------------------------
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SimpleServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.setContentType("text/plain");
            resp.getWriter().write("Hello from the cloud!");
    }
}


///////--------------------------------------MANIFEST.MF---------------------------------------------
Manifest-Version: 1.0
Bundle-Description: OSGI
Bundle-Name: Demo1
Bundle-SymbolicName: com.osgi.httpservice.bp.demo1
Bundle-Version: 1.0.0
Bundle-ManifestVersion: 2
Import-Package: javax.servlet;version="[2.6.0,2.6.0]",
 javax.servlet.http;version="[2.6.0,2.6.0]",
 org.osgi.service.device;version="[1.1.0,1.1.0]",
 org.osgi.service.event;version="[1.3.0,1.3.0]",
 org.osgi.service.http;version="[1.2.1,1.2.1]",
 org.osgi.service.io;version="[1.0.0,1.0.0]",
 org.osgi.service.metatype;version="[1.2.0,1.2.0]",
 org.osgi.service.provisioning;version="[1.2.0,1.2.0]",
 org.osgi.service.upnp;version="[1.2.0,1.2.0]",
 org.osgi.service.useradmin;version="[1.1.0,1.1.0]",
 org.osgi.service.wireadmin;version="[1.0.1,1.0.1]"
Bundle-Blueprint: OSGI-INF/blueprint/*.xml

//----------------------------OSGI-INF/blueprint/blueprint.xml---------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
   <reference id="simpleService" interface="org.osgi.service.http.HttpService"/>
 
  <bean id="simpleBean" class="com.osgi.httpservice.bp.demo1.SimpleBean" init-method="start" destroy-method="stop">
    <property name="httpService" ref="simpleService"/>
  </bean>
 
</blueprint>

Following the instruction in the following link
http://chrisfrost.com/osgi/extending-virgo-with-a-httpservice/

I had included the following jar in the ${VIRGO_HOME}/repository/usr


I have included it in the initialArtifacts property in org.eclipse.virgo.kernel.userregion.properties
and set the -Dorg.eclipse.osgi.service.http.port=9090.

After all the above change, when I deploy my bundle in VJS. I get the following exception

[2014-06-24 15:34:23.119] start-signalling-2           <DE0006E> Start failed for bundle 'com.osgi.httpservice.bp.demo1' version '1.0.0'. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleService': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: javax.servlet.ServletException
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1441)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:581)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:60)
    at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:325)
    at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
    at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:290)
    at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137)
    at org.eclipse.virgo.kernel.agent.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:95)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:626)
    at java.lang.Thread.run(Thread.java:804)
Caused by: java.lang.NoClassDefFoundError: javax.servlet.ServletException
    at java.lang.Class.getDeclaredMethodsImpl(Native Method)
    at java.lang.Class.getDeclaredMethods(Class.java:783)
    at org.springframework.aop.framework.JdkDynamicAopProxy.findDefinedEqualsAndHashCodeMethods(JdkDynamicAopProxy.java:127)
    at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(JdkDynamicAopProxy.java:116)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:112)
    at org.eclipse.gemini.blueprint.service.util.internal.aop.ProxyUtils.createProxy(ProxyUtils.java:68)
    at org.eclipse.gemini.blueprint.service.util.internal.aop.ProxyUtils.createProxy(ProxyUtils.java:37)
    at org.eclipse.gemini.blueprint.service.importer.support.AbstractServiceProxyCreator.createServiceProxy(AbstractServiceProxyCreator.java:105)
    at org.eclipse.gemini.blueprint.service.importer.support.OsgiServiceProxyFactoryBean.createProxy(OsgiServiceProxyFactoryBean.java:181)
    at org.eclipse.gemini.blueprint.service.importer.support.AbstractServiceImporterProxyFactoryBean.getObject(AbstractServiceImporterProxyFactoryBean.java:95)
    at org.eclipse.gemini.blueprint.service.importer.support.OsgiServiceProxyFactoryBean.getObject(OsgiServiceProxyFactoryBean.java:125)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
    ... 15 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletException
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:455)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:707)
    ... 27 common frames omitted

Also get another exception

Caused by: org.eclipse.virgo.kernel.osgi.framework.ExtendedClassNotFoundException: javax.servlet.http.HttpServletRequest in KernelBundleClassLoader: [bundle=org.eclipse.equinox.http_1.0.400.v20100503]
    at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:150)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:707)
    ... 50 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:455)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:146)
    ... 51 common frames omitted



Back to the top