Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » registering servlet using httpService via blueprint declaration in Virgo(registering servlet using httpService via blueprint declaration in Virgo)
registering servlet using httpService via blueprint declaration in Virgo [message #1387975] Wed, 25 June 2014 21:33 Go to next message
Johnson Abraham is currently offline Johnson AbrahamFriend
Messages: 3
Registered: November 2011
Junior Member
Using Eclipse Virgo Tooling in eclipse juno, I have created a Bundle project which which uses JRE 7.0. runtime environment. It is not a web application bundle

I am trying to register a HttpServlet using Equinox HttpService using Gemini Blueprint and then deploy it in 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.

Attached the log file.

Johnson Abraham


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 {
httpService.registerServlet(SERVLET_ALIAS,rs, null, null);
} catch (Exception se) {
_logger.log(Level.SEVERE, "SimpleBean unable to register servlet", se);
System.out.println ("SimpleServlet registered at /hellods");

public void stop(){




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.getWriter().write("Hello from the cloud!");

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]",
Bundle-Blueprint: OSGI-INF/blueprint/*.xml

<?xml version="1.0" encoding="UTF-8"?>
<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"/>


I have included the following jar in the ${VIRGO_HOME}/repository/ext

I have created a plan to include the and the above bundle which has been added to the initialArtifacts property in

<plan name="httpservice.blueprint" version="1.0.0" scoped="false" atomic="false">
<artifact type="bundle" name="javax.servlet" version="0.0.0"/>
<artifact type="bundle" name="" version="0.0.0"/>
<artifact type="bundle" name="org.eclipse.equinox.http.servlet" version="0.0.0"/>
<artifact type="bundle" name="org.eclipse.equinox.http.jetty" version="0.0.0"/>


Changed the osgi http port to the folllowing.
and set the -Dorg.eclipse.osgi.service.http.port=9090.

After all the above change, when I deploy my bundle in VJS in eclipse IDE. 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.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: java.lang.NoClassDefFoundError: javax.servlet.ServletException
at java.lang.Class.getDeclaredMethodsImpl(Native Method)
at java.lang.Class.getDeclaredMethods(
at org.springframework.aop.framework.JdkDynamicAopProxy.findDefinedEqualsAndHashCodeMethods(
at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(
at org.springframework.aop.framework.ProxyFactory.getProxy(
at org.eclipse.gemini.blueprint.service.util.internal.aop.ProxyUtils.createProxy(
at org.eclipse.gemini.blueprint.service.util.internal.aop.ProxyUtils.createProxy(
... 15 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletException
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
... 27 common frames omitted

Re: registering servlet using httpService via blueprint declaration in Virgo [message #1388549 is a reply to message #1387975] Thu, 26 June 2014 15:53 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi Johnson,

My blog post about the HTTPService is a little old now and I suspect something has changed. Please be aware that Virgo already provides a HTTPService separate from Jetty and this may be causing some issues when you try and run two at one. The config for the built in one is in configuration/config.ini and includes 'org.osgi.service.http.port=8080'. I can't remember if the built in HTTPService is used in the user region with the Jetty distribution, I just had a quick look and it dosn't look like it. I can't see the equinox.httpservice bundle at all actually. This would mean the admin console is running on Jetty as a Web Bundle but you should still be aware that the config is still there.

The exception you posted isn't the real error, it's masking the actual error that needed to lookup the 'ServletError' class which then swallowed your error and spat out that ClassNotFound exception. I would try and simplify your example, start with a bundle that works then see if you can pull in the httpService without error and then finally try and use the HttpService. Also, try expanding the version ranges for javax.servlet in your manifest. javax.servlet;version="[2.6.0,3.1.0)", javax.servlet.http;version="[2.6.0,3.1.0)", ..." Virgo ships with Servlet 3.0, this could be why ServletException isn't getting found.

Hope that helps.

Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: registering servlet using httpService via blueprint declaration in Virgo [message #1388703 is a reply to message #1388549] Thu, 26 June 2014 20:52 Go to previous message
Johnson Abraham is currently offline Johnson AbrahamFriend
Messages: 3
Registered: November 2011
Junior Member
Hi Chris,
Thanks for the reply.
I tried simplifying my example by removing the Gemini blueprint dependency injection and introducing a ServiceTracker to consume the org.eclipse.osgi.service.httpService . It works fine.

Now that I was able to consume the org.eclipse.osgi.service.httpService using ServiceTracker. I tried using blueprint dependency injection as well. The servlet was registered in a separate context path to ensure there is no conflict.

Though the httpService is available I am not able to consume it using the blueprint definition. It still throws the exception reported in my previous email.

I extended the version range of javax.servlet and javax.servlet.http but it had no affect on the exception.

I repeated the example by replacing the blueprint dependency injection with component based dependency injection (i.e. OSGI declarative service) It works fine. I am able to use both the HttpServiceTracker as well as the OSGI declarative service on two different context path.

I have pasted my HttpServiceTracker code below.

I have also attached my example project as well.

Johnson Abraham
public class HttpServiceTracker extends ServiceTracker {

private static Logger _logger = Logger.getLogger(HttpServiceTracker.class.getName());

public HttpServiceTracker(final BundleContext context) {
super(context, HttpService.class.getName(), null);"Creating tracker");

public Object addingService(final ServiceReference reference) {"adding Service " + reference);
HttpService httpService = (HttpService) super.addingService(reference);
if (httpService == null)
return null;

try {"registering servlet");"Registering servlet at /hellods");

new SimpleServlet(), null, null);
} catch (Exception e) {
_logger.log(Level.SEVERE, "Exception registering anotherhelloworldservlet", e);

return httpService;

public void removedService(final ServiceReference reference,
final Object service) {
HttpService httpService = (HttpService) service;

_logger.log(Level.INFO, "Unregistering /hellods");

super.removedService(reference, service);

Previous Topic:new version of virgo
Next Topic:Virgo Tomcat and static web content context
Goto Forum:

Current Time: Tue Aug 03 21:53:58 GMT 2021

Powered by FUDForum. Page generated in 0.01335 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top