[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