geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Chau <mtqc2...@yahoo.com>
Subject Re: Geronino 3 beta Servlet issue
Date Thu, 19 Apr 2012 05:07:51 GMT
Thanks for helping me.  I'm new to OSGi.  Here are my configs and code.

SampleApp
APPLICATION.MF

Application-Name: sample-app
Application-SymbolicName: sample-app
Application-ManifestVersion: 1.0
Application-Version: 1.0.0.qualifier
Application-Content: sample-api;version="1.0.0",
 sample-server;version="1.0.0",
 sample-web;version="1.0.0"
Manifest-Version: 1.0

SampleApi

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: sample-api
Bundle-SymbolicName: sample-api
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: com.sample.api


package com.sample.api;

public interface SampleService {
	public String sayHello(String name);
}


SampleServer

Manifest-Version: 1.0
Bundle-Blueprint: OSGI-INF/blueprint/*.xml
Bundle-Version: 1.0.0.qualifier
Bundle-Name: sample-server
Bundle-ManifestVersion: 2
Import-Package: com.sample.api
Bundle-SymbolicName: sample-server
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: com.sample.server

Source:
package com.sample.server;

import com.sample.api.SampleService;

public class SampleServiceImpl implements SampleService {

	public String sayHello(String name) {
		// TODO Auto-generated method stub
		return "Hello "+name;
	}

}

**** Blueprint.xml

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
    <bean id="serviceBean" class="com.sample.server.SampleServiceImpl"/>

    <service ref="serviceBean" interface="com.sample.api.SampleService"/>

</blueprint>

SampleWeb

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: sample-web
Bundle-SymbolicName: sample-web
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: WEB-INF/classes
Web-ContextPath: /sample-web
Import-Package: com.sample.api,
 javax.naming,
 javax.servlet;version="2.5",
 javax.servlet.http;version="2.5"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: com.sample.client.web


package com.sample.client.web;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sample.api.SampleService;

/**
 * Servlet implementation class SampleServlet
 */
public class SampleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SampleServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
		// TODO Auto-generated method stub
		SampleService sample = null;
		try {
			InitialContext ic = new InitialContext();
			sample = (SampleService) ic.lookup("osgi:service/" + SampleService.class.getName());
			response.getOutputStream().println("**** " + sample.sayHello("Sample Service"));
		}
		catch (NamingException e) {
			e.printStackTrace(System.out);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
		// TODO Auto-generated method stub
	}

}

**** web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>sample-web</display-name>
  <servlet>
		<display-name>SampleServlet</display-name>
		<servlet-name>SampleServlet</servlet-name>
		<servlet-class>com.sample.client.web.SampleServlet</servlet-class>
  </servlet>
  <servlet-mapping>
		<servlet-name>SampleServlet</servlet-name>
		<url-pattern>/sample</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>



On Apr 18, 2012, at 8:44 PM, Forrest Xia wrote:

> Can you attach your sample here for a check?
> 
> On Thu, Apr 19, 2012 at 12:43 AM, Michael Chau <mtqc2000@yahoo.com> wrote:
> I have my SampleApi (interface) exported it.  I don't believe I'm suppose to export the
implementation (SampleServer) and web bundle(Sample Web).  But, i just tried exporting them
both just to see if it will work and I'm still getting the same error.  I'm somewhat following
the CounterApp example.  My web bundle is pretty much the same as the CounterWebBundle (same
required import packages and no exports).
> 
> 
> On Apr 18, 2012, at 12:55 AM, Forrest Xia wrote:
> 
>> Have you exported your application classes in Export-Package of MANIFEST.MF?
>> 
>> On Wed, Apr 18, 2012 at 3:42 AM, Michael Chau <mtqc2000@yahoo.com> wrote:
>> Thanks, Ivan.
>> 
>> I added the javax.naming to the import and now getting this error:
>> 
>> 2012-04-18 00:40:53,484 ERROR [WebApplication] Unable to start web application for
bundle sample-web
>> org.apache.geronimo.common.DeploymentException: Fail to load servlet class
>> 	at org.apache.geronimo.web25.deployment.merge.annotation.ServletSecurityAnnotationMergeHandler.postProcessWebXmlElement(ServletSecurityAnnotationMergeHandler.java:79)
>> 	at org.apache.geronimo.web25.deployment.merge.MergeHelper.processWebFragmentsAndAnnotations(MergeHelper.java:418)
>> 	at org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder.basicInitContext(AbstractWebModuleBuilder.java:493)
>> 	at org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder.initContext(AbstractWebModuleBuilder.java:436)
>> 	at org.apache.geronimo.osgi.web.extender.WebApplication.doRun(WebApplication.java:213)
>> 	at org.apache.geronimo.osgi.web.extender.WebApplication.run(WebApplication.java:125)
>> 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
>> 	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
>> 	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
>> 	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>> 	at java.lang.Thread.run(Thread.java:680)
>> Caused by: java.lang.ClassNotFoundException: com.sample.client.web.SampleServlet
>> 	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
>> 	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
>> 	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
>> 	at org.apache.geronimo.hook.equinox.GeronimoClassLoader.loadClass(GeronimoClassLoader.java:85)
>> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>> 	at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
>> 	at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
>> 	at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1207)
>> 	at org.apache.geronimo.web25.deployment.merge.annotation.ServletSecurityAnnotationMergeHandler.postProcessWebXmlElement(ServletSecurityAnnotationMergeHandler.java:52)
>> 	... 11 more
>> 
>> 
>> On Apr 17, 2012, at 11:09 PM, Ivan wrote:
>> 
>>> From the log files, it seems that javax.naming should be added in the import-package
list for the wab ?
>>> 
>>> 2012/4/18 Michael Chau <mchau01@gmail.com>
>>> I've created a SampleApi(interface), SampleServer(implementation) and SampleWeb(servlet)
bundles.  It's using Blueprint.  I ran it in the Apache Aries container and it was fine. 
I tried to run it in Geronimo and got 
>>> 
>>> 2012-04-17 14:44:52,759 ERROR [WebApplication] Unable to start web application
for bundle sample-web
>>> java.lang.NoClassDefFoundError: Could not fully load class: com.sample.client.web.SampleServlet
>>>  due to:javax/naming/NamingException
>>>  in classLoader: 
>>> org.apache.geronimo.hook.equinox.GeronimoClassLoader@10993991
>>> 	at org.apache.xbean.finder.ClassFinder.<init>(ClassFinder.java:136)
>>> 	at org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder.createWebAppClassFinder(AbstractWebModuleBuilder.java:663)
>>> 	at org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder.configureBasicWebModuleAttributes(AbstractWebModuleBuilder.java:698)
>>> 	at org.apache.geronimo.tomcat.deployment.TomcatModuleBuilder.addGBeans(TomcatModuleBuilder.java:483)
>>> 	at org.apache.geronimo.osgi.web.extender.WebApplication.doRun(WebApplication.java:218)
>>> 	at org.apache.geronimo.osgi.web.extender.WebApplication.run(WebApplication.java:125)
>>> 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
>>> 	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
>>> 	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
>>> 	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>>> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>>> 	at java.lang.Thread.run(Thread.java:680)
>>> 
>>> Any help is appreciated.
>>> 
>>> Michael
>>> 
>>> 
>>> 
>>> -- 
>>> Ivan
>> 
>> 
>> 
>> 
>> -- 
>> Thanks!
>> 
>> Regards, Forrest
>> 
> 
> 
> 
> 
> -- 
> Thanks!
> 
> Regards, Forrest
> 


Mime
View raw message