Cannot deploy OSGI bundle with datasource
rcbandit Jan 3, 2012 3:35 AMHi,
I found this example how webapp can call methods from OSGI bundle:
https://github.com/bosschaert/coderthoughts/tree/master/WebAppOSGiService
I made some modification to the code:
package org.coderthoughts.demo.web.osgi.impl; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Random; import javax.activation.DataSource; import javax.annotation.Resource; import org.coderthoughts.demo.web.osgi.api.StockInfoService; import org.coderthoughts.demo.web.osgi.api.StockQuote; public class StockInfoServiceImpl implements StockInfoService { public static final long DELAY = 15; @Resource(name="java:/Oracle") public DataSource ds; private Random random = new Random(); public StockQuote getStockQuote(String symbol) { return new StockQuote() { public int getPrice(int tte) { return tte; } public String getCurrency(String hash){ StringBuilder sb = null; try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(hash.getBytes()); byte byteData[] = md.digest(); /** convert the byte to hex format */ sb = new StringBuilder(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); } return sb.toString(); } public String getDelay(String ggh) { return ggh; } }; } }
When I try to deploy the OSGI bundle in JBoss 7.1.0 CR1B an error occurs. This is the error stack:
[root@Testserver bin]# [root@Testserver bin]# ./standalone.sh ========================================================================= JBoss Bootstrap Environment JBOSS_HOME: /opt/jboss-as-7.1.0.CR1b JAVA: /opt/jdk1.7.0_01/bin/java JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true ========================================================================= 10:38:26,004 INFO [org.jboss.modules] JBoss Modules version 1.1.0.CR6 10:38:26,349 INFO [org.jboss.msc] JBoss MSC version 1.0.1.GA 10:38:26,410 INFO [org.jboss.as] JBoss AS 7.1.0.CR1b "Flux Capacitor" starting 10:38:27,669 INFO [org.xnio] XNIO Version 3.0.0.CR7 10:38:27,681 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.0.CR7 10:38:27,691 INFO [org.jboss.remoting] JBoss Remoting version 3.2.0.CR8 10:38:27,699 INFO [org.jboss.as] Creating http management service using socket-binding (management-http) 10:38:27,748 INFO [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers 10:38:27,798 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 26) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3) 10:38:27,801 INFO [org.jboss.as.clustering] (ServerService Thread Pool -- 30) JBAS010300: Activating Infinispan subsystem. 10:38:27,857 INFO [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011910: Activating OSGi Subsystem 10:38:27,883 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem 10:38:27,897 INFO [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service 10:38:27,952 INFO [org.jboss.as.security] (ServerService Thread Pool -- 44) Activating Security Subsystem 10:38:27,962 INFO [org.jboss.as.connector] (MSC service thread 1-3) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.6.Final) 10:38:28,051 INFO [org.jboss.as.mail.extension] (MSC service thread 1-4) JBAS015400: Bound mail session [java:jboss/mail/Default] 10:38:28,053 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-4) JBossOSGi Framework Core - 1.1.0 10:38:28,056 INFO [org.jboss.as.security] (MSC service thread 1-4) Picketbox version=4.0.6.Beta2 10:38:28,099 INFO [org.jboss.as.jaxr] (MSC service thread 1-2) Binding JAXR ConnectionFactory: java:jboss/jaxr/ConnectionFactory 10:38:28,144 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension 10:38:28,245 INFO [org.jboss.as.remoting] (MSC service thread 1-1) Listening on /10.15.203.13:4447 10:38:28,468 INFO [org.apache.coyote.http11.Http11AprProtocol] (MSC service thread 1-1) Starting Coyote HTTP/1.1 on http--10.15.203.13-8080 10:38:28,476 INFO [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-3) JBoss Web Services - Stack CXF Server 4.0.0.GA 10:38:28,513 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-2) Install bundle: system.bundle:0.0.0 10:38:28,929 WARN [org.jboss.as.osgi] (MSC service thread 1-2) JBAS011918: Found OSGi bundle in modules hierarchy: /opt/jboss-as-7.1.0.CR1b/modules/org/jboss/netty/main/netty-3.2.5.Final.jar 10:38:29,050 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: org.apache.felix.log:1.0.0 10:38:29,061 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-2) Install bundle: org.apache.felix.metatype:1.0.4 10:38:29,161 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-2) Install bundle: stilts-stomplet-server-bundle:0.1.20 10:38:29,170 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: org.apache.aries.util:0.3.0 10:38:29,173 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: javax.api:0.0.0 10:38:29,196 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-2) Install bundle: jboss-as-osgi-configadmin:7.1.0.CR1b 10:38:29,200 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: jboss-osgi-jmx:1.0.10 10:38:29,213 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: jbosgi-webconsole:1.0.6 10:38:29,231 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: jboss-osgi-logging:1.0.0 10:38:29,607 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: org.apache.aries.jmx:0.3.0 10:38:30,005 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: jboss-osgi-xerces:2.9.1.SP7 10:38:30,011 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: javax.servlet.api:0.0.0 10:38:30,013 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: javax.transaction.api:0.0.0 10:38:30,236 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: org.apache.felix.configadmin:1.2.8 10:38:30,246 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: org.apache.felix.eventadmin:1.2.6 10:38:30,309 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: jbosgi-blueprint:1.0.3 10:38:30,600 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-4) Install bundle: osgi.cmpn:4.2.0.200908310645 10:38:30,731 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: org.apache.felix.scr:1.6.0 10:38:30,828 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-4) Install bundle: jbosgi-http:1.0.5 10:38:31,059 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: org.apache.felix.webconsole:3.1.6.SP1 10:38:31,073 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Install bundle: jbosgi-webapp:1.0.5 10:38:31,098 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-1) JBAS015012: Started FileSystemDeploymentService for directory /opt/jboss-as-7.1.0.CR1b/standalone/deployments 10:38:31,180 INFO [org.jboss.as.remoting] (MSC service thread 1-1) Listening on /10.15.203.13:9999 10:38:31,252 INFO [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-2) Install bundle: org.jboss.netty:3.2.5.Final 10:38:31,322 INFO [org.jboss.osgi.framework.internal.StartLevelPlugin] (MSC service thread 1-2) Starting bundles for start level: 1 10:38:31,559 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: jboss-osgi-logging:1.0.0 10:38:31,707 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: jboss-as-osgi-configadmin:7.1.0.CR1b 10:38:31,847 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: org.apache.felix.log:1.0.0 10:38:31,878 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: org.apache.felix.configadmin:1.2.8 10:38:31,879 INFO [org.jboss.osgi.framework.internal.StartLevelPlugin] (MSC service thread 1-2) Starting bundles for start level: 2 10:38:31,976 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: org.apache.felix.scr:1.6.0 10:38:32,017 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: org.jboss.netty:3.2.5.Final 10:38:32,083 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: org.apache.felix.eventadmin:1.2.6 10:38:32,339 INFO [org.eclipse.jetty.util.log] (MSC service thread 1-2) jetty-7.x.y-SNAPSHOT 10:38:32,397 INFO [org.eclipse.jetty.util.log] (MSC service thread 1-2) Started NIOSocketConnectorWrapper@0.0.0.0:8090 10:38:32,421 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: jbosgi-http:1.0.5 10:38:32,476 INFO [org.projectodd.stilts.stomplet.bundle.StompletServerActivator] (MSC service thread 1-2) start: BundleContext[stilts-stomplet-server-bundle:0.1.20] 10:38:32,487 INFO [org.projectodd.stilts.stomplet.bundle.StompletServerActivator] (MSC service thread 1-2) adding transaction manager: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@3b92671a 10:38:32,490 INFO [org.projectodd.stilts.stomplet.server.StompletServer] (MSC service thread 1-2) STOMPLET_SERVER start() 10:38:32,491 ERROR [org.projectodd.stilts.conduit.ConduitServer] (MSC service thread 1-2) CONDUIT_SERVER.start com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@3b92671a 10:38:32,516 INFO [org.eclipse.jetty.util.log] (CM Configuration Updater (ManagedService Update: pid=org.ops4j.pax.web)) jetty-7.x.y-SNAPSHOT 10:38:32,523 INFO [org.eclipse.jetty.util.log] (CM Configuration Updater (ManagedService Update: pid=org.ops4j.pax.web)) Started NIOSocketConnectorWrapper@0.0.0.0:8090 10:38:32,579 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: stilts-stomplet-server-bundle:0.1.20 10:38:32,676 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: jboss-osgi-jmx:1.0.10 10:38:32,685 INFO [org.apache.aries.jmx] (Thread-63) Starting JMX OSGi agent 10:38:32,704 INFO [org.apache.aries.jmx] (Thread-63) Registering MBean with ObjectName [osgi.compendium:service=cm,version=1.3] for service with service.id [13] 10:38:32,713 INFO [org.apache.aries.jmx] (Thread-63) Registering org.osgi.jmx.service.cm.ConfigurationAdminMBean to MBeanServer org.jboss.as.jmx.PluggableMBeanServerImpl@1df889b9 with name osgi.compendium:service=cm,version=1.3 10:38:32,713 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: org.apache.aries.jmx:0.3.0 10:38:32,714 INFO [org.apache.aries.jmx] (Thread-63) Registering org.osgi.jmx.framework.PackageStateMBean to MBeanServer org.jboss.as.jmx.PluggableMBeanServerImpl@1df889b9 with name osgi.core:type=packageState,version=1.5 10:38:32,715 INFO [org.apache.aries.jmx] (Thread-63) Registering org.osgi.jmx.framework.ServiceStateMBean to MBeanServer org.jboss.as.jmx.PluggableMBeanServerImpl@1df889b9 with name osgi.core:type=serviceState,version=1.5 10:38:32,722 INFO [org.apache.aries.jmx] (Thread-63) Registering org.osgi.jmx.framework.BundleStateMBean to MBeanServer org.jboss.as.jmx.PluggableMBeanServerImpl@1df889b9 with name osgi.core:type=bundleState,version=1.5 10:38:32,724 INFO [org.apache.aries.jmx] (Thread-63) Registering org.osgi.jmx.framework.FrameworkMBean to MBeanServer org.jboss.as.jmx.PluggableMBeanServerImpl@1df889b9 with name osgi.core:type=framework,version=1.5 10:38:33,126 INFO [org.eclipse.jetty.util.log] (MSC service thread 1-2) started HttpServiceContext{httpContext=org.apache.felix.webconsole.internal.servlet.OsgiManagerHttpContext@78d2b5cf} 10:38:33,174 INFO [org.eclipse.jetty.util.log] (CM Configuration Updater (ManagedService Update: pid=org.apache.felix.webconsole.internal.servlet.OsgiManager)) stopped HttpServiceContext{httpContext=org.apache.felix.webconsole.internal.servlet.OsgiManagerHttpContext@78d2b5cf} 10:38:33,178 INFO [org.eclipse.jetty.util.log] (CM Configuration Updater (ManagedService Update: pid=org.apache.felix.webconsole.internal.servlet.OsgiManager)) started HttpServiceContext{httpContext=org.apache.felix.webconsole.internal.servlet.OsgiManagerHttpContext@1f04e1c2} 10:38:33,189 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: org.apache.felix.webconsole:3.1.6.SP1 10:38:33,232 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: org.apache.felix.metatype:1.0.4 10:38:33,233 INFO [org.jboss.osgi.framework.internal.StartLevelPlugin] (MSC service thread 1-2) Starting bundles for start level: 3 10:38:33,317 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: jbosgi-blueprint:1.0.3 10:38:33,423 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: jbosgi-webapp:1.0.5 10:38:33,575 INFO [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: jboss-osgi-xerces:2.9.1.SP7 10:38:33,577 INFO [org.jboss.osgi.framework.internal.FrameworkActive] (MSC service thread 1-2) OSGi Framework started 10:38:33,595 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report JBAS014775: New missing/unsatisfied dependencies: service jboss.jdbc-driver._ojdbc6_jar (missing) dependents: [service jboss.data-source.java:/Oracle] 10:38:33,602 ERROR [org.jboss.as] (Controller Boot Thread) JBoss AS 7.1.0.CR1b "Flux Capacitor" started (with errors) in 7850ms - Started 129 of 200 services (2 services failed or missing dependencies, 67 services are passive or on-demand) 10:38:33,612 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) Starting deployment of "_ojdbc6.jar" 10:38:33,993 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010403: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 11.2) 10:38:34,058 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010400: Bound data source [java:/Oracle] 10:38:34,113 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "_ojdbc6.jar" 10:38:34,114 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report JBAS014776: Newly corrected services: service jboss.jdbc-driver._ojdbc6_jar (no longer required) 10:38:44,426 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "osgi-webapp-demo-bundle-7.0.0.jar" 10:38:44,437 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.deployment.unit."osgi-webapp-demo-bundle-7.0.0.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."osgi-webapp-demo-bundle-7.0.0.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "osgi-webapp-demo-bundle-7.0.0.jar" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA] at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0_01] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0_01] at java.lang.Thread.run(Thread.java:722) [:1.7.0_01] Caused by: java.lang.NullPointerException at org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor.isEnvEntryType(ResourceInjectionAnnotationParsingProcessor.java:296) at org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor.process(ResourceInjectionAnnotationParsingProcessor.java:227) at org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor.processFieldResource(ResourceInjectionAnnotationParsingProcessor.java:184) at org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor.deploy(ResourceInjectionAnnotationParsingProcessor.java:146) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b] ... 5 more 10:38:44,445 INFO [org.jboss.as.server] (HttpManagementService-threads - 1) JBAS015856: Undeploy of deployment "osgi-webapp-demo-bundle-7.0.0.jar" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"osgi-webapp-demo-bundle-7.0.0.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"osgi-webapp-demo-bundle-7.0.0.jar\".POST_MODULE: Failed to process phase POST_MODULE of deployment \"osgi-webapp-demo-bundle-7.0.0.jar\""}} 10:38:44,447 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) Stopped deployment osgi-webapp-demo-bundle-7.0.0.jar in 5ms 10:38:44,448 INFO [org.jboss.as.controller] (HttpManagementService-threads - 1) JBAS014774: Service status report JBAS014777: Services which failed to start: service jboss.deployment.unit."osgi-webapp-demo-bundle-7.0.0.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."osgi-webapp-demo-bundle-7.0.0.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "osgi-webapp-demo-bundle-7.0.0.jar"
Maybe there is a bug into JBoss application server or it's not possible to use datasource into OSGI bundle?
Regards
Peter