Re: OpenEJB and OSGi

2009-05-10 Thread Jonathan Gallimore
Hi

Sorry for the delay. I've had a bit of a play around and created a sample
Equinox directory with the bundles needed for OpenEJB, and added some basic
instructions to the Wiki. The sample zip is available from
http://people.apache.org/~jgallimore/openejb-osgi.zip and the source code is
available from http://people.apache.org/~jgallimore/projects.zip

The page I added to the Wiki is here:
http://cwiki.apache.org/confluence/x/qMkB - please let me know if you have
any comments.

To build the projects I pointed you at, you'll need to run Maven at the
openejb-eclipse-plugin level the first time, this will go an download the
necessary Eclipse projects and add these to your local Maven repository.

Issuing the following at the openejb-eclipse-plugin level should work and do
what you're after:

mvn -Dassemble clean install eclipse:clean eclipse:eclipse

See here:
http://cwiki.apache.org/confluence/display/OPENEJB/Building+from+source for
more details. If you do encounter any issues with building the plugin,
please do post and let us know.

A couple of issues I noticed when putting this together:

* I encountered a ConcurrentModificationException caused by adding
System.getProperties() to a IStringVariableManager, commenting out line 44:
addPropertyVariables(System.getProperties()); in OpenEjbPlugin resolved
this, and everything seemed to work, but I don't know what the effect of
this will be - Deryck, do you have any thoughts on this?

* We make a fair bit of use org.eclipse.core.runtime.FileLocator which
converts URLs of resources in OSGi bundles to URLs on the file system - I
think I'm right in thinking that this is an Equinox / Eclipse specific thing
and probably won't work in other OSGi implementations. I think it would be
nice if we can find a way of not requiring org.eclipse.core.runtime or
org.eclipse.core.variables.

Jon

2009/5/9 Gauthier Libéral liberal.gauth...@gmail.com


 Hi,

 I'm a beginner concerning the use of Maven but I don't understand why the
 first link provided by Jonathan (SVN) is unbuildable by my own maven due to
 an eclipse error (seems I've not eclipse:eclipse). I think that I will wait
 for your tutorial.

 I don't understand why using RCP is useful, why do not run OpenEJB in just
 only Equinox ? If I'm not mad, RCP apps used some graphical technologies
 like SWT so why use RCP-based apps on the server-side ?

 Thanks a lot for these anwers.

 ---
 Gauthier Libéral


 Jonathan Gallimore-2 wrote:
 
  Thanks for your reply Deryck - sorry I haven't replied to this thread
  sooner. I agree, I think the work Deryck has done will do what you're
  after,
  and it works really well. As promised yesterday I'm going to try and
 write
  a
  tutorial on this functionality today - I'll post it up when its done :)
 
  Jon
 
  On Fri, May 8, 2009 at 10:24 AM, Brown, Deryck
  deryck.br...@ziebel.bizwrote:
 
  Hi,
 
  In fact the example code that Jonathan provided the links for does
  exactly
  this. I know, I wrote it!
 
  The setup I use in my own application has OpenEJB in one plug-in running
  as
  an OSGi service listener that watches for services that belong to the
  OpenEjbApplication class to be deployed. It then invokes the OpenEJB
  deployment code to start the application running. Your application
 plugin
  must include a plug-in activator that registers a new OpenEjbApplication
  service. When the plug-in is deactivated, the service is automatically
  stopped by the platform, and the OpenEJB server undeploys the
  application.
 
  The plugins at the moment are running on the Eclipse 3.4.2 RCP platform.
  This may cause some problems with running on (just) Equinox as the
  current
  code may be using some non-OSGi APIs (to load properties from files and
  allow for variable expansion within property values).
 
  I have used this to deploy an application that contains stateless
 session
  beans and entity beans that use an Apache Derby database and Hibernate
  for
  the persistence. (I've since moved Hibernate into its own plugin so I
 can
  share the Hibernate instance between OpenEJB and EMF/Teneo.)
 
  See the original description of this code at:
 
 
 
 http://www.nabble.com/Dynamically-deploying-to-an-embedded-OpenEJB-server-within-an-Eclipse-RCP-application-tt21667308.html#a21827389
 
  Regards,
  Deryck
 
  --
  Dr Deryck F Brown
  Software Engineer
  Ziebel UK Ltd
  Unit A, Broadfold Road,
  Bridge of Don,
  Aberdeen AB23 8EE
 
  Tel: 01224 227227 (X143)
  Fax: 01224 703146
  Skype: ziebel-deryckb
  Web: www.ziebel.biz
 
  -Original Message-
  From: Gauthier Libéral [mailto:liberal.gauth...@gmail.com]
  Sent: 08 May 2009 09:48
  To: users@openejb.apache.org
  Subject: Re: OpenEJB and OSGi
 
 
  Hi,
 
  I would like to have OpenEJB running as an equinox bundle and then would
  like to run my EJB-Jar in Equinox too (one bundle per EJB).
 
  When you said You don't expect EJBs will be deployed as OSGi bundles,
 do
  you? is it a warning for not doing that thing ?
 
  Sorry 

Injection into Unit Tests

2009-05-10 Thread Reza Rahman

Hi,

I am currently using Spring JUnit 4 support classes to inject OpenEJB 
Session Beans into unit tests. Here is the code:


@RunWith(SpringJUnit4ClassRunner.class) // Bootstraps Spring inside the 
test.
@ContextConfiguration(locations = { /applicationContext.xml }) // 
Responsible for instantiating OpenEJB and injecting the EJB below.

public class AccountServiceTest {
   @EJB(mappedName = DefaultAccountServiceLocal) // Spring processes 
this @EJB annotation to perform the injection from an OpenEJB JNDI instance.

   private AccountService accountService;

I would like to avoid using Spring just for this. Does OpenEJB provide 
support for anything similar to SpringJUnit4ClassRunner?


Many thanks in advance,
Reza

Expert Group Member, EJB 3.1 and Java EE 6
Author, EJB 3 in Action
Independent Consultant


Re: MDB Listening on external ActiveMQ broker

2009-05-10 Thread Reza Rahman

Hi,

I was able to get the MDB listening on the remote topic. There were two 
issues. The first was that I had the same MDB in the classpath for the 
Tomcat web app. The second is that ActiveMQ did not recognize async=true 
for remote servers. Here is the fix:


properties.put(Default JMS Resource Adapter.ServerUrl, 
tcp://localhost:61616);


I still would like to have an answer to the JUnit support question. 
Also, I would like to not create an embedded broker on the command-line 
client at all. I tried keeping the BrokerXmlConfig null or empty. null 
tried to create a remoted broker and empty resulted in an error message.


Many thanks in advance,
Reza

Expert Group Member, EJB 3.1 and Java EE 6
Author, EJB 3 in Action
Independent Consultant


Reza Rahman wrote:

Hi,

I am trying to connect an OpenEJB MDB embedded in a Java SE command-line
application to a JMS topic inside an ActiveMQ embedded broker running
inside Tomcat/OpenEJB. The MDB works fine when it is inside Tomcat, but
that's not that useful in this scenario since I want to perform remote
notification to the Java SE program running outside Tomcat. Here is my
SE bootstrap code:

Properties properties = new Properties();

properties.put(Context.INITIAL_CONTEXT_FACTORY,
org.apache.openejb.client.LocalInitialContextFactory);
properties.put(Default JMS Resource Adapter,
new://Resource?type=ActiveMQResourceAdapter);
properties.put(Default JMS Resource Adapter.BrokerXmlConfig,
broker:vm://localhost); // Ideally, I don't want an embedded broker
here at all.
properties.put(Default JMS Resource Adapter.ServerUrl,
tcp://localhost:61616?async=true); // Trying to connect to the Tomcat
broker.

new InitialContext(properties);

Here is the MDB container configuration on the Tomcat/OpenEJB side:

Resource id=My JMS Resource Adapter type=ActiveMQResourceAdapter
 # Broker configuration URI as defined by ActiveMQ
 # see http://activemq.apache.org/broker-configuration-uri.html

 BrokerXmlConfig broker:(tcp://localhost:61616)?useJmx=false // Should
be listening to remote clients

 # Broker address

 ServerUrl vm://localhost?async=true // Should start an embedded broker.

 # DataSource for persistence messages

 DataSource My Unmanaged DataSource
/Resource

Here is my MDB configuration:

@MessageDriven(activationConfig = {
   @ActivationConfigProperty(propertyName = destinationType,
propertyValue = javax.jms.Topic),
   @ActivationConfigProperty(propertyName = destination,
propertyValue = alertTopic) }) // Can I connect directly to the remote
topic instead?

Can anyone help?

Many thanks in advance,
Reza

Expert Group Member, EJB 3.1 and Java EE 6
Author, EJB 3 in Action
Independent Consultant






Re: OpenEJB and OSGi

2009-05-10 Thread Jacek Laskowski
On Sun, May 10, 2009 at 3:34 PM, Jonathan Gallimore
jonathan.gallim...@gmail.com wrote:

 Sorry for the delay. I've had a bit of a play around and created a sample
 Equinox directory with the bundles needed for OpenEJB, and added some basic
 instructions to the Wiki. The sample zip is available from
 http://people.apache.org/~jgallimore/openejb-osgi.zip and the source code is
 available from http://people.apache.org/~jgallimore/projects.zip

Do I need Eclipse to import the project and build the openejb.server
bundle? I've got the latest stable Equinox 3.4.3 and downloaded the
sources but couldn't find the necessary bundle(s) in their binary
form. I looked at the sources and I liked the The white-board model
approach. I have read about it before, but have never tried it out
myself so I'm really happy to see it in OpenEJB (even though it's
currently tied to Equinox). Congrats to all the people involved. Very
appreciated.

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl