regunath
Jun 5th, 2008, 05:07 AM
Hi,
I am experimenting with Spring-DM to serve as a container for my Spring beans exposed as services. Contrary to the samples provided, I would like to deploy and invoke a bundle standalone and actually outside of Eclipse.
As per the documentation, I built the bundle for the "simple-service" sample. Again, in order to access the service, I created another Spring bean XML with relevant contents like
<osgi:reference id="service" interface="org.springframework.osgi.samples.simpleservice.MyS ervice"/>
<bean id="consumerBean" class="org.springframework.osgi.samples.simpleservice.Ser viceConsumer">
<property name="service" ref="service"/>
</bean>
I then wrote a sample class like this:
package org.springframework.osgi.samples.simpleservice;
public class OSGiTest {
private static final String[] paths = new String[] {
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/log4j.osgi-1.2.15-SNAPSHOT.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/commons-logging_all-2.0.0.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/aopalliance.osgi-1.0-SNAPSHOT.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/spring-core-2.5.4.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/spring-beans-2.5.4.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/spring-context-2.5.4.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/spring-aop-2.5.4.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/dist/spring-osgi-io-1.1.0-m2.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/dist/spring-osgi-core-1.1.0-m2.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/dist/spring-osgi-extender-1.1.0-m2.jar",
};
public static void main(String args[]) throws Exception {
EquinoxPlatform runtime = new EquinoxPlatform();
runtime.start();
BundleContext context = runtime.getBundleContext();
for (int i = 0; i < paths.length; i++) {
FileInputStream fis = new FileInputStream(paths[i]);
Bundle bundle = context.installBundle("Test " + i,fis);
bundle.start();
}
FileInputStream fis = new FileInputStream("D:/WorkTools/spring-osgi-1.1.0-m2/src/samples/simple-service/simple-service-bundle/target/simple-service-bundle-1.1.0-m2.jar");
Bundle bundle = context.installBundle("Simple-Service-Sample",fis);
bundle.start();
Bundle[] bundles = context.getBundles();
for (int j = 0; j < bundles.length; j++) {
ServiceReference[] sr = bundles[j].getRegisteredServices();
if (sr != null) {
for (int i = 0; i < sr.length; i++) {
System.out.println("Service Reference ---> " + sr[i]);
}
}
}
OsgiBundleXmlApplicationContext applicationContext = new OsgiBundleXmlApplicationContext(
new String[] {"file:///D:/WorkTools/spring-osgi-1.1.0-m2/src/samples/simple-service/simple-service-bundle/testbean.xml"});
applicationContext.setBundleContext(context);
applicationContext.refresh();
((ServiceConsumer)applicationContext.getBean("consumerBean")).foo();
bundle.stop();
//runtime.stop();
}
}
}
I was able to see a ServiceReference for the simple-service bundle. I however get an error trace like below :
Service Reference ---> {org.springframework.osgi.samples.simpleservice.My Service}={org.springframework.osgi.bean.name=simpl eService, Bundle-SymbolicName=org.springframework.osgi.samples.simp leservice, Bundle-Version=1.0, service.id=21}
Service Reference ---> {org.springframework.osgi.context.DelegatedExecuti onOsgiBundleApplicationContext, org.springframework.osgi.context.ConfigurableOsgiB undleApplicationContext, org.springframework.context.ConfigurableApplicatio nContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle,
........< other interfaces listed here >
org.springframework.beans.factory.DisposableBean}= {org.springframework.context.service.name=org.spri ngframework.osgi.samples.simpleservice, Bundle-SymbolicName=org.springframework.osgi.samples.simp leservice, Bundle-Version=1.0.0, service.id=22}
2008-06-05 14:27:17,031 [main] INFO [factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from OSGi resource[file:///D:/WorkTools/spring-osgi-1.1.0-m2/src/samples/simple-service/simple-service-bundle/testbean.xml|bnd.id=0|bnd.sym=system.bundle]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionSt oreException: Unexpected exception parsing XML document from OSGi resource[file:///D:/WorkTools/spring-osgi-1.1.0-m2/src/samples/simple-service/simple-service-bundle/testbean.xml|bnd.id=0|bnd.sym=system.bundle]; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:420)
...... <stack trace from Spring framework followed by>
Caused by: java.lang.NullPointerException
at org.eclipse.osgi.framework.internal.core.BundleLoa der.createBCL(BundleLoader.java:664)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.createBCLPrevileged(BundleLoader.java:639)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.createClassLoader(BundleLoader.java:313)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.getResources(BundleLoader.java:304)
at org.eclipse.osgi.framework.internal.core.BundleHos t.getResources(BundleHost.java:270)
at org.springframework.osgi.util.BundleDelegatingClas sLoader.findResources(BundleDelegatingClassLoader. java:137)
at java.lang.ClassLoader.getResources(ClassLoader.jav a:1015)
at org.springframework.core.io.support.PropertiesLoad erUtils.loadAllProperties(PropertiesLoaderUtils.ja va:103)
at org.springframework.beans.factory.xml.PluggableSch emaResolver.getSchemaMapping(PluggableSchemaResolv er.java:128)
at org.springframework.beans.factory.xml.PluggableSch emaResolver.resolveEntity(PluggableSchemaResolver. java:107)
at org.springframework.beans.factory.xml.DelegatingEn tityResolver.resolveEntity(DelegatingEntityResolve r.java:85)
at org.springframework.osgi.context.support.Delegated EntityResolver.resolveEntity(DelegatedEntityResolv er.java:59)
at com.sun.org.apache.xerces.internal.util.EntityReso lverWrapper.resolveEntity(EntityResolverWrapper.ja va:148)
at com.sun.org.apache.xerces.internal.impl.XMLEntityM anager.resolveEntity(XMLEntityManager.java:701)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maLoader.resolveDocument(XMLSchemaLoader.java:599)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.findSchemaGrammar(XMLSchemaValidator.j ava:2454)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.handleStartElement(XMLSchemaValidator. java:1807)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.startElement(XMLSchemaValidator.java:7 05)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.scanStartElement(XMLNSDocumentScann erImpl.java:324)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl$NSContentDispatcher.scanRootElement Hook(XMLNSDocumentScannerImpl.java:773)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDispatcher.dis patch(XMLDocumentFragmentScannerImpl.java:1794)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(DOMParser.java:250)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(DocumentBuilderImpl.java:292)
at org.springframework.beans.factory.xml.DefaultDocum entLoader.loadDocument(DefaultDocumentLoader.java: 75)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:396)
... 14 more
I wonder why I get a NullPointerException in the Eclipse BundleLoader.createBCL() method. Any pointers or help is much appreciated.
I am experimenting with Spring-DM to serve as a container for my Spring beans exposed as services. Contrary to the samples provided, I would like to deploy and invoke a bundle standalone and actually outside of Eclipse.
As per the documentation, I built the bundle for the "simple-service" sample. Again, in order to access the service, I created another Spring bean XML with relevant contents like
<osgi:reference id="service" interface="org.springframework.osgi.samples.simpleservice.MyS ervice"/>
<bean id="consumerBean" class="org.springframework.osgi.samples.simpleservice.Ser viceConsumer">
<property name="service" ref="service"/>
</bean>
I then wrote a sample class like this:
package org.springframework.osgi.samples.simpleservice;
public class OSGiTest {
private static final String[] paths = new String[] {
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/log4j.osgi-1.2.15-SNAPSHOT.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/commons-logging_all-2.0.0.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/aopalliance.osgi-1.0-SNAPSHOT.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/spring-core-2.5.4.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/spring-beans-2.5.4.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/spring-context-2.5.4.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/lib/spring-aop-2.5.4.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/dist/spring-osgi-io-1.1.0-m2.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/dist/spring-osgi-core-1.1.0-m2.jar",
"D:/WorkTools/spring-osgi-1.1.0-m2/dist/spring-osgi-extender-1.1.0-m2.jar",
};
public static void main(String args[]) throws Exception {
EquinoxPlatform runtime = new EquinoxPlatform();
runtime.start();
BundleContext context = runtime.getBundleContext();
for (int i = 0; i < paths.length; i++) {
FileInputStream fis = new FileInputStream(paths[i]);
Bundle bundle = context.installBundle("Test " + i,fis);
bundle.start();
}
FileInputStream fis = new FileInputStream("D:/WorkTools/spring-osgi-1.1.0-m2/src/samples/simple-service/simple-service-bundle/target/simple-service-bundle-1.1.0-m2.jar");
Bundle bundle = context.installBundle("Simple-Service-Sample",fis);
bundle.start();
Bundle[] bundles = context.getBundles();
for (int j = 0; j < bundles.length; j++) {
ServiceReference[] sr = bundles[j].getRegisteredServices();
if (sr != null) {
for (int i = 0; i < sr.length; i++) {
System.out.println("Service Reference ---> " + sr[i]);
}
}
}
OsgiBundleXmlApplicationContext applicationContext = new OsgiBundleXmlApplicationContext(
new String[] {"file:///D:/WorkTools/spring-osgi-1.1.0-m2/src/samples/simple-service/simple-service-bundle/testbean.xml"});
applicationContext.setBundleContext(context);
applicationContext.refresh();
((ServiceConsumer)applicationContext.getBean("consumerBean")).foo();
bundle.stop();
//runtime.stop();
}
}
}
I was able to see a ServiceReference for the simple-service bundle. I however get an error trace like below :
Service Reference ---> {org.springframework.osgi.samples.simpleservice.My Service}={org.springframework.osgi.bean.name=simpl eService, Bundle-SymbolicName=org.springframework.osgi.samples.simp leservice, Bundle-Version=1.0, service.id=21}
Service Reference ---> {org.springframework.osgi.context.DelegatedExecuti onOsgiBundleApplicationContext, org.springframework.osgi.context.ConfigurableOsgiB undleApplicationContext, org.springframework.context.ConfigurableApplicatio nContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle,
........< other interfaces listed here >
org.springframework.beans.factory.DisposableBean}= {org.springframework.context.service.name=org.spri ngframework.osgi.samples.simpleservice, Bundle-SymbolicName=org.springframework.osgi.samples.simp leservice, Bundle-Version=1.0.0, service.id=22}
2008-06-05 14:27:17,031 [main] INFO [factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from OSGi resource[file:///D:/WorkTools/spring-osgi-1.1.0-m2/src/samples/simple-service/simple-service-bundle/testbean.xml|bnd.id=0|bnd.sym=system.bundle]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionSt oreException: Unexpected exception parsing XML document from OSGi resource[file:///D:/WorkTools/spring-osgi-1.1.0-m2/src/samples/simple-service/simple-service-bundle/testbean.xml|bnd.id=0|bnd.sym=system.bundle]; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:420)
...... <stack trace from Spring framework followed by>
Caused by: java.lang.NullPointerException
at org.eclipse.osgi.framework.internal.core.BundleLoa der.createBCL(BundleLoader.java:664)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.createBCLPrevileged(BundleLoader.java:639)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.createClassLoader(BundleLoader.java:313)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.getResources(BundleLoader.java:304)
at org.eclipse.osgi.framework.internal.core.BundleHos t.getResources(BundleHost.java:270)
at org.springframework.osgi.util.BundleDelegatingClas sLoader.findResources(BundleDelegatingClassLoader. java:137)
at java.lang.ClassLoader.getResources(ClassLoader.jav a:1015)
at org.springframework.core.io.support.PropertiesLoad erUtils.loadAllProperties(PropertiesLoaderUtils.ja va:103)
at org.springframework.beans.factory.xml.PluggableSch emaResolver.getSchemaMapping(PluggableSchemaResolv er.java:128)
at org.springframework.beans.factory.xml.PluggableSch emaResolver.resolveEntity(PluggableSchemaResolver. java:107)
at org.springframework.beans.factory.xml.DelegatingEn tityResolver.resolveEntity(DelegatingEntityResolve r.java:85)
at org.springframework.osgi.context.support.Delegated EntityResolver.resolveEntity(DelegatedEntityResolv er.java:59)
at com.sun.org.apache.xerces.internal.util.EntityReso lverWrapper.resolveEntity(EntityResolverWrapper.ja va:148)
at com.sun.org.apache.xerces.internal.impl.XMLEntityM anager.resolveEntity(XMLEntityManager.java:701)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maLoader.resolveDocument(XMLSchemaLoader.java:599)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.findSchemaGrammar(XMLSchemaValidator.j ava:2454)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.handleStartElement(XMLSchemaValidator. java:1807)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.startElement(XMLSchemaValidator.java:7 05)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.scanStartElement(XMLNSDocumentScann erImpl.java:324)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl$NSContentDispatcher.scanRootElement Hook(XMLNSDocumentScannerImpl.java:773)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDispatcher.dis patch(XMLDocumentFragmentScannerImpl.java:1794)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(DOMParser.java:250)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(DocumentBuilderImpl.java:292)
at org.springframework.beans.factory.xml.DefaultDocum entLoader.loadDocument(DefaultDocumentLoader.java: 75)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:396)
... 14 more
I wonder why I get a NullPointerException in the Eclipse BundleLoader.createBCL() method. Any pointers or help is much appreciated.