solution to the example!!

View: New views
3 Messages — Rating Filter:   Alert me  

solution to the example!!

by Freitas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi ,
  I would like to send my example to help those who are starting with easybeans. I've used a EZB + EJB on OSGI Equinox .
This sample includes a HelloWorld example containing an SLSB and a client for invocation.  

This example was only possible with EkkeHard Gentz's help.

 Thanks Ekke!

//--------------------------------------------------------------------
Step 1

Follow the sequence of the blog of Ekke.

I've used a easybeans_target_minimal

http://ekkes-corner.blogspot.com/2008/06/easybeans-und-equinox.html

//------------------------------------------------------------------------

Step 2

Create two bundle/plugin projects:

ex..

br.com.test_ezb
    and
br.com.test_ezb_invoke

//-------------------------------------------------------------------------

  br.com.test_ezb

//----- Interface EJB

package br.com.test_ezb;

import javax.ejb.Local;
import javax.ejb.Remote;

@Local
@Remote
public interface Hello{
        public String sayHello(String str);
}

//--- Stateless EJB

package br.com.test_ezb;

import javax.ejb.Stateless;

@Stateless(mappedName="HelloBean")
public class HelloBean implements Hello{
        public String sayHello(String str){
                return str;
        }  
}



//---Manifest

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test_ezb3 Plug-in
Bundle-SymbolicName: br.com.test_ezb
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Activator:  org.ow2.easybeans.osgi.ejbjar.Activator
Bundle-ActivationPolicy: lazy
Import-Package:  javax.ejb , org.ow2.easybeans.osgi.ejbjar , javax.annotation
Export-Package: br.com.test_ezb



//This bundle must have this Activator org.ow2.easybeans.osgi.ejbjar.Activator

//----------------------------------------------------------------------------------

br.com.test_ezb_invoke


//For this bundle to work, you must add in your easybeans_targed_minimal 
//this bundle  org.eclipse.osgi.source_3.4.0


//This bundle should have this Activator.
 
package br.com.test_ezb_invoke;

import javax.naming.Context;
import javax.naming.NamingException;
import java.util.Hashtable;
import javax.naming.InitialContext;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;


import br.com.test_ezb.Hello;

public class Activator implements BundleActivator {


      private static final String DEFAULT_INITIAL_CONTEXT_FACTORY = "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory";
   

      private Hello hello = null;
     
      private static Context getInitialContext() throws NamingException {

            Hashtable<String, Object> env = new Hashtable<String, Object>();
            env.put(Context.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT_FACTORY);           
            return new InitialContext(env);}
     
     
    /*
     * (non-Javadoc)
     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
     */
    public void start(BundleContext context) throws Exception {
              
       
        Context initialContext = getInitialContext();
        hello = (Hello) initialContext.lookup("HelloBean");
        System.out.println(hello.sayHello("Hello World"));     

    }

    /*
     * (non-Javadoc)
     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     */
    public void stop(BundleContext context) throws Exception {
    }

}

//--- manifest

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test_ezb_ivk2 Plug-in
Bundle-SymbolicName: br.com.test_ezb_invoke
Bundle-Version: 1.0.0
Bundle-Activator: br.com.test_ezb_invoke.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.osgi.framework;version="1.3.0", javax.ejb, br.com.test_ezb, org.objectweb.carol.jndi.spi


//----------------------------------------------------

Step 3

 before your code is running you must be sure:
1) that EZB initializes all well

2) the EZB agent must be finished
3) and also Hibernate must be finsihed initiliazing

Console View



osgi> 29/10/08 15:22:09 (W) Activator.start : Cannot find User configuration (easybeans.xml) for Easybeans. Using default configuration
29/10/08 15:22:11 (I) Activator.start : Starting Bundle initial@reference:file:easybeans-component-carol_1.0.2.jar/ [14]
29/10/08 15:22:12 (I) Activator.start : Starting Bundle initial@reference:file:easybeans-component-jotm_1.0.2.jar/ [15]
INFO - 15:22:12 [B: org.ow2.easybeans.component.carol] - BundleEvent STARTED.
INFO - 15:22:12 [B: org.ow2.easybeans.component.jotm] - BundleEvent STARTED.
29/10/08 15:22:12 (I) Activator.start : Starting Bundle initial@reference:file:easybeans-component-quartz_1.0.2.jar/ [2]
INFO - 15:22:12 [B: org.ow2.easybeans.component.quartz] - BundleEvent STARTED.
29/10/08 15:22:12 (I) Activator.start : Starting Bundle initial@reference:file:easybeans-component-hsqldb_1.0.2.jar/ [6]
INFO - 15:22:12 [B: org.ow2.easybeans.component.hsqldb] - BundleEvent STARTED.
29/10/08 15:22:12 (I) Activator.start : Starting Bundle initial@reference:file:easybeans-core_1.0.2.jar/ [10]
29/10/08 15:22:12 (I) Activator.start : Starting Bundle initial@reference:file:easybeans-component-joram_1.0.2.jar/ [3]
INFO - 15:22:12 [B: org.ow2.easybeans.core] - BundleEvent STARTED.
29/10/08 15:22:12 (I) Activator.start : Starting Bundle initial@reference:file:easybeans-component-jdbcpool_1.0.2.jar/ [5]
INFO - 15:22:12 [B: org.ow2.easybeans.component.joram] - BundleEvent STARTED.
INFO - 15:22:12 [B: org.ow2.easybeans.component.jdbcpool] - BundleEvent STARTED.
INFO - 15:22:12 [B: org.ow2.easybeans.agent] - BundleEvent STARTED.
INFO - 15:22:12 [S: org.ow2.easybeans.component.carol.carolcomponent] - ServiceEvent REGISTERED.
INFO - 15:22:12 [B: org.eclipse.osgi] - FrameworkEvent STARTLEVEL CHANGED.
INFO - 15:22:12 [S: org.ow2.easybeans.component.hsqldb.hsqldbcomponent] - ServiceEvent REGISTERED.
29/10/08 15:22:12 (I) TraceCarol.infoCarol : Name service for jrmp is started on port 1099
INFO - 15:22:13 [S: org.ow2.easybeans.component.carol.carolcomponent-1225300931396-1] - ServiceEvent REGISTERED.
INFO - 15:22:13 [S: org.ow2.easybeans.component.jotm.jotmcomponent] - ServiceEvent REGISTERED.
INFO - 15:22:13 [S: org.ow2.easybeans.component.quartz.quartzcomponent] - ServiceEvent REGISTERED.
INFO - 15:22:13 [S: org.ow2.easybeans.core] - ServiceEvent REGISTERED.
29/10/08 15:22:13 (I) EZBCoreService.activate : Activating EasyBeans/OSGi/Core
29/10/08 15:22:13 (I) PolicyProvider.init : Using EasyBeans policy provider 'org.ow2.easybeans.security.jacc.provider.JPolicy'.
29/10/08 15:22:13 (I) PolicyProvider.init : Using EasyBeans PolicyConfigurationFactory provider and EasyBeans Policy provider
29/10/08 15:22:14 (I) JMXRemoteHelper.init : Creating JMXRemote connector with URL 'service:jmx:rmi:///jndi/rmi://localhost:1099/EasyBeansConnector'
29/10/08 15:22:14 (I) Embedded.start : Startup of EasyBeans '1.0.2' was done in '1.017' ms.
INFO - 15:22:14 [S: null] - ServiceEvent REGISTERED.
29/10/08 15:22:14 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.carol.carolcomponent-1225300931396-1 created
INFO - 15:22:14 [S: org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent] - ServiceEvent REGISTERED.
29/10/08 15:22:14 (I) HSQLDBComponent.start : Starting 'HSQLDB server' '1.8.0' on port '9002'
29/10/08 15:22:15 (I) HSQLDBComponent.start : HSQLDB server started with URL jdbc:hsqldb:hsql://localhost:9002/jdbc_2
INFO - 15:22:15 [S: org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931643-5] - ServiceEvent REGISTERED.
29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931643-5 created
29/10/08 15:22:15 (I) HSQLDBComponent.start : Starting 'HSQLDB server' '1.8.0' on port '9001'
29/10/08 15:22:15 (I) HSQLDBComponent.start : HSQLDB server started with URL jdbc:hsqldb:hsql://localhost:9001/jdbc_1
INFO - 15:22:15 [S: org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931600-4] - ServiceEvent REGISTERED.
29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931600-4 created
29/10/08 15:22:15 (I) Current.<init> : JOTM 2.0.10
29/10/08 15:22:15 (I) JOTMComponent.start : Register javax.transaction.UserTransaction as transaction manager object
INFO - 15:22:15 [S: org.ow2.easybeans.component.jotm.jotmcomponent-1225300931470-2] - ServiceEvent REGISTERED.
INFO - 15:22:15 [S: org.ow2.easybeans.component.joram.joramcomponent] - ServiceEvent REGISTERED.
29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.jotm.jotmcomponent-1225300931470-2 created
29/10/08 15:22:16 (I) QuartzScheduler.<init> : Quartz Scheduler v.1.6.0 created.
29/10/08 15:22:16 (I) RAMJobStore.initialize : RAMJobStore initialized.
29/10/08 15:22:16 (I) StdSchedulerFactory.instantiate : Quartz scheduler 'EasyBeans' initialized from an externally provided properties instance.
29/10/08 15:22:16 (I) StdSchedulerFactory.instantiate : Quartz scheduler version: 1.6.0
29/10/08 15:22:16 (I) QuartzScheduler.start : Scheduler EasyBeans_$_NON_CLUSTERED started.
INFO - 15:22:16 [S: org.ow2.easybeans.component.quartz.quartzcomponent-1225300930552-0] - ServiceEvent REGISTERED.
29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.quartz.quartzcomponent-1225300930552-0 created
29/10/08 15:22:16 (I) JDBCPoolComponent.start : DS 'jdbc_1', URL 'jdbc:hsqldb:hsql://localhost:9001/jdbc_1', Driver = 'org.hsqldb.jdbcDriver'.
INFO - 15:22:16 [S: org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931753-7] - ServiceEvent REGISTERED.
29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931753-7 created
29/10/08 15:22:16 (I) JDBCPoolComponent.start : DS 'jdbc_2', URL 'jdbc:hsqldb:hsql://localhost:9002/jdbc_2', Driver = 'org.hsqldb.jdbcDriver'.
INFO - 15:22:16 [S: org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931796-8] - ServiceEvent REGISTERED.
29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931796-8 created
29/10/08 15:22:17 (I) JoramComponent.start : Joram version '5.0.9' started on localhost:16030. WorkManager[minTx=5,maxTx=100,txTimeout=60s]
INFO - 15:22:17 [S: org.ow2.easybeans.component.joram.joramcomponent-1225300931532-3] - ServiceEvent REGISTERED.
29/10/08 15:22:17 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.joram.joramcomponent-1225300931532-3 created
ss

Framework is launched.

id    State       Bundle
0    ACTIVE      org.eclipse.osgi_3.4.0.v20080529-1200
1    ACTIVE      org.eclipse.equinox.cm_1.0.0.v20080509-1800
2    ACTIVE      org.ow2.easybeans.component.quartz_1.0.2
3    ACTIVE      org.ow2.easybeans.component.joram_1.0.2
4    ACTIVE      org.eclipse.equinox.log_1.1.0.v20080414
5    ACTIVE      org.ow2.easybeans.component.jdbcpool_1.0.2
6    ACTIVE      org.ow2.easybeans.component.hsqldb_1.0.2
7    ACTIVE      org.eclipse.equinox.util_1.0.0.v20080414
8    ACTIVE      org.ow2.easybeans.agent_1.0.2
9    <<LAZY>>    br.com.test_ezb_1.0.0
10    ACTIVE      org.ow2.easybeans.core_1.0.2
11    <<LAZY>>    br.com.test_ezb_invoke_1.0.0
12    ACTIVE      org.eclipse.osgi.source_3.4.0.v20080529-1200
13    ACTIVE      org.eclipse.equinox.common_3.4.0.v20080421-2006
14    ACTIVE      org.ow2.easybeans.component.carol_1.0.2
15    ACTIVE      org.ow2.easybeans.component.jotm_1.0.2
16    ACTIVE      org.ow2.bundles.ow2-bundles-externals-commons-logging_1.0.5
17    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20080427-0830
18    ACTIVE      org.eclipse.osgi.services_3.1.200.v20071203

osgi> start 9
29/10/08 15:22:45 (I) Activator.startContainer : Creating Container from the Bundle Archive 'bundleentry://9/'
29/10/08 15:22:46 (W) ContainerJNDIResolver.addJNDIName : Data already set for JNDIData[name=HelloBean, beanName=HelloBean] for the container URL bundleentry://9/.
29/10/08 15:22:46 (I) JContainer3.start : Container 'br.com.test_ezb' [1 SLSB, 0 SFSB, 0 MDB] started in 1.209 ms

osgi> INFO - 15:22:46 [S: null] - ServiceEvent REGISTERED.
INFO - 15:22:46 [B: br.com.test_ezb] - BundleEvent STARTED.
start 11
Hello World

osgi> INFO - 15:22:56 [B: br.com.test_ezb_invoke] - BundleEvent STARTED.

//----------------------------------------------------------------------------------------------------------------------------



Thanks and Regards
Fernando Freitas




Re: solution to the example!!

by Missias :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Freitas,

I followed his example and when I initiate bundle "br.com.test _ezb" I receive an exception, I am using the easybeans RC1 version. You can give me a hint?

----------------------< EXCEPTION >---------------------------
osgi> start 8
23/03/09 15:56:32 (I) Activator.startContainer : Creating Container from the Bundle Archive 'bundleentry://8.fwk20243707/'
23/03/09 15:56:32 (W) ServerJNDIResolver.removeContainerResolver : Cannot remove the given container resolver as it is not present.
org.osgi.framework.BundleException: Exception in org.ow2.easybeans.osgi.ejbjar.Activator.start() of bundle br.com.test_ezb.
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:830)
...
-----------------------

follows my console themselves View

-----------------< CONSOLE VIEW >----------------

osgi> 23/03/09 15:54:02 (W) Activator.start : Cannot find User configuration (easybeans.xml) for Easybeans. Using default configuration
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.bundles.ow2-util-event-impl_1.0.12 [12]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.bundles.ow2-util-jmx-impl_1.0.12 [23]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.easybeans.component.carol_1.1.0.RC1 [2]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.easybeans.component.quartz_1.1.0.RC1 [10]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.easybeans.component.jotm_1.1.0.RC1 [18]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.easybeans.component.joram_1.1.0.RC1 [4]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.easybeans.component.event_1.1.0.RC1 [11]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.easybeans.component.hsqldb_1.1.0.RC1 [7]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.easybeans.component.jdbcpool_1.1.0.RC1 [1]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle org.ow2.easybeans.core_1.1.0.RC1 [3]
23/03/09 15:54:06 (I) TraceCarol.infoCarol : Name service for jrmp is started on port 1099
23/03/09 15:54:07 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.carol.carolcomponent-1237834443937-2 created
23/03/09 15:54:07 (I) EZBCoreService.activate : Activating EasyBeans/OSGi/Core
23/03/09 15:54:08 (I) JMXRemoteHelper.init : Creating JMXRemote connector with URL 'service:jmx:rmi:///jndi/rmi://localhost:1099/EasyBeansConnector'
23/03/09 15:54:09 (I) Embedded.start : Startup of EasyBeans '1.1.0-RC1.0' was done in '1.282' ms.
23/03/09 15:54:09 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.event.eventcomponent-1237834443937-1 created
23/03/09 15:54:09 (I) HSQLDBComponent.start : Starting 'HSQLDB server' '1.8.0' on port '9002'
23/03/09 15:54:09 (I) HSQLDBComponent.start : HSQLDB server started with URL jdbc:hsqldb:hsql://localhost:9002/jdbc_2
23/03/09 15:54:09 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1237834443968-6 created
23/03/09 15:54:09 (I) HSQLDBComponent.start : Starting 'HSQLDB server' '1.8.0' on port '9001'
23/03/09 15:54:09 (I) HSQLDBComponent.start : HSQLDB server started with URL jdbc:hsqldb:hsql://localhost:9001/jdbc_1
23/03/09 15:54:09 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1237834443953-5 created
23/03/09 15:54:09 (I) QuartzScheduler.<init> : Quartz Scheduler v.1.6.0 created.
23/03/09 15:54:09 (I) RAMJobStore.initialize : RAMJobStore initialized.
23/03/09 15:54:09 (I) StdSchedulerFactory.instantiate : Quartz scheduler 'EasyBeans' initialized from an externally provided properties instance.
23/03/09 15:54:09 (I) StdSchedulerFactory.instantiate : Quartz scheduler version: 1.6.0
23/03/09 15:54:09 (I) QuartzScheduler.start : Scheduler EasyBeans_$_NON_CLUSTERED started.
23/03/09 15:54:09 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.quartz.quartzcomponent-1237834443859-0 created
23/03/09 15:54:09 (I) Jotm.<init> : JOTM started with a local transaction factory which is not bound.
23/03/09 15:54:09 (I) Jotm.<init> : CAROL initialization
23/03/09 15:54:10 (I) Current.<init> : JOTM 2.0.10
23/03/09 15:54:10 (I) JOTMComponent.start : Register javax.transaction.UserTransaction as transaction manager object
23/03/09 15:54:10 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.jotm.jotmcomponent-1237834443953-3 created
23/03/09 15:54:10 (I) JDBCPoolComponent.start : DS 'jdbc_2', URL 'jdbc:hsqldb:hsql://localhost:9002/jdbc_2', Driver = 'org.hsqldb.jdbcDriver'.
23/03/09 15:54:10 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1237834443984-9 created
23/03/09 15:54:10 (I) JDBCPoolComponent.start : DS 'jdbc_1', URL 'jdbc:hsqldb:hsql://localhost:9001/jdbc_1', Driver = 'org.hsqldb.jdbcDriver'.
23/03/09 15:54:10 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1237834443968-8 created
23/03/09 15:54:10 (I) JoramComponent.start : Joram version '5.2.1' started on localhost:16030. WorkManager[minTx=5,maxTx=100,txTimeout=60s]
23/03/09 15:54:10 (I) EZBComponentServiceFactory.updated : Component with pid org.ow2.easybeans.component.joram.joramcomponent-1237834443953-4 created
ss

Framework is launched.

id State       Bundle
0 ACTIVE      org.eclipse.osgi_3.5.0.v20090311-1300
1 ACTIVE      org.ow2.easybeans.component.jdbcpool_1.1.0.RC1
2 ACTIVE      org.ow2.easybeans.component.carol_1.1.0.RC1
3 ACTIVE      org.ow2.easybeans.core_1.1.0.RC1
4 ACTIVE      org.ow2.easybeans.component.joram_1.1.0.RC1
5 RESOLVED    org.ow2.bundles.ow2-bundles-externals-commons-logging_1.0.12
6 ACTIVE      org.ow2.easybeans.agent_1.1.0.RC1
7 ACTIVE      org.ow2.easybeans.component.hsqldb_1.1.0.RC1
8 <<LAZY>>    br.com.test_ezb_1.0.0
9 ACTIVE      org.eclipse.equinox.ds_1.1.0.v20090306-1900
10 ACTIVE      org.ow2.easybeans.component.quartz_1.1.0.RC1
11 ACTIVE      org.ow2.easybeans.component.event_1.1.0.RC1
12 ACTIVE      org.ow2.bundles.ow2-util-event-impl_1.0.12
13 ACTIVE      org.eclipse.equinox.common_3.5.0.v20090310-1800
14 RESOLVED    org.ow2.bundles.ow2-util-event-api_1.0.12
15 RESOLVED    org.ow2.bundles.ow2-bundles-externals-commons-modeler_1.0.12
16 RESOLVED    org.apache.felix.dependencymanager_1.1.0.10
17 ACTIVE      org.eclipse.equinox.log_1.1.0.v20090223-1400
18 ACTIVE      org.ow2.easybeans.component.jotm_1.1.0.RC1
19 <<LAZY>>    br.com.test_ezb_invoke_1.0.0
20 RESOLVED    org.ow2.bundles.ow2-util-jmx-api_1.0.12
21 ACTIVE      org.eclipse.equinox.util_1.0.100.v20090306-1900
22 ACTIVE      org.eclipse.osgi.services_3.2.0.v20090306-1900
23 ACTIVE      org.ow2.bundles.ow2-util-jmx-impl_1.0.12
24 RESOLVED    org.ow2.bundles.ow2-bundles-externals-slf4j-jcl_1.0.12
25 ACTIVE      org.eclipse.equinox.cm_1.0.100.v20090306-1900

------------------------------------------------------

Tanks,
Missias


Freitas wrote:
Hi ,
  I would like to send my example to help those who are starting with
easybeans. I've used a EZB + EJB on OSGI Equinox .
This sample includes a HelloWorld example containing an SLSB and a client
for invocation.

This example was only possible with EkkeHard Gentz's help.

 Thanks Ekke!

//--------------------------------------------------------------------
Step 1

Follow the sequence of the blog of Ekke.

I've used a easybeans_target_minimal

http://ekkes-corner.blogspot.com/2008/06/easybeans-und-equinox.html

//------------------------------------------------------------------------

Step 2

Create two bundle/plugin projects:

ex..

br.com.test_ezb
    and
br.com.test_ezb_invoke

//-------------------------------------------------------------------------

  br.com.test_ezb

//----- Interface EJB

package br.com.test_ezb;

import javax.ejb.Local;
import javax.ejb.Remote;

@Local
@Remote
public interface Hello{
        public String sayHello(String str);
}

//--- Stateless EJB

package br.com.test_ezb;

import javax.ejb.Stateless;

@Stateless(mappedName="HelloBean")
public class HelloBean implements Hello{
        public String sayHello(String str){
                return str;
        }
}



//---Manifest

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test_ezb3 Plug-in
Bundle-SymbolicName: br.com.test_ezb
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Activator:  org.ow2.easybeans.osgi.ejbjar.Activator
Bundle-ActivationPolicy: lazy
Import-Package:  javax.ejb , org.ow2.easybeans.osgi.ejbjar ,
javax.annotation
Export-Package: br.com.test_ezb



//This bundle must have this Activator
org.ow2.easybeans.osgi.ejbjar.Activator

//----------------------------------------------------------------------------------

br.com.test_ezb_invoke


//For this bundle to work, you must add in your easybeans_targed_minimal
//this bundle  org.eclipse.osgi.source_3.4.0


//This bundle should have this Activator.

package br.com.test_ezb_invoke;

import javax.naming.Context;
import javax.naming.NamingException;
import java.util.Hashtable;
import javax.naming.InitialContext;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;


import br.com.test_ezb.Hello;

public class Activator implements BundleActivator {


      private static final String DEFAULT_INITIAL_CONTEXT_FACTORY =
"org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory";


      private Hello hello = null;

      private static Context getInitialContext() throws NamingException {

            Hashtable<String, Object> env = new Hashtable<String, Object>();
            env.put(Context.INITIAL_CONTEXT_FACTORY,
DEFAULT_INITIAL_CONTEXT_FACTORY);
            return new InitialContext(env);}


    /*
     * (non-Javadoc)
     * @see
org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
     */
    public void start(BundleContext context) throws Exception {


        Context initialContext = getInitialContext();
        hello = (Hello) initialContext.lookup("HelloBean");
        System.out.println(hello.sayHello("Hello World"));

    }

    /*
     * (non-Javadoc)
     * @see
org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     */
    public void stop(BundleContext context) throws Exception {
    }

}

//--- manifest

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test_ezb_ivk2 Plug-in
Bundle-SymbolicName: br.com.test_ezb_invoke
Bundle-Version: 1.0.0
Bundle-Activator: br.com.test_ezb_invoke.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.osgi.framework;version="1.3.0", javax.ejb,
br.com.test_ezb, org.objectweb.carol.jndi.spi


//----------------------------------------------------

Step 3

 before your code is running you must be sure:
1) that EZB initializes all well
2) the EZB agent must be finished
3) and also Hibernate must be finsihed initiliazing

Console View



osgi> 29/10/08 15:22:09 (W) Activator.start : Cannot find User configuration
(easybeans.xml) for Easybeans. Using default configuration
29/10/08 15:22:11 (I) Activator.start : Starting Bundle
initial@reference:file:easybeans-component-carol_1.0.2.jar/
[14]
29/10/08 15:22:12 (I) Activator.start : Starting Bundle
initial@reference:file:easybeans-component-jotm_1.0.2.jar/
[15]
INFO - 15:22:12 [B: org.ow2.easybeans.component.carol] - BundleEvent
STARTED.
INFO - 15:22:12 [B: org.ow2.easybeans.component.jotm] - BundleEvent STARTED.
29/10/08 15:22:12 (I) Activator.start : Starting Bundle
initial@reference:file:easybeans-component-quartz_1.0.2.jar/
[2]
INFO - 15:22:12 [B: org.ow2.easybeans.component.quartz] - BundleEvent
STARTED.
29/10/08 15:22:12 (I) Activator.start : Starting Bundle
initial@reference:file:easybeans-component-hsqldb_1.0.2.jar/
[6]
INFO - 15:22:12 [B: org.ow2.easybeans.component.hsqldb] - BundleEvent
STARTED.
29/10/08 15:22:12 (I) Activator.start : Starting Bundle
initial@reference:file:easybeans-core_1.0.2.jar/
[10]
29/10/08 15:22:12 (I) Activator.start : Starting Bundle
initial@reference:file:easybeans-component-joram_1.0.2.jar/
[3]
INFO - 15:22:12 [B: org.ow2.easybeans.core] - BundleEvent STARTED.
29/10/08 15:22:12 (I) Activator.start : Starting Bundle
initial@reference:file:easybeans-component-jdbcpool_1.0.2.jar/
[5]
INFO - 15:22:12 [B: org.ow2.easybeans.component.joram] - BundleEvent
STARTED.
INFO - 15:22:12 [B: org.ow2.easybeans.component.jdbcpool] - BundleEvent
STARTED.
INFO - 15:22:12 [B: org.ow2.easybeans.agent] - BundleEvent STARTED.
INFO - 15:22:12 [S: org.ow2.easybeans.component.carol.carolcomponent] -
ServiceEvent REGISTERED.
INFO - 15:22:12 [B: org.eclipse.osgi] - FrameworkEvent STARTLEVEL CHANGED.
INFO - 15:22:12 [S: org.ow2.easybeans.component.hsqldb.hsqldbcomponent] -
ServiceEvent REGISTERED.
29/10/08 15:22:12 (I) TraceCarol.infoCarol : Name service for jrmp is
started on port 1099
INFO - 15:22:13 [S:
org.ow2.easybeans.component.carol.carolcomponent-1225300931396-1] -
ServiceEvent REGISTERED.
INFO - 15:22:13 [S: org.ow2.easybeans.component.jotm.jotmcomponent] -
ServiceEvent REGISTERED.
INFO - 15:22:13 [S: org.ow2.easybeans.component.quartz.quartzcomponent] -
ServiceEvent REGISTERED.
INFO - 15:22:13 [S: org.ow2.easybeans.core] - ServiceEvent REGISTERED.
29/10/08 15:22:13 (I) EZBCoreService.activate : Activating
EasyBeans/OSGi/Core
29/10/08 15:22:13 (I) PolicyProvider.init : Using EasyBeans policy provider
'org.ow2.easybeans.security.jacc.provider.JPolicy'.
29/10/08 15:22:13 (I) PolicyProvider.init : Using EasyBeans
PolicyConfigurationFactory provider and EasyBeans Policy provider
29/10/08 15:22:14 (I) JMXRemoteHelper.init : Creating JMXRemote connector
with URL 'service:jmx:rmi:///jndi/rmi://localhost:1099/EasyBeansConnector'
29/10/08 15:22:14 (I) Embedded.start : Startup of EasyBeans '1.0.2' was done
in '1.017' ms.
INFO - 15:22:14 [S: null] - ServiceEvent REGISTERED.
29/10/08 15:22:14 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.carol.carolcomponent-1225300931396-1 created
INFO - 15:22:14 [S: org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent]
- ServiceEvent REGISTERED.
29/10/08 15:22:14 (I) HSQLDBComponent.start : Starting 'HSQLDB server'
'1.8.0' on port '9002'
29/10/08 15:22:15 (I) HSQLDBComponent.start : HSQLDB server started with URL
jdbc:hsqldb:hsql://localhost:9002/jdbc_2
INFO - 15:22:15 [S:
org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931643-5] -
ServiceEvent REGISTERED.
29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931643-5
created
29/10/08 15:22:15 (I) HSQLDBComponent.start : Starting 'HSQLDB server'
'1.8.0' on port '9001'
29/10/08 15:22:15 (I) HSQLDBComponent.start : HSQLDB server started with URL
jdbc:hsqldb:hsql://localhost:9001/jdbc_1
INFO - 15:22:15 [S:
org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931600-4] -
ServiceEvent REGISTERED.
29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931600-4
created
29/10/08 15:22:15 (I) Current.<init> : JOTM 2.0.10
29/10/08 15:22:15 (I) JOTMComponent.start : Register
javax.transaction.UserTransaction as transaction manager object
INFO - 15:22:15 [S:
org.ow2.easybeans.component.jotm.jotmcomponent-1225300931470-2] -
ServiceEvent REGISTERED.
INFO - 15:22:15 [S: org.ow2.easybeans.component.joram.joramcomponent] -
ServiceEvent REGISTERED.
29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.jotm.jotmcomponent-1225300931470-2 created
29/10/08 15:22:16 (I) QuartzScheduler.<init> : Quartz Scheduler v.1.6.0
created.
29/10/08 15:22:16 (I) RAMJobStore.initialize : RAMJobStore initialized.
29/10/08 15:22:16 (I) StdSchedulerFactory.instantiate : Quartz scheduler
'EasyBeans' initialized from an externally provided properties instance.
29/10/08 15:22:16 (I) StdSchedulerFactory.instantiate : Quartz scheduler
version: 1.6.0
29/10/08 15:22:16 (I) QuartzScheduler.start : Scheduler
EasyBeans_$_NON_CLUSTERED started.
INFO - 15:22:16 [S:
org.ow2.easybeans.component.quartz.quartzcomponent-1225300930552-0] -
ServiceEvent REGISTERED.
29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.quartz.quartzcomponent-1225300930552-0
created
29/10/08 15:22:16 (I) JDBCPoolComponent.start : DS 'jdbc_1', URL
'jdbc:hsqldb:hsql://localhost:9001/jdbc_1', Driver =
'org.hsqldb.jdbcDriver'.
INFO - 15:22:16 [S:
org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931753-7] -
ServiceEvent REGISTERED.
29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931753-7
created
29/10/08 15:22:16 (I) JDBCPoolComponent.start : DS 'jdbc_2', URL
'jdbc:hsqldb:hsql://localhost:9002/jdbc_2', Driver =
'org.hsqldb.jdbcDriver'.
INFO - 15:22:16 [S:
org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931796-8] -
ServiceEvent REGISTERED.
29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931796-8
created
29/10/08 15:22:17 (I) JoramComponent.start : Joram version '5.0.9' started
on localhost:16030. WorkManager[minTx=5,maxTx=100,txTimeout=60s]
INFO - 15:22:17 [S:
org.ow2.easybeans.component.joram.joramcomponent-1225300931532-3] -
ServiceEvent REGISTERED.
29/10/08 15:22:17 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.joram.joramcomponent-1225300931532-3 created
ss

Framework is launched.

id    State       Bundle
0    ACTIVE      org.eclipse.osgi_3.4.0.v20080529-1200
1    ACTIVE      org.eclipse.equinox.cm_1.0.0.v20080509-1800
2    ACTIVE      org.ow2.easybeans.component.quartz_1.0.2
3    ACTIVE      org.ow2.easybeans.component.joram_1.0.2
4    ACTIVE      org.eclipse.equinox.log_1.1.0.v20080414
5    ACTIVE      org.ow2.easybeans.component.jdbcpool_1.0.2
6    ACTIVE      org.ow2.easybeans.component.hsqldb_1.0.2
7    ACTIVE      org.eclipse.equinox.util_1.0.0.v20080414
8    ACTIVE      org.ow2.easybeans.agent_1.0.2
9    <<LAZY>>    br.com.test_ezb_1.0.0
10    ACTIVE      org.ow2.easybeans.core_1.0.2
11    <<LAZY>>    br.com.test_ezb_invoke_1.0.0
12    ACTIVE      org.eclipse.osgi.source_3.4.0.v20080529-1200
13    ACTIVE      org.eclipse.equinox.common_3.4.0.v20080421-2006
14    ACTIVE      org.ow2.easybeans.component.carol_1.0.2
15    ACTIVE      org.ow2.easybeans.component.jotm_1.0.2
16    ACTIVE
org.ow2.bundles.ow2-bundles-externals-commons-logging_1.0.5
17    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20080427-0830
18    ACTIVE      org.eclipse.osgi.services_3.1.200.v20071203

osgi> start 9
29/10/08 15:22:45 (I) Activator.startContainer : Creating Container from the
Bundle Archive 'bundleentry://9/'
29/10/08 15:22:46 (W) ContainerJNDIResolver.addJNDIName : Data already set
for JNDIData[name=HelloBean, beanName=HelloBean] for the container URL
bundleentry://9/.
29/10/08 15:22:46 (I) JContainer3.start : Container 'br.com.test_ezb' [1
SLSB, 0 SFSB, 0 MDB] started in 1.209 ms

osgi> INFO - 15:22:46 [S: null] - ServiceEvent REGISTERED.
INFO - 15:22:46 [B: br.com.test_ezb] - BundleEvent STARTED.
start 11
Hello World

osgi> INFO - 15:22:56 [B: br.com.test_ezb_invoke] - BundleEvent STARTED.

//----------------------------------------------------------------------------------------------------------------------------



Thanks and Regards
Fernando Freitas

Re: Re: solution to the example!!

by Freitas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Missias, 
        In this example I used easybeans version 1.0.2. Follow the Ekke's blog. You should to use the same versions.

Best Regards
Fernando

2009/3/23 Missias <josecarlosmissias@...>

Hi Freitas,

I followed his example and when I initiate bundle "br.com.test _ezb" I
receive an exception, I am using the easybeans RC1 version. You can give me
a hint?

----------------------< EXCEPTION >---------------------------
osgi> start 8
23/03/09 15:56:32 (I) Activator.startContainer : Creating Container from the
Bundle Archive 'bundleentry://8.fwk20243707/'
23/03/09 15:56:32 (W) ServerJNDIResolver.removeContainerResolver : Cannot
remove the given container resolver as it is not present.
org.osgi.framework.BundleException: Exception in
org.ow2.easybeans.osgi.ejbjar.Activator.start() of bundle br.com.test_ezb.
       at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:830)
...
-----------------------

follows my console themselves View

-----------------< CONSOLE VIEW >----------------

osgi> 23/03/09 15:54:02 (W) Activator.start : Cannot find User configuration
(easybeans.xml) for Easybeans. Using default configuration
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.bundles.ow2-util-event-impl_1.0.12 [12]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.bundles.ow2-util-jmx-impl_1.0.12 [23]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.easybeans.component.carol_1.1.0.RC1 [2]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.easybeans.component.quartz_1.1.0.RC1 [10]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.easybeans.component.jotm_1.1.0.RC1 [18]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.easybeans.component.joram_1.1.0.RC1 [4]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.easybeans.component.event_1.1.0.RC1 [11]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.easybeans.component.hsqldb_1.1.0.RC1 [7]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.easybeans.component.jdbcpool_1.1.0.RC1 [1]
23/03/09 15:54:04 (I) Activator.start : Starting Bundle
org.ow2.easybeans.core_1.1.0.RC1 [3]
23/03/09 15:54:06 (I) TraceCarol.infoCarol : Name service for jrmp is
started on port 1099
23/03/09 15:54:07 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.carol.carolcomponent-1237834443937-2 created
23/03/09 15:54:07 (I) EZBCoreService.activate : Activating
EasyBeans/OSGi/Core
23/03/09 15:54:08 (I) JMXRemoteHelper.init : Creating JMXRemote connector
with URL 'service:jmx:rmi:///jndi/rmi://localhost:1099/EasyBeansConnector'
23/03/09 15:54:09 (I) Embedded.start : Startup of EasyBeans '1.1.0-RC1.0'
was done in '1.282' ms.
23/03/09 15:54:09 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.event.eventcomponent-1237834443937-1 created
23/03/09 15:54:09 (I) HSQLDBComponent.start : Starting 'HSQLDB server'
'1.8.0' on port '9002'
23/03/09 15:54:09 (I) HSQLDBComponent.start : HSQLDB server started with URL
jdbc:hsqldb:hsql://localhost:9002/jdbc_2
23/03/09 15:54:09 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1237834443968-6
created
23/03/09 15:54:09 (I) HSQLDBComponent.start : Starting 'HSQLDB server'
'1.8.0' on port '9001'
23/03/09 15:54:09 (I) HSQLDBComponent.start : HSQLDB server started with URL
jdbc:hsqldb:hsql://localhost:9001/jdbc_1
23/03/09 15:54:09 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1237834443953-5
created
23/03/09 15:54:09 (I) QuartzScheduler.<init> : Quartz Scheduler v.1.6.0
created.
23/03/09 15:54:09 (I) RAMJobStore.initialize : RAMJobStore initialized.
23/03/09 15:54:09 (I) StdSchedulerFactory.instantiate : Quartz scheduler
'EasyBeans' initialized from an externally provided properties instance.
23/03/09 15:54:09 (I) StdSchedulerFactory.instantiate : Quartz scheduler
version: 1.6.0
23/03/09 15:54:09 (I) QuartzScheduler.start : Scheduler
EasyBeans_$_NON_CLUSTERED started.
23/03/09 15:54:09 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.quartz.quartzcomponent-1237834443859-0
created
23/03/09 15:54:09 (I) Jotm.<init> : JOTM started with a local transaction
factory which is not bound.
23/03/09 15:54:09 (I) Jotm.<init> : CAROL initialization
23/03/09 15:54:10 (I) Current.<init> : JOTM 2.0.10
23/03/09 15:54:10 (I) JOTMComponent.start : Register
javax.transaction.UserTransaction as transaction manager object
23/03/09 15:54:10 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.jotm.jotmcomponent-1237834443953-3 created
23/03/09 15:54:10 (I) JDBCPoolComponent.start : DS 'jdbc_2', URL
'jdbc:hsqldb:hsql://localhost:9002/jdbc_2', Driver =
'org.hsqldb.jdbcDriver'.
23/03/09 15:54:10 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1237834443984-9
created
23/03/09 15:54:10 (I) JDBCPoolComponent.start : DS 'jdbc_1', URL
'jdbc:hsqldb:hsql://localhost:9001/jdbc_1', Driver =
'org.hsqldb.jdbcDriver'.
23/03/09 15:54:10 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1237834443968-8
created
23/03/09 15:54:10 (I) JoramComponent.start : Joram version '5.2.1' started
on localhost:16030. WorkManager[minTx=5,maxTx=100,txTimeout=60s]
23/03/09 15:54:10 (I) EZBComponentServiceFactory.updated : Component with
pid org.ow2.easybeans.component.joram.joramcomponent-1237834443953-4 created
ss

Framework is launched.

id      State       Bundle
0       ACTIVE      org.eclipse.osgi_3.5.0.v20090311-1300
1       ACTIVE      org.ow2.easybeans.component.jdbcpool_1.1.0.RC1
2       ACTIVE      org.ow2.easybeans.component.carol_1.1.0.RC1
3       ACTIVE      org.ow2.easybeans.core_1.1.0.RC1
4       ACTIVE      org.ow2.easybeans.component.joram_1.1.0.RC1
5       RESOLVED    org.ow2.bundles.ow2-bundles-externals-commons-logging_1.0.12
6       ACTIVE      org.ow2.easybeans.agent_1.1.0.RC1
7       ACTIVE      org.ow2.easybeans.component.hsqldb_1.1.0.RC1
8       <<LAZY>>    br.com.test_ezb_1.0.0
9       ACTIVE      org.eclipse.equinox.ds_1.1.0.v20090306-1900
10      ACTIVE      org.ow2.easybeans.component.quartz_1.1.0.RC1
11      ACTIVE      org.ow2.easybeans.component.event_1.1.0.RC1
12      ACTIVE      org.ow2.bundles.ow2-util-event-impl_1.0.12
13      ACTIVE      org.eclipse.equinox.common_3.5.0.v20090310-1800
14      RESOLVED    org.ow2.bundles.ow2-util-event-api_1.0.12
15      RESOLVED    org.ow2.bundles.ow2-bundles-externals-commons-modeler_1.0.12
16      RESOLVED    org.apache.felix.dependencymanager_1.1.0.10
17      ACTIVE      org.eclipse.equinox.log_1.1.0.v20090223-1400
18      ACTIVE      org.ow2.easybeans.component.jotm_1.1.0.RC1
19      <<LAZY>>    br.com.test_ezb_invoke_1.0.0
20      RESOLVED    org.ow2.bundles.ow2-util-jmx-api_1.0.12
21      ACTIVE      org.eclipse.equinox.util_1.0.100.v20090306-1900
22      ACTIVE      org.eclipse.osgi.services_3.2.0.v20090306-1900
23      ACTIVE      org.ow2.bundles.ow2-util-jmx-impl_1.0.12
24      RESOLVED    org.ow2.bundles.ow2-bundles-externals-slf4j-jcl_1.0.12
25      ACTIVE      org.eclipse.equinox.cm_1.0.100.v20090306-1900

------------------------------------------------------

Tanks,
Missias



Freitas wrote:
>
> Hi ,
>   I would like to send my example to help those who are starting with
> easybeans. I've used a EZB + EJB on OSGI Equinox .
> This sample includes a HelloWorld example containing an SLSB and a client
> for invocation.
>
> This example was only possible with EkkeHard Gentz's help.
>
>  Thanks Ekke!
>
> //--------------------------------------------------------------------
> Step 1
>
> Follow the sequence of the blog of Ekke.
>
> I've used a easybeans_target_minimal
>
> http://ekkes-corner.blogspot.com/2008/06/easybeans-und-equinox.html
>
> //------------------------------------------------------------------------
>
> Step 2
>
> Create two bundle/plugin projects:
>
> ex..
>
> br.com.test_ezb
>     and
> br.com.test_ezb_invoke
>
> //-------------------------------------------------------------------------
>
>   br.com.test_ezb
>
> //----- Interface EJB
>
> package br.com.test_ezb;
>
> import javax.ejb.Local;
> import javax.ejb.Remote;
>
> @Local
> @Remote
> public interface Hello{
>         public String sayHello(String str);
> }
>
> //--- Stateless EJB
>
> package br.com.test_ezb;
>
> import javax.ejb.Stateless;
>
> @Stateless(mappedName="HelloBean")
> public class HelloBean implements Hello{
>         public String sayHello(String str){
>                 return str;
>         }
> }
>
>
>
> //---Manifest
>
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: Test_ezb3 Plug-in
> Bundle-SymbolicName: br.com.test_ezb
> Bundle-Version: 1.0.0
> Bundle-RequiredExecutionEnvironment: J2SE-1.5
> Bundle-Activator:  org.ow2.easybeans.osgi.ejbjar.Activator
> Bundle-ActivationPolicy: lazy
> Import-Package:  javax.ejb , org.ow2.easybeans.osgi.ejbjar ,
> javax.annotation
> Export-Package: br.com.test_ezb
>
>
>
> //This bundle must have this Activator
> org.ow2.easybeans.osgi.ejbjar.Activator
>
> //----------------------------------------------------------------------------------
>
> br.com.test_ezb_invoke
>
>
> //For this bundle to work, you must add in your easybeans_targed_minimal
> //this bundle  org.eclipse.osgi.source_3.4.0
>
>
> //This bundle should have this Activator.
>
> package br.com.test_ezb_invoke;
>
> import javax.naming.Context;
> import javax.naming.NamingException;
> import java.util.Hashtable;
> import javax.naming.InitialContext;
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
>
>
> import br.com.test_ezb.Hello;
>
> public class Activator implements BundleActivator {
>
>
>       private static final String DEFAULT_INITIAL_CONTEXT_FACTORY =
> "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory";
>
>
>       private Hello hello = null;
>
>       private static Context getInitialContext() throws NamingException {
>
>             Hashtable<String, Object> env = new Hashtable<String,
> Object>();
>             env.put(Context.INITIAL_CONTEXT_FACTORY,
> DEFAULT_INITIAL_CONTEXT_FACTORY);
>             return new InitialContext(env);}
>
>
>     /*
>      * (non-Javadoc)
>      * @see
> org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
>      */
>     public void start(BundleContext context) throws Exception {
>
>
>         Context initialContext = getInitialContext();
>         hello = (Hello) initialContext.lookup("HelloBean");
>         System.out.println(hello.sayHello("Hello World"));
>
>     }
>
>     /*
>      * (non-Javadoc)
>      * @see
> org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
>      */
>     public void stop(BundleContext context) throws Exception {
>     }
>
> }
>
> //--- manifest
>
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: Test_ezb_ivk2 Plug-in
> Bundle-SymbolicName: br.com.test_ezb_invoke
> Bundle-Version: 1.0.0
> Bundle-Activator: br.com.test_ezb_invoke.Activator
> Bundle-ActivationPolicy: lazy
> Bundle-RequiredExecutionEnvironment: J2SE-1.5
> Import-Package: org.osgi.framework;version="1.3.0", javax.ejb,
> br.com.test_ezb, org.objectweb.carol.jndi.spi
>
>
> //----------------------------------------------------
>
> Step 3
>
>  before your code is running you must be sure:
> 1) that EZB initializes all well
> 2) the EZB agent must be finished
> 3) and also Hibernate must be finsihed initiliazing
>
> Console View
>
>
>
> osgi> 29/10/08 15:22:09 (W) Activator.start : Cannot find User
> configuration
> (easybeans.xml) for Easybeans. Using default configuration
> 29/10/08 15:22:11 (I) Activator.start : Starting Bundle
> initial@reference:file:easybeans-component-carol_1.0.2.jar/
> [14]
> 29/10/08 15:22:12 (I) Activator.start : Starting Bundle
> initial@reference:file:easybeans-component-jotm_1.0.2.jar/
> [15]
> INFO - 15:22:12 [B: org.ow2.easybeans.component.carol] - BundleEvent
> STARTED.
> INFO - 15:22:12 [B: org.ow2.easybeans.component.jotm] - BundleEvent
> STARTED.
> 29/10/08 15:22:12 (I) Activator.start : Starting Bundle
> initial@reference:file:easybeans-component-quartz_1.0.2.jar/
> [2]
> INFO - 15:22:12 [B: org.ow2.easybeans.component.quartz] - BundleEvent
> STARTED.
> 29/10/08 15:22:12 (I) Activator.start : Starting Bundle
> initial@reference:file:easybeans-component-hsqldb_1.0.2.jar/
> [6]
> INFO - 15:22:12 [B: org.ow2.easybeans.component.hsqldb] - BundleEvent
> STARTED.
> 29/10/08 15:22:12 (I) Activator.start : Starting Bundle
> initial@reference:file:easybeans-core_1.0.2.jar/
> [10]
> 29/10/08 15:22:12 (I) Activator.start : Starting Bundle
> initial@reference:file:easybeans-component-joram_1.0.2.jar/
> [3]
> INFO - 15:22:12 [B: org.ow2.easybeans.core] - BundleEvent STARTED.
> 29/10/08 15:22:12 (I) Activator.start : Starting Bundle
> initial@reference:file:easybeans-component-jdbcpool_1.0.2.jar/
> [5]
> INFO - 15:22:12 [B: org.ow2.easybeans.component.joram] - BundleEvent
> STARTED.
> INFO - 15:22:12 [B: org.ow2.easybeans.component.jdbcpool] - BundleEvent
> STARTED.
> INFO - 15:22:12 [B: org.ow2.easybeans.agent] - BundleEvent STARTED.
> INFO - 15:22:12 [S: org.ow2.easybeans.component.carol.carolcomponent] -
> ServiceEvent REGISTERED.
> INFO - 15:22:12 [B: org.eclipse.osgi] - FrameworkEvent STARTLEVEL CHANGED.
> INFO - 15:22:12 [S: org.ow2.easybeans.component.hsqldb.hsqldbcomponent] -
> ServiceEvent REGISTERED.
> 29/10/08 15:22:12 (I) TraceCarol.infoCarol : Name service for jrmp is
> started on port 1099
> INFO - 15:22:13 [S:
> org.ow2.easybeans.component.carol.carolcomponent-1225300931396-1] -
> ServiceEvent REGISTERED.
> INFO - 15:22:13 [S: org.ow2.easybeans.component.jotm.jotmcomponent] -
> ServiceEvent REGISTERED.
> INFO - 15:22:13 [S: org.ow2.easybeans.component.quartz.quartzcomponent] -
> ServiceEvent REGISTERED.
> INFO - 15:22:13 [S: org.ow2.easybeans.core] - ServiceEvent REGISTERED.
> 29/10/08 15:22:13 (I) EZBCoreService.activate : Activating
> EasyBeans/OSGi/Core
> 29/10/08 15:22:13 (I) PolicyProvider.init : Using EasyBeans policy
> provider
> 'org.ow2.easybeans.security.jacc.provider.JPolicy'.
> 29/10/08 15:22:13 (I) PolicyProvider.init : Using EasyBeans
> PolicyConfigurationFactory provider and EasyBeans Policy provider
> 29/10/08 15:22:14 (I) JMXRemoteHelper.init : Creating JMXRemote connector
> with URL 'service:jmx:rmi:///jndi/rmi://localhost:1099/EasyBeansConnector'
> 29/10/08 15:22:14 (I) Embedded.start : Startup of EasyBeans '1.0.2' was
> done
> in '1.017' ms.
> INFO - 15:22:14 [S: null] - ServiceEvent REGISTERED.
> 29/10/08 15:22:14 (I) EZBComponentServiceFactory.updated : Component with
> pid org.ow2.easybeans.component.carol.carolcomponent-1225300931396-1
> created
> INFO - 15:22:14 [S:
> org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent]
> - ServiceEvent REGISTERED.
> 29/10/08 15:22:14 (I) HSQLDBComponent.start : Starting 'HSQLDB server'
> '1.8.0' on port '9002'
> 29/10/08 15:22:15 (I) HSQLDBComponent.start : HSQLDB server started with
> URL
> jdbc:hsqldb:hsql://localhost:9002/jdbc_2
> INFO - 15:22:15 [S:
> org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931643-5] -
> ServiceEvent REGISTERED.
> 29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with
> pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931643-5
> created
> 29/10/08 15:22:15 (I) HSQLDBComponent.start : Starting 'HSQLDB server'
> '1.8.0' on port '9001'
> 29/10/08 15:22:15 (I) HSQLDBComponent.start : HSQLDB server started with
> URL
> jdbc:hsqldb:hsql://localhost:9001/jdbc_1
> INFO - 15:22:15 [S:
> org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931600-4] -
> ServiceEvent REGISTERED.
> 29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with
> pid org.ow2.easybeans.component.hsqldb.hsqldbcomponent-1225300931600-4
> created
> 29/10/08 15:22:15 (I) Current.<init> : JOTM 2.0.10
> 29/10/08 15:22:15 (I) JOTMComponent.start : Register
> javax.transaction.UserTransaction as transaction manager object
> INFO - 15:22:15 [S:
> org.ow2.easybeans.component.jotm.jotmcomponent-1225300931470-2] -
> ServiceEvent REGISTERED.
> INFO - 15:22:15 [S: org.ow2.easybeans.component.joram.joramcomponent] -
> ServiceEvent REGISTERED.
> 29/10/08 15:22:15 (I) EZBComponentServiceFactory.updated : Component with
> pid org.ow2.easybeans.component.jotm.jotmcomponent-1225300931470-2 created
> 29/10/08 15:22:16 (I) QuartzScheduler.<init> : Quartz Scheduler v.1.6.0
> created.
> 29/10/08 15:22:16 (I) RAMJobStore.initialize : RAMJobStore initialized.
> 29/10/08 15:22:16 (I) StdSchedulerFactory.instantiate : Quartz scheduler
> 'EasyBeans' initialized from an externally provided properties instance.
> 29/10/08 15:22:16 (I) StdSchedulerFactory.instantiate : Quartz scheduler
> version: 1.6.0
> 29/10/08 15:22:16 (I) QuartzScheduler.start : Scheduler
> EasyBeans_$_NON_CLUSTERED started.
> INFO - 15:22:16 [S:
> org.ow2.easybeans.component.quartz.quartzcomponent-1225300930552-0] -
> ServiceEvent REGISTERED.
> 29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with
> pid org.ow2.easybeans.component.quartz.quartzcomponent-1225300930552-0
> created
> 29/10/08 15:22:16 (I) JDBCPoolComponent.start : DS 'jdbc_1', URL
> 'jdbc:hsqldb:hsql://localhost:9001/jdbc_1', Driver =
> 'org.hsqldb.jdbcDriver'.
> INFO - 15:22:16 [S:
> org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931753-7] -
> ServiceEvent REGISTERED.
> 29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with
> pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931753-7
> created
> 29/10/08 15:22:16 (I) JDBCPoolComponent.start : DS 'jdbc_2', URL
> 'jdbc:hsqldb:hsql://localhost:9002/jdbc_2', Driver =
> 'org.hsqldb.jdbcDriver'.
> INFO - 15:22:16 [S:
> org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931796-8] -
> ServiceEvent REGISTERED.
> 29/10/08 15:22:16 (I) EZBComponentServiceFactory.updated : Component with
> pid org.ow2.easybeans.component.jdbcpool.jdbcpoolcomponent-1225300931796-8
> created
> 29/10/08 15:22:17 (I) JoramComponent.start : Joram version '5.0.9' started
> on localhost:16030. WorkManager[minTx=5,maxTx=100,txTimeout=60s]
> INFO - 15:22:17 [S:
> org.ow2.easybeans.component.joram.joramcomponent-1225300931532-3] -
> ServiceEvent REGISTERED.
> 29/10/08 15:22:17 (I) EZBComponentServiceFactory.updated : Component with
> pid org.ow2.easybeans.component.joram.joramcomponent-1225300931532-3
> created
> ss
>
> Framework is launched.
>
> id    State       Bundle
> 0    ACTIVE      org.eclipse.osgi_3.4.0.v20080529-1200
> 1    ACTIVE      org.eclipse.equinox.cm_1.0.0.v20080509-1800
> 2    ACTIVE      org.ow2.easybeans.component.quartz_1.0.2
> 3    ACTIVE      org.ow2.easybeans.component.joram_1.0.2
> 4    ACTIVE      org.eclipse.equinox.log_1.1.0.v20080414
> 5    ACTIVE      org.ow2.easybeans.component.jdbcpool_1.0.2
> 6    ACTIVE      org.ow2.easybeans.component.hsqldb_1.0.2
> 7    ACTIVE      org.eclipse.equinox.util_1.0.0.v20080414
> 8    ACTIVE      org.ow2.easybeans.agent_1.0.2
> 9    <<LAZY>>    br.com.test_ezb_1.0.0
> 10    ACTIVE      org.ow2.easybeans.core_1.0.2
> 11    <<LAZY>>    br.com.test_ezb_invoke_1.0.0
> 12    ACTIVE      org.eclipse.osgi.source_3.4.0.v20080529-1200
> 13    ACTIVE      org.eclipse.equinox.common_3.4.0.v20080421-2006
> 14    ACTIVE      org.ow2.easybeans.component.carol_1.0.2
> 15    ACTIVE      org.ow2.easybeans.component.jotm_1.0.2
> 16    ACTIVE
> org.ow2.bundles.ow2-bundles-externals-commons-logging_1.0.5
> 17    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20080427-0830
> 18    ACTIVE      org.eclipse.osgi.services_3.1.200.v20071203
>
> osgi> start 9
> 29/10/08 15:22:45 (I) Activator.startContainer : Creating Container from
> the
> Bundle Archive 'bundleentry://9/'
> 29/10/08 15:22:46 (W) ContainerJNDIResolver.addJNDIName : Data already set
> for JNDIData[name=HelloBean, beanName=HelloBean] for the container URL
> bundleentry://9/.
> 29/10/08 15:22:46 (I) JContainer3.start : Container 'br.com.test_ezb' [1
> SLSB, 0 SFSB, 0 MDB] started in 1.209 ms
>
> osgi> INFO - 15:22:46 [S: null] - ServiceEvent REGISTERED.
> INFO - 15:22:46 [B: br.com.test_ezb] - BundleEvent STARTED.
> start 11
> Hello World
>
> osgi> INFO - 15:22:56 [B: br.com.test_ezb_invoke] - BundleEvent STARTED.
>
> //----------------------------------------------------------------------------------------------------------------------------
>
>
>
> Thanks and Regards
> Fernando Freitas
>
>

--
View this message in context: http://www.nabble.com/solution-to-the-example%21%21-tp20232716p22667038.html
Sent from the EasyBeans-user mailing list archive at Nabble.com.