You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Reza Rahman <re...@rahmannet.net> on 2009/05/10 16:21:38 UTC

MDB Listening on external ActiveMQ broker

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: Injection into Unit Tests

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Awesome.

This is a really nice feature and very useful for end users.
It increases a little bit more productivity and makes usage even more
simple.

I will checkout this feature and have a look.

Jean-Louis




David Blevins wrote:
> 
> Highly requested feature, no doubt.  Worked on it a couple weeks ago,  
> but had to put it down to focus on other things for a bit.  Dug it  
> back up today and got it to the point where it works for local clients  
> using the LocalInitialContextFactory.  Would still like to get similar  
> support in for remote clients using the RemoteInitialContextFactory,  
> but that will have to wait for another time.
> 
> Uploaded new maven2 snapshots[1] and a new server zip[2] to our repo  
> so that people can give it a try.  Also an example here[3].
> 
> It's all driven via new @LocalClient annotation used like so:
> 
>    @LocalClient
>    public class MoviesTest extends TestCase {
> 
>        @EJB
>        private Movies movies;
> 
>        @Resource
>        private UserTransaction userTransaction;
> 
>        @PersistenceContext
>        private EntityManager entityManager;
> 
>        public void setUp() throws Exception {
>            Properties p = new Properties();
>            p.put(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
>            p.put("movieDatabase", "new://Resource?type=DataSource");
>            p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
>            p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
> 
>            InitialContext initialContext = new InitialContext(p);
> 
>            // Here's the fun part
>            initialContext.bind("inject", this);
>        }
> 
>        // ...
>    }
> 
> Just add an empty META-INF/ejb-jar.xml or an empty META-INF/ 
> application-client.xml to your test source and we will pickup your  
> @LocalClient annotated classes and make them injectable via the  
> LocalInitialContextFactory.
> 
> Give it a try and definitely let me know if you encounter any issues.
> 
> 
> -David
> 
> 
> [1] http://repository.apache.org/snapshots/
> [2]
> http://repository.apache.org/content/repositories/snapshots/org/apache/openejb/openejb-standalone/3.1.1-SNAPSHOT/openejb-standalone-3.1.1-20090512.062318-3.zip
> [3]
> http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/testcase-injection/
> 
> On May 10, 2009, at 7:29 AM, Reza Rahman wrote:
>> 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
>>
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p23499227.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Injection into Unit Tests

Posted by David Blevins <da...@visi.com>.
Great.  Thanks for reporting back, very appreciated.  We're aiming to  
do a followup 3.1.2 release soon and it's good to know this will be  
fixed.


-David


On Jun 19, 2009, at 10:28 AM, burroinquieto wrote:

>
> Nice job, 3.1.2-SNAPSHOT passes in both Maven and IntelliJ without the
> additional prop.
>
>
> David Blevins wrote:
>>
>> I think I have a fix for this issue that will work without the
>> openejb.tempclassoader.skip workaround.	New 3.1.2-SNAPSHOT jars have
>> been published to http://repository.apache.org/snapshots/
>>
>> Can you give that version a try without the flag and see if things
>> work for you?
>>
>> -David
>>
>> On Jun 15, 2009, at 8:42 PM, burroinquieto wrote:
>>
>>>
>>> No problem.
>>> http://www.nabble.com/file/p24047145/parent-pom.xml parent-pom.xml
>>> http://www.nabble.com/file/p24047145/ejb-pom.xml ejb-pom.xml
>>>
>>> Let me know if you need anything else...
>>>
>>>
>>> David Blevins wrote:
>>>>
>>>>
>>>> On Jun 15, 2009, at 7:57 PM, burroinquieto wrote:
>>>>
>>>>>
>>>>> Adding contextProps.put("openejb.tempclassloader.skip",
>>>>> "annotations") seems
>>>>> to have done the trick.
>>>>>
>>>>> Thanks for the help.  By the way, I noticed in the linked docs  
>>>>> that
>>>>> you've
>>>>> never had the pleasure of encountering this in IntelliJ or Maven.
>>>>> Sorry to
>>>>> break the bad news, but I'm able to reproduce this in both  
>>>>> IntelliJ
>>>>> 8.1.2
>>>>> #9852 and Maven 2.0.10 with JRE 1.5.0_16.
>>>>
>>>> Really, fantastic.  We have an example in our build and it passes
>>>> fine
>>>> without this flag -- makes it hard to test workarounds.  I'd love  
>>>> to
>>>> get my hands on a pom.xml that does fail so we could add it to the
>>>> test suite.  Is it possible you could share it?
>>>>
>>>>
>>>> -David
>>>>
>>>>
>>>>>
>>>>>
>>>>>
>>>>> David Blevins wrote:
>>>>>>
>>>>>>
>>>>>> On Jun 11, 2009, at 8:38 AM, burroinquieto wrote:
>>>>>>
>>>>>>>
>>>>>>> I wasn't able to get this working with the 3.1.1 release.
>>>>>>>
>>>>>>> I configured a simple test case as follows:
>>>>>>>
>>>>>>> @LocalClient
>>>>>>> public class StockEJBLocalTest extends TestCase {
>>>>>>>
>>>>>>> private Context context;
>>>>>>>
>>>>>>> @EJB
>>>>>>> private StockEJBLocal stockEJBLocal;
>>>>>>>
>>>>>>> public void setUp() throws Exception {
>>>>>>>   initContext();
>>>>>>> }
>>>>>>>
>>>>>>> private void initContext() {
>>>>>>>
>>>>>>>   Properties contextProps = new Properties();
>>>>>>>   ResourceBundle rb = ResourceBundle.getBundle("datasource");
>>>>>>>   Enumeration props = rb.getKeys();
>>>>>>>
>>>>>>>   String dsName = null;
>>>>>>>   while (props.hasMoreElements()) {
>>>>>>>
>>>>>>>      String prop = (String)props.nextElement();
>>>>>>>      if (dsName == null) {
>>>>>>>         dsName = StringUtils.substringBefore(prop, ".");
>>>>>>>      }
>>>>>>>
>>>>>>>      contextProps.put(prop, rb.getString(prop));
>>>>>>>   }
>>>>>>>
>>>>>>>   contextProps.put(dsName, "new://Resource?type=DataSource");
>>>>>>>   contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
>>>>>>> "org.apache.openejb.client.LocalInitialContextFactory");
>>>>>>>
>>>>>>>   try {
>>>>>>>
>>>>>>>      context = new InitialContext(contextProps);
>>>>>>>      context.bind("inject", this);
>>>>>>>
>>>>>>>   } catch (Throwable th) {
>>>>>>>      throw new RuntimeException(th);
>>>>>>>   }
>>>>>>> }
>>>>>>>
>>>>>>> ...
>>>>>>> }
>>>>>>>
>>>>>>> Resulting output and stack trace:
>>>>>>>
>>>>>>> INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
>>>>>>> INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
>>>>>>> container=Default Stateless Container)
>>>>>>> INFO - Deployed Application(path=classpath.ear)
>>>>>>>
>>>>>>> java.lang.RuntimeException: javax.naming.NamingException: Unable
>>>>>>> to
>>>>>>> find
>>>>>>> injection meta-data for
>>>>>>> org.dpage.stocksloth.ejb.StockEJBLocalTest.
>>>>>>> Ensure
>>>>>>> that class was annotated with  
>>>>>>> @org.apache.openejb.api.LocalClient
>>>>>>> and was
>>>>>>> successfully discovered and deployed.  See
>>>>>>> http://openejb.apache.org/3.0/local-client-injection.html
>>>>>>> 	at
>>>>>>> org
>>>>>>> .dpage
>>>>>>> .stocksloth
>>>>>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>>>>>> 63)
>>>>>>> 	at
>>>>>>> org
>>>>>>> .dpage
>>>>>>> .stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java:
>>>>>>> 34)
>>>>>>> 	at
>>>>>>> com
>>>>>>> .intellij 
>>>>>>> .rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
>>>>>>> 40)
>>>>>>> Caused by: javax.naming.NamingException: Unable to find  
>>>>>>> injection
>>>>>>> meta-data
>>>>>>> for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure that  
>>>>>>> class
>>>>>>> was
>>>>>>> annotated with @org.apache.openejb.api.LocalClient and was
>>>>>>> successfully
>>>>>>> discovered and deployed.  See
>>>>>>> http://openejb.apache.org/3.0/local-client-injection.html
>>>>>>> 	at
>>>>>>> org
>>>>>>> .apache
>>>>>>> .openejb
>>>>>>> .client.LocalInitialContext.inject(LocalInitialContext.java:
>>>>>>> 251)
>>>>>>> 	at
>>>>>>> org
>>>>>>> .apache
>>>>>>> .openejb 
>>>>>>> .client.LocalInitialContext.bind(LocalInitialContext.java:
>>>>>>> 225)
>>>>>>> 	at javax.naming.InitialContext.bind(InitialContext.java:359)
>>>>>>> 	at
>>>>>>> org
>>>>>>> .dpage
>>>>>>> .stocksloth
>>>>>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>>>>>> 60)
>>>>>>> 	... 14 more
>>>>>>>
>>>>>>> Adding the empty META-INF/ejb-jar.xml and META-INF/application-
>>>>>>> client.xml
>>>>>>> files didn't seem to make any difference.  Any ideas?
>>>>>>
>>>>>>
>>>>>> Your usage looks good.  I did encounter something like this in
>>>>>> Eclipse
>>>>>> a few days post-release.  It seems that in Eclipse we sometimes  
>>>>>> get
>>>>>> two copies of the @LocalClient annotation loaded and as a result
>>>>>> nothing gets discovered as we're looking for usage of the
>>>>>> LocalClient
>>>>>> from classloader one and the application is using LocalClient  
>>>>>> from
>>>>>> classloader two.  A workaround for this is to boot OpenEJB with  
>>>>>> the
>>>>>> flag 'openejb.tempclassloader.skip=annotations'
>>>>>>
>>>>>> On a related note I just noticed the link in the error message
>>>>>> still
>>>>>> didn't exist!  Ooops!  I went ahead and drafted up that page and
>>>>>> included the above information.
>>>>>>
>>>>>> http://cwiki.apache.org/OPENEJBx30/local-client-injection.html
>>>>>>
>>>>>> It should sync to the openejb.apache.org/ section in an hour.
>>>>>>
>>>>>> Definitely let us know if this does or does not work.  We
>>>>>> definitely
>>>>>> want to make sure this feature operates fine in all environments
>>>>>> and
>>>>>> is properly documented.
>>>>>>
>>>>>> Thanks for reporting this!
>>>>>>
>>>>>> -David
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> -- 
>>>>> View this message in context:
>>>>> http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24046803.html
>>>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24047145.html
>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24115811.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>


Re: Injection into Unit Tests

Posted by burroinquieto <da...@gmail.com>.
Nice job, 3.1.2-SNAPSHOT passes in both Maven and IntelliJ without the
additional prop. 


David Blevins wrote:
> 
> I think I have a fix for this issue that will work without the  
> openejb.tempclassoader.skip workaround.	New 3.1.2-SNAPSHOT jars have  
> been published to http://repository.apache.org/snapshots/
> 
> Can you give that version a try without the flag and see if things  
> work for you?
> 
> -David
> 
> On Jun 15, 2009, at 8:42 PM, burroinquieto wrote:
> 
>>
>> No problem.
>> http://www.nabble.com/file/p24047145/parent-pom.xml parent-pom.xml
>> http://www.nabble.com/file/p24047145/ejb-pom.xml ejb-pom.xml
>>
>> Let me know if you need anything else...
>>
>>
>> David Blevins wrote:
>>>
>>>
>>> On Jun 15, 2009, at 7:57 PM, burroinquieto wrote:
>>>
>>>>
>>>> Adding contextProps.put("openejb.tempclassloader.skip",
>>>> "annotations") seems
>>>> to have done the trick.
>>>>
>>>> Thanks for the help.  By the way, I noticed in the linked docs that
>>>> you've
>>>> never had the pleasure of encountering this in IntelliJ or Maven.
>>>> Sorry to
>>>> break the bad news, but I'm able to reproduce this in both IntelliJ
>>>> 8.1.2
>>>> #9852 and Maven 2.0.10 with JRE 1.5.0_16.
>>>
>>> Really, fantastic.  We have an example in our build and it passes  
>>> fine
>>> without this flag -- makes it hard to test workarounds.  I'd love to
>>> get my hands on a pom.xml that does fail so we could add it to the
>>> test suite.  Is it possible you could share it?
>>>
>>>
>>> -David
>>>
>>>
>>>>
>>>>
>>>>
>>>> David Blevins wrote:
>>>>>
>>>>>
>>>>> On Jun 11, 2009, at 8:38 AM, burroinquieto wrote:
>>>>>
>>>>>>
>>>>>> I wasn't able to get this working with the 3.1.1 release.
>>>>>>
>>>>>> I configured a simple test case as follows:
>>>>>>
>>>>>> @LocalClient
>>>>>> public class StockEJBLocalTest extends TestCase {
>>>>>>
>>>>>> private Context context;
>>>>>>
>>>>>> @EJB
>>>>>> private StockEJBLocal stockEJBLocal;
>>>>>>
>>>>>> public void setUp() throws Exception {
>>>>>>    initContext();
>>>>>> }
>>>>>>
>>>>>> private void initContext() {
>>>>>>
>>>>>>    Properties contextProps = new Properties();
>>>>>>    ResourceBundle rb = ResourceBundle.getBundle("datasource");
>>>>>>    Enumeration props = rb.getKeys();
>>>>>>
>>>>>>    String dsName = null;
>>>>>>    while (props.hasMoreElements()) {
>>>>>>
>>>>>>       String prop = (String)props.nextElement();
>>>>>>       if (dsName == null) {
>>>>>>          dsName = StringUtils.substringBefore(prop, ".");
>>>>>>       }
>>>>>>
>>>>>>       contextProps.put(prop, rb.getString(prop));
>>>>>>    }
>>>>>>
>>>>>>    contextProps.put(dsName, "new://Resource?type=DataSource");
>>>>>>    contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
>>>>>> "org.apache.openejb.client.LocalInitialContextFactory");
>>>>>>
>>>>>>    try {
>>>>>>
>>>>>>       context = new InitialContext(contextProps);
>>>>>>       context.bind("inject", this);
>>>>>>
>>>>>>    } catch (Throwable th) {
>>>>>>       throw new RuntimeException(th);
>>>>>>    }
>>>>>> }
>>>>>>
>>>>>> ...
>>>>>> }
>>>>>>
>>>>>> Resulting output and stack trace:
>>>>>>
>>>>>> INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
>>>>>> INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
>>>>>> container=Default Stateless Container)
>>>>>> INFO - Deployed Application(path=classpath.ear)
>>>>>>
>>>>>> java.lang.RuntimeException: javax.naming.NamingException: Unable  
>>>>>> to
>>>>>> find
>>>>>> injection meta-data for  
>>>>>> org.dpage.stocksloth.ejb.StockEJBLocalTest.
>>>>>> Ensure
>>>>>> that class was annotated with @org.apache.openejb.api.LocalClient
>>>>>> and was
>>>>>> successfully discovered and deployed.  See
>>>>>> http://openejb.apache.org/3.0/local-client-injection.html
>>>>>> 	at
>>>>>> org
>>>>>> .dpage
>>>>>> .stocksloth
>>>>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>>>>> 63)
>>>>>> 	at
>>>>>> org
>>>>>> .dpage
>>>>>> .stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java:
>>>>>> 34)
>>>>>> 	at
>>>>>> com 
>>>>>> .intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
>>>>>> 40)
>>>>>> Caused by: javax.naming.NamingException: Unable to find injection
>>>>>> meta-data
>>>>>> for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure that class
>>>>>> was
>>>>>> annotated with @org.apache.openejb.api.LocalClient and was
>>>>>> successfully
>>>>>> discovered and deployed.  See
>>>>>> http://openejb.apache.org/3.0/local-client-injection.html
>>>>>> 	at
>>>>>> org
>>>>>> .apache
>>>>>> .openejb 
>>>>>> .client.LocalInitialContext.inject(LocalInitialContext.java:
>>>>>> 251)
>>>>>> 	at
>>>>>> org
>>>>>> .apache
>>>>>> .openejb.client.LocalInitialContext.bind(LocalInitialContext.java:
>>>>>> 225)
>>>>>> 	at javax.naming.InitialContext.bind(InitialContext.java:359)
>>>>>> 	at
>>>>>> org
>>>>>> .dpage
>>>>>> .stocksloth
>>>>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>>>>> 60)
>>>>>> 	... 14 more
>>>>>>
>>>>>> Adding the empty META-INF/ejb-jar.xml and META-INF/application-
>>>>>> client.xml
>>>>>> files didn't seem to make any difference.  Any ideas?
>>>>>
>>>>>
>>>>> Your usage looks good.  I did encounter something like this in
>>>>> Eclipse
>>>>> a few days post-release.  It seems that in Eclipse we sometimes get
>>>>> two copies of the @LocalClient annotation loaded and as a result
>>>>> nothing gets discovered as we're looking for usage of the  
>>>>> LocalClient
>>>>> from classloader one and the application is using LocalClient from
>>>>> classloader two.  A workaround for this is to boot OpenEJB with the
>>>>> flag 'openejb.tempclassloader.skip=annotations'
>>>>>
>>>>> On a related note I just noticed the link in the error message  
>>>>> still
>>>>> didn't exist!  Ooops!  I went ahead and drafted up that page and
>>>>> included the above information.
>>>>>
>>>>>  http://cwiki.apache.org/OPENEJBx30/local-client-injection.html
>>>>>
>>>>> It should sync to the openejb.apache.org/ section in an hour.
>>>>>
>>>>> Definitely let us know if this does or does not work.  We  
>>>>> definitely
>>>>> want to make sure this feature operates fine in all environments  
>>>>> and
>>>>> is properly documented.
>>>>>
>>>>> Thanks for reporting this!
>>>>>
>>>>> -David
>>>>>
>>>>>
>>>>>
>>>>
>>>> -- 
>>>> View this message in context:
>>>> http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24046803.html
>>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24047145.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24115811.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Injection into Unit Tests

Posted by David Blevins <da...@visi.com>.
I think I have a fix for this issue that will work without the  
openejb.tempclassoader.skip workaround.	New 3.1.2-SNAPSHOT jars have  
been published to http://repository.apache.org/snapshots/

Can you give that version a try without the flag and see if things  
work for you?

-David

On Jun 15, 2009, at 8:42 PM, burroinquieto wrote:

>
> No problem.
> http://www.nabble.com/file/p24047145/parent-pom.xml parent-pom.xml
> http://www.nabble.com/file/p24047145/ejb-pom.xml ejb-pom.xml
>
> Let me know if you need anything else...
>
>
> David Blevins wrote:
>>
>>
>> On Jun 15, 2009, at 7:57 PM, burroinquieto wrote:
>>
>>>
>>> Adding contextProps.put("openejb.tempclassloader.skip",
>>> "annotations") seems
>>> to have done the trick.
>>>
>>> Thanks for the help.  By the way, I noticed in the linked docs that
>>> you've
>>> never had the pleasure of encountering this in IntelliJ or Maven.
>>> Sorry to
>>> break the bad news, but I'm able to reproduce this in both IntelliJ
>>> 8.1.2
>>> #9852 and Maven 2.0.10 with JRE 1.5.0_16.
>>
>> Really, fantastic.  We have an example in our build and it passes  
>> fine
>> without this flag -- makes it hard to test workarounds.  I'd love to
>> get my hands on a pom.xml that does fail so we could add it to the
>> test suite.  Is it possible you could share it?
>>
>>
>> -David
>>
>>
>>>
>>>
>>>
>>> David Blevins wrote:
>>>>
>>>>
>>>> On Jun 11, 2009, at 8:38 AM, burroinquieto wrote:
>>>>
>>>>>
>>>>> I wasn't able to get this working with the 3.1.1 release.
>>>>>
>>>>> I configured a simple test case as follows:
>>>>>
>>>>> @LocalClient
>>>>> public class StockEJBLocalTest extends TestCase {
>>>>>
>>>>> private Context context;
>>>>>
>>>>> @EJB
>>>>> private StockEJBLocal stockEJBLocal;
>>>>>
>>>>> public void setUp() throws Exception {
>>>>>    initContext();
>>>>> }
>>>>>
>>>>> private void initContext() {
>>>>>
>>>>>    Properties contextProps = new Properties();
>>>>>    ResourceBundle rb = ResourceBundle.getBundle("datasource");
>>>>>    Enumeration props = rb.getKeys();
>>>>>
>>>>>    String dsName = null;
>>>>>    while (props.hasMoreElements()) {
>>>>>
>>>>>       String prop = (String)props.nextElement();
>>>>>       if (dsName == null) {
>>>>>          dsName = StringUtils.substringBefore(prop, ".");
>>>>>       }
>>>>>
>>>>>       contextProps.put(prop, rb.getString(prop));
>>>>>    }
>>>>>
>>>>>    contextProps.put(dsName, "new://Resource?type=DataSource");
>>>>>    contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
>>>>> "org.apache.openejb.client.LocalInitialContextFactory");
>>>>>
>>>>>    try {
>>>>>
>>>>>       context = new InitialContext(contextProps);
>>>>>       context.bind("inject", this);
>>>>>
>>>>>    } catch (Throwable th) {
>>>>>       throw new RuntimeException(th);
>>>>>    }
>>>>> }
>>>>>
>>>>> ...
>>>>> }
>>>>>
>>>>> Resulting output and stack trace:
>>>>>
>>>>> INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
>>>>> INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
>>>>> container=Default Stateless Container)
>>>>> INFO - Deployed Application(path=classpath.ear)
>>>>>
>>>>> java.lang.RuntimeException: javax.naming.NamingException: Unable  
>>>>> to
>>>>> find
>>>>> injection meta-data for  
>>>>> org.dpage.stocksloth.ejb.StockEJBLocalTest.
>>>>> Ensure
>>>>> that class was annotated with @org.apache.openejb.api.LocalClient
>>>>> and was
>>>>> successfully discovered and deployed.  See
>>>>> http://openejb.apache.org/3.0/local-client-injection.html
>>>>> 	at
>>>>> org
>>>>> .dpage
>>>>> .stocksloth
>>>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>>>> 63)
>>>>> 	at
>>>>> org
>>>>> .dpage
>>>>> .stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java:
>>>>> 34)
>>>>> 	at
>>>>> com 
>>>>> .intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
>>>>> 40)
>>>>> Caused by: javax.naming.NamingException: Unable to find injection
>>>>> meta-data
>>>>> for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure that class
>>>>> was
>>>>> annotated with @org.apache.openejb.api.LocalClient and was
>>>>> successfully
>>>>> discovered and deployed.  See
>>>>> http://openejb.apache.org/3.0/local-client-injection.html
>>>>> 	at
>>>>> org
>>>>> .apache
>>>>> .openejb 
>>>>> .client.LocalInitialContext.inject(LocalInitialContext.java:
>>>>> 251)
>>>>> 	at
>>>>> org
>>>>> .apache
>>>>> .openejb.client.LocalInitialContext.bind(LocalInitialContext.java:
>>>>> 225)
>>>>> 	at javax.naming.InitialContext.bind(InitialContext.java:359)
>>>>> 	at
>>>>> org
>>>>> .dpage
>>>>> .stocksloth
>>>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>>>> 60)
>>>>> 	... 14 more
>>>>>
>>>>> Adding the empty META-INF/ejb-jar.xml and META-INF/application-
>>>>> client.xml
>>>>> files didn't seem to make any difference.  Any ideas?
>>>>
>>>>
>>>> Your usage looks good.  I did encounter something like this in
>>>> Eclipse
>>>> a few days post-release.  It seems that in Eclipse we sometimes get
>>>> two copies of the @LocalClient annotation loaded and as a result
>>>> nothing gets discovered as we're looking for usage of the  
>>>> LocalClient
>>>> from classloader one and the application is using LocalClient from
>>>> classloader two.  A workaround for this is to boot OpenEJB with the
>>>> flag 'openejb.tempclassloader.skip=annotations'
>>>>
>>>> On a related note I just noticed the link in the error message  
>>>> still
>>>> didn't exist!  Ooops!  I went ahead and drafted up that page and
>>>> included the above information.
>>>>
>>>>  http://cwiki.apache.org/OPENEJBx30/local-client-injection.html
>>>>
>>>> It should sync to the openejb.apache.org/ section in an hour.
>>>>
>>>> Definitely let us know if this does or does not work.  We  
>>>> definitely
>>>> want to make sure this feature operates fine in all environments  
>>>> and
>>>> is properly documented.
>>>>
>>>> Thanks for reporting this!
>>>>
>>>> -David
>>>>
>>>>
>>>>
>>>
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24046803.html
>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24047145.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>


Re: Injection into Unit Tests

Posted by burroinquieto <da...@gmail.com>.
No problem.
http://www.nabble.com/file/p24047145/parent-pom.xml parent-pom.xml 
http://www.nabble.com/file/p24047145/ejb-pom.xml ejb-pom.xml 

Let me know if you need anything else...


David Blevins wrote:
> 
> 
> On Jun 15, 2009, at 7:57 PM, burroinquieto wrote:
> 
>>
>> Adding contextProps.put("openejb.tempclassloader.skip",  
>> "annotations") seems
>> to have done the trick.
>>
>> Thanks for the help.  By the way, I noticed in the linked docs that  
>> you've
>> never had the pleasure of encountering this in IntelliJ or Maven.   
>> Sorry to
>> break the bad news, but I'm able to reproduce this in both IntelliJ  
>> 8.1.2
>> #9852 and Maven 2.0.10 with JRE 1.5.0_16.
> 
> Really, fantastic.  We have an example in our build and it passes fine  
> without this flag -- makes it hard to test workarounds.  I'd love to  
> get my hands on a pom.xml that does fail so we could add it to the  
> test suite.  Is it possible you could share it?
> 
> 
> -David
> 
> 
>>
>>
>>
>> David Blevins wrote:
>>>
>>>
>>> On Jun 11, 2009, at 8:38 AM, burroinquieto wrote:
>>>
>>>>
>>>> I wasn't able to get this working with the 3.1.1 release.
>>>>
>>>> I configured a simple test case as follows:
>>>>
>>>> @LocalClient
>>>> public class StockEJBLocalTest extends TestCase {
>>>>
>>>>  private Context context;
>>>>
>>>>  @EJB
>>>>  private StockEJBLocal stockEJBLocal;
>>>>
>>>>  public void setUp() throws Exception {
>>>>     initContext();
>>>>  }
>>>>
>>>>  private void initContext() {
>>>>
>>>>     Properties contextProps = new Properties();
>>>>     ResourceBundle rb = ResourceBundle.getBundle("datasource");
>>>>     Enumeration props = rb.getKeys();
>>>>
>>>>     String dsName = null;
>>>>     while (props.hasMoreElements()) {
>>>>
>>>>        String prop = (String)props.nextElement();
>>>>        if (dsName == null) {
>>>>           dsName = StringUtils.substringBefore(prop, ".");
>>>>        }
>>>>
>>>>        contextProps.put(prop, rb.getString(prop));
>>>>     }
>>>>
>>>>     contextProps.put(dsName, "new://Resource?type=DataSource");
>>>>     contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
>>>> "org.apache.openejb.client.LocalInitialContextFactory");
>>>>
>>>>     try {
>>>>
>>>>        context = new InitialContext(contextProps);
>>>>        context.bind("inject", this);
>>>>
>>>>     } catch (Throwable th) {
>>>>        throw new RuntimeException(th);
>>>>     }
>>>>  }
>>>>
>>>> ...
>>>> }
>>>>
>>>> Resulting output and stack trace:
>>>>
>>>> INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
>>>> INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
>>>> container=Default Stateless Container)
>>>> INFO - Deployed Application(path=classpath.ear)
>>>>
>>>> java.lang.RuntimeException: javax.naming.NamingException: Unable to
>>>> find
>>>> injection meta-data for org.dpage.stocksloth.ejb.StockEJBLocalTest.
>>>> Ensure
>>>> that class was annotated with @org.apache.openejb.api.LocalClient
>>>> and was
>>>> successfully discovered and deployed.  See
>>>> http://openejb.apache.org/3.0/local-client-injection.html
>>>> 	at
>>>> org
>>>> .dpage
>>>> .stocksloth 
>>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>>> 63)
>>>> 	at
>>>> org
>>>> .dpage 
>>>> .stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java:
>>>> 34)
>>>> 	at
>>>> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
>>>> 40)
>>>> Caused by: javax.naming.NamingException: Unable to find injection
>>>> meta-data
>>>> for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure that class  
>>>> was
>>>> annotated with @org.apache.openejb.api.LocalClient and was
>>>> successfully
>>>> discovered and deployed.  See
>>>> http://openejb.apache.org/3.0/local-client-injection.html
>>>> 	at
>>>> org
>>>> .apache
>>>> .openejb.client.LocalInitialContext.inject(LocalInitialContext.java:
>>>> 251)
>>>> 	at
>>>> org
>>>> .apache
>>>> .openejb.client.LocalInitialContext.bind(LocalInitialContext.java: 
>>>> 225)
>>>> 	at javax.naming.InitialContext.bind(InitialContext.java:359)
>>>> 	at
>>>> org
>>>> .dpage
>>>> .stocksloth 
>>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>>> 60)
>>>> 	... 14 more
>>>>
>>>> Adding the empty META-INF/ejb-jar.xml and META-INF/application-
>>>> client.xml
>>>> files didn't seem to make any difference.  Any ideas?
>>>
>>>
>>> Your usage looks good.  I did encounter something like this in  
>>> Eclipse
>>> a few days post-release.  It seems that in Eclipse we sometimes get
>>> two copies of the @LocalClient annotation loaded and as a result
>>> nothing gets discovered as we're looking for usage of the LocalClient
>>> from classloader one and the application is using LocalClient from
>>> classloader two.  A workaround for this is to boot OpenEJB with the
>>> flag 'openejb.tempclassloader.skip=annotations'
>>>
>>> On a related note I just noticed the link in the error message still
>>> didn't exist!  Ooops!  I went ahead and drafted up that page and
>>> included the above information.
>>>
>>>   http://cwiki.apache.org/OPENEJBx30/local-client-injection.html
>>>
>>> It should sync to the openejb.apache.org/ section in an hour.
>>>
>>> Definitely let us know if this does or does not work.  We definitely
>>> want to make sure this feature operates fine in all environments and
>>> is properly documented.
>>>
>>> Thanks for reporting this!
>>>
>>> -David
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24046803.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24047145.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Injection into Unit Tests

Posted by David Blevins <da...@visi.com>.
On Jun 15, 2009, at 7:57 PM, burroinquieto wrote:

>
> Adding contextProps.put("openejb.tempclassloader.skip",  
> "annotations") seems
> to have done the trick.
>
> Thanks for the help.  By the way, I noticed in the linked docs that  
> you've
> never had the pleasure of encountering this in IntelliJ or Maven.   
> Sorry to
> break the bad news, but I'm able to reproduce this in both IntelliJ  
> 8.1.2
> #9852 and Maven 2.0.10 with JRE 1.5.0_16.

Really, fantastic.  We have an example in our build and it passes fine  
without this flag -- makes it hard to test workarounds.  I'd love to  
get my hands on a pom.xml that does fail so we could add it to the  
test suite.  Is it possible you could share it?


-David


>
>
>
> David Blevins wrote:
>>
>>
>> On Jun 11, 2009, at 8:38 AM, burroinquieto wrote:
>>
>>>
>>> I wasn't able to get this working with the 3.1.1 release.
>>>
>>> I configured a simple test case as follows:
>>>
>>> @LocalClient
>>> public class StockEJBLocalTest extends TestCase {
>>>
>>>  private Context context;
>>>
>>>  @EJB
>>>  private StockEJBLocal stockEJBLocal;
>>>
>>>  public void setUp() throws Exception {
>>>     initContext();
>>>  }
>>>
>>>  private void initContext() {
>>>
>>>     Properties contextProps = new Properties();
>>>     ResourceBundle rb = ResourceBundle.getBundle("datasource");
>>>     Enumeration props = rb.getKeys();
>>>
>>>     String dsName = null;
>>>     while (props.hasMoreElements()) {
>>>
>>>        String prop = (String)props.nextElement();
>>>        if (dsName == null) {
>>>           dsName = StringUtils.substringBefore(prop, ".");
>>>        }
>>>
>>>        contextProps.put(prop, rb.getString(prop));
>>>     }
>>>
>>>     contextProps.put(dsName, "new://Resource?type=DataSource");
>>>     contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
>>> "org.apache.openejb.client.LocalInitialContextFactory");
>>>
>>>     try {
>>>
>>>        context = new InitialContext(contextProps);
>>>        context.bind("inject", this);
>>>
>>>     } catch (Throwable th) {
>>>        throw new RuntimeException(th);
>>>     }
>>>  }
>>>
>>> ...
>>> }
>>>
>>> Resulting output and stack trace:
>>>
>>> INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
>>> INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
>>> container=Default Stateless Container)
>>> INFO - Deployed Application(path=classpath.ear)
>>>
>>> java.lang.RuntimeException: javax.naming.NamingException: Unable to
>>> find
>>> injection meta-data for org.dpage.stocksloth.ejb.StockEJBLocalTest.
>>> Ensure
>>> that class was annotated with @org.apache.openejb.api.LocalClient
>>> and was
>>> successfully discovered and deployed.  See
>>> http://openejb.apache.org/3.0/local-client-injection.html
>>> 	at
>>> org
>>> .dpage
>>> .stocksloth 
>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>> 63)
>>> 	at
>>> org
>>> .dpage 
>>> .stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java:
>>> 34)
>>> 	at
>>> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
>>> 40)
>>> Caused by: javax.naming.NamingException: Unable to find injection
>>> meta-data
>>> for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure that class  
>>> was
>>> annotated with @org.apache.openejb.api.LocalClient and was
>>> successfully
>>> discovered and deployed.  See
>>> http://openejb.apache.org/3.0/local-client-injection.html
>>> 	at
>>> org
>>> .apache
>>> .openejb.client.LocalInitialContext.inject(LocalInitialContext.java:
>>> 251)
>>> 	at
>>> org
>>> .apache
>>> .openejb.client.LocalInitialContext.bind(LocalInitialContext.java: 
>>> 225)
>>> 	at javax.naming.InitialContext.bind(InitialContext.java:359)
>>> 	at
>>> org
>>> .dpage
>>> .stocksloth 
>>> .ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
>>> 60)
>>> 	... 14 more
>>>
>>> Adding the empty META-INF/ejb-jar.xml and META-INF/application-
>>> client.xml
>>> files didn't seem to make any difference.  Any ideas?
>>
>>
>> Your usage looks good.  I did encounter something like this in  
>> Eclipse
>> a few days post-release.  It seems that in Eclipse we sometimes get
>> two copies of the @LocalClient annotation loaded and as a result
>> nothing gets discovered as we're looking for usage of the LocalClient
>> from classloader one and the application is using LocalClient from
>> classloader two.  A workaround for this is to boot OpenEJB with the
>> flag 'openejb.tempclassloader.skip=annotations'
>>
>> On a related note I just noticed the link in the error message still
>> didn't exist!  Ooops!  I went ahead and drafted up that page and
>> included the above information.
>>
>>   http://cwiki.apache.org/OPENEJBx30/local-client-injection.html
>>
>> It should sync to the openejb.apache.org/ section in an hour.
>>
>> Definitely let us know if this does or does not work.  We definitely
>> want to make sure this feature operates fine in all environments and
>> is properly documented.
>>
>> Thanks for reporting this!
>>
>> -David
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24046803.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>


Re: Injection into Unit Tests

Posted by burroinquieto <da...@gmail.com>.
Adding contextProps.put("openejb.tempclassloader.skip", "annotations") seems
to have done the trick.

Thanks for the help.  By the way, I noticed in the linked docs that you've
never had the pleasure of encountering this in IntelliJ or Maven.  Sorry to
break the bad news, but I'm able to reproduce this in both IntelliJ 8.1.2
#9852 and Maven 2.0.10 with JRE 1.5.0_16.


David Blevins wrote:
> 
> 
> On Jun 11, 2009, at 8:38 AM, burroinquieto wrote:
> 
>>
>> I wasn't able to get this working with the 3.1.1 release.
>>
>> I configured a simple test case as follows:
>>
>> @LocalClient
>> public class StockEJBLocalTest extends TestCase {
>>
>>   private Context context;
>>
>>   @EJB
>>   private StockEJBLocal stockEJBLocal;
>>
>>   public void setUp() throws Exception {
>>      initContext();
>>   }
>>
>>   private void initContext() {
>>
>>      Properties contextProps = new Properties();
>>      ResourceBundle rb = ResourceBundle.getBundle("datasource");
>>      Enumeration props = rb.getKeys();
>>
>>      String dsName = null;
>>      while (props.hasMoreElements()) {
>>
>>         String prop = (String)props.nextElement();
>>         if (dsName == null) {
>>            dsName = StringUtils.substringBefore(prop, ".");
>>         }
>>
>>         contextProps.put(prop, rb.getString(prop));
>>      }
>>
>>      contextProps.put(dsName, "new://Resource?type=DataSource");
>>      contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
>> "org.apache.openejb.client.LocalInitialContextFactory");
>>
>>      try {
>>
>>         context = new InitialContext(contextProps);
>>         context.bind("inject", this);
>>
>>      } catch (Throwable th) {
>>         throw new RuntimeException(th);
>>      }
>>   }
>>
>>  ...
>> }
>>
>> Resulting output and stack trace:
>>
>> INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
>> INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
>> container=Default Stateless Container)
>> INFO - Deployed Application(path=classpath.ear)
>>
>> java.lang.RuntimeException: javax.naming.NamingException: Unable to  
>> find
>> injection meta-data for org.dpage.stocksloth.ejb.StockEJBLocalTest.   
>> Ensure
>> that class was annotated with @org.apache.openejb.api.LocalClient  
>> and was
>> successfully discovered and deployed.  See
>> http://openejb.apache.org/3.0/local-client-injection.html
>> 	at
>> org 
>> .dpage 
>> .stocksloth.ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java: 
>> 63)
>> 	at
>> org 
>> .dpage.stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java: 
>> 34)
>> 	at  
>> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java: 
>> 40)
>> Caused by: javax.naming.NamingException: Unable to find injection  
>> meta-data
>> for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure that class was
>> annotated with @org.apache.openejb.api.LocalClient and was  
>> successfully
>> discovered and deployed.  See
>> http://openejb.apache.org/3.0/local-client-injection.html
>> 	at
>> org 
>> .apache 
>> .openejb.client.LocalInitialContext.inject(LocalInitialContext.java: 
>> 251)
>> 	at
>> org 
>> .apache 
>> .openejb.client.LocalInitialContext.bind(LocalInitialContext.java:225)
>> 	at javax.naming.InitialContext.bind(InitialContext.java:359)
>> 	at
>> org 
>> .dpage 
>> .stocksloth.ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java: 
>> 60)
>> 	... 14 more
>>
>> Adding the empty META-INF/ejb-jar.xml and META-INF/application- 
>> client.xml
>> files didn't seem to make any difference.  Any ideas?
> 
> 
> Your usage looks good.  I did encounter something like this in Eclipse  
> a few days post-release.  It seems that in Eclipse we sometimes get  
> two copies of the @LocalClient annotation loaded and as a result  
> nothing gets discovered as we're looking for usage of the LocalClient  
> from classloader one and the application is using LocalClient from  
> classloader two.  A workaround for this is to boot OpenEJB with the  
> flag 'openejb.tempclassloader.skip=annotations'
> 
> On a related note I just noticed the link in the error message still  
> didn't exist!  Ooops!  I went ahead and drafted up that page and  
> included the above information.
> 
>    http://cwiki.apache.org/OPENEJBx30/local-client-injection.html
> 
> It should sync to the openejb.apache.org/ section in an hour.
> 
> Definitely let us know if this does or does not work.  We definitely  
> want to make sure this feature operates fine in all environments and  
> is properly documented.
> 
> Thanks for reporting this!
> 
> -David
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p24046803.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Injection into Unit Tests

Posted by David Blevins <da...@visi.com>.
On Jun 11, 2009, at 8:38 AM, burroinquieto wrote:

>
> I wasn't able to get this working with the 3.1.1 release.
>
> I configured a simple test case as follows:
>
> @LocalClient
> public class StockEJBLocalTest extends TestCase {
>
>   private Context context;
>
>   @EJB
>   private StockEJBLocal stockEJBLocal;
>
>   public void setUp() throws Exception {
>      initContext();
>   }
>
>   private void initContext() {
>
>      Properties contextProps = new Properties();
>      ResourceBundle rb = ResourceBundle.getBundle("datasource");
>      Enumeration props = rb.getKeys();
>
>      String dsName = null;
>      while (props.hasMoreElements()) {
>
>         String prop = (String)props.nextElement();
>         if (dsName == null) {
>            dsName = StringUtils.substringBefore(prop, ".");
>         }
>
>         contextProps.put(prop, rb.getString(prop));
>      }
>
>      contextProps.put(dsName, "new://Resource?type=DataSource");
>      contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>
>      try {
>
>         context = new InitialContext(contextProps);
>         context.bind("inject", this);
>
>      } catch (Throwable th) {
>         throw new RuntimeException(th);
>      }
>   }
>
>  ...
> }
>
> Resulting output and stack trace:
>
> INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
> INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
> container=Default Stateless Container)
> INFO - Deployed Application(path=classpath.ear)
>
> java.lang.RuntimeException: javax.naming.NamingException: Unable to  
> find
> injection meta-data for org.dpage.stocksloth.ejb.StockEJBLocalTest.   
> Ensure
> that class was annotated with @org.apache.openejb.api.LocalClient  
> and was
> successfully discovered and deployed.  See
> http://openejb.apache.org/3.0/local-client-injection.html
> 	at
> org 
> .dpage 
> .stocksloth.ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java: 
> 63)
> 	at
> org 
> .dpage.stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java: 
> 34)
> 	at  
> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java: 
> 40)
> Caused by: javax.naming.NamingException: Unable to find injection  
> meta-data
> for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure that class was
> annotated with @org.apache.openejb.api.LocalClient and was  
> successfully
> discovered and deployed.  See
> http://openejb.apache.org/3.0/local-client-injection.html
> 	at
> org 
> .apache 
> .openejb.client.LocalInitialContext.inject(LocalInitialContext.java: 
> 251)
> 	at
> org 
> .apache 
> .openejb.client.LocalInitialContext.bind(LocalInitialContext.java:225)
> 	at javax.naming.InitialContext.bind(InitialContext.java:359)
> 	at
> org 
> .dpage 
> .stocksloth.ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java: 
> 60)
> 	... 14 more
>
> Adding the empty META-INF/ejb-jar.xml and META-INF/application- 
> client.xml
> files didn't seem to make any difference.  Any ideas?


Your usage looks good.  I did encounter something like this in Eclipse  
a few days post-release.  It seems that in Eclipse we sometimes get  
two copies of the @LocalClient annotation loaded and as a result  
nothing gets discovered as we're looking for usage of the LocalClient  
from classloader one and the application is using LocalClient from  
classloader two.  A workaround for this is to boot OpenEJB with the  
flag 'openejb.tempclassloader.skip=annotations'

On a related note I just noticed the link in the error message still  
didn't exist!  Ooops!  I went ahead and drafted up that page and  
included the above information.

   http://cwiki.apache.org/OPENEJBx30/local-client-injection.html

It should sync to the openejb.apache.org/ section in an hour.

Definitely let us know if this does or does not work.  We definitely  
want to make sure this feature operates fine in all environments and  
is properly documented.

Thanks for reporting this!

-David


Re: Injection into Unit Tests

Posted by burroinquieto <da...@gmail.com>.
I wasn't able to get this working with the 3.1.1 release.

I configured a simple test case as follows:

@LocalClient
public class StockEJBLocalTest extends TestCase {

   private Context context;

   @EJB
   private StockEJBLocal stockEJBLocal;

   public void setUp() throws Exception {
      initContext();
   }

   private void initContext() {

      Properties contextProps = new Properties();
      ResourceBundle rb = ResourceBundle.getBundle("datasource");
      Enumeration props = rb.getKeys();

      String dsName = null;
      while (props.hasMoreElements()) {

         String prop = (String)props.nextElement();
         if (dsName == null) {
            dsName = StringUtils.substringBefore(prop, ".");
         }

         contextProps.put(prop, rb.getString(prop));
      }

      contextProps.put(dsName, "new://Resource?type=DataSource");
      contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");

      try {
         
         context = new InitialContext(contextProps);
         context.bind("inject", this);

      } catch (Throwable th) {
         throw new RuntimeException(th);
      }
   }

  ...
}

Resulting output and stack trace:

INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
container=Default Stateless Container)
INFO - Deployed Application(path=classpath.ear)

java.lang.RuntimeException: javax.naming.NamingException: Unable to find
injection meta-data for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure
that class was annotated with @org.apache.openejb.api.LocalClient and was
successfully discovered and deployed.  See
http://openejb.apache.org/3.0/local-client-injection.html
	at
org.dpage.stocksloth.ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:63)
	at
org.dpage.stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java:34)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
Caused by: javax.naming.NamingException: Unable to find injection meta-data
for org.dpage.stocksloth.ejb.StockEJBLocalTest.  Ensure that class was
annotated with @org.apache.openejb.api.LocalClient and was successfully
discovered and deployed.  See
http://openejb.apache.org/3.0/local-client-injection.html
	at
org.apache.openejb.client.LocalInitialContext.inject(LocalInitialContext.java:251)
	at
org.apache.openejb.client.LocalInitialContext.bind(LocalInitialContext.java:225)
	at javax.naming.InitialContext.bind(InitialContext.java:359)
	at
org.dpage.stocksloth.ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:60)
	... 14 more

Adding the empty META-INF/ejb-jar.xml and META-INF/application-client.xml
files didn't seem to make any difference.  Any ideas?


David Blevins wrote:
> 
> Highly requested feature, no doubt.  Worked on it a couple weeks ago,  
> but had to put it down to focus on other things for a bit.  Dug it  
> back up today and got it to the point where it works for local clients  
> using the LocalInitialContextFactory.  Would still like to get similar  
> support in for remote clients using the RemoteInitialContextFactory,  
> but that will have to wait for another time.
> 
> Uploaded new maven2 snapshots[1] and a new server zip[2] to our repo  
> so that people can give it a try.  Also an example here[3].
> 
> It's all driven via new @LocalClient annotation used like so:
> 
>    @LocalClient
>    public class MoviesTest extends TestCase {
> 
>        @EJB
>        private Movies movies;
> 
>        @Resource
>        private UserTransaction userTransaction;
> 
>        @PersistenceContext
>        private EntityManager entityManager;
> 
>        public void setUp() throws Exception {
>            Properties p = new Properties();
>            p.put(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
>            p.put("movieDatabase", "new://Resource?type=DataSource");
>            p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
>            p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
> 
>            InitialContext initialContext = new InitialContext(p);
> 
>            // Here's the fun part
>            initialContext.bind("inject", this);
>        }
> 
>        // ...
>    }
> 
> Just add an empty META-INF/ejb-jar.xml or an empty META-INF/ 
> application-client.xml to your test source and we will pickup your  
> @LocalClient annotated classes and make them injectable via the  
> LocalInitialContextFactory.
> 
> Give it a try and definitely let me know if you encounter any issues.
> 
> 
> -David
> 
> 
> [1] http://repository.apache.org/snapshots/
> [2]
> http://repository.apache.org/content/repositories/snapshots/org/apache/openejb/openejb-standalone/3.1.1-SNAPSHOT/openejb-standalone-3.1.1-20090512.062318-3.zip
> [3]
> http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/testcase-injection/
> 
> On May 10, 2009, at 7:29 AM, Reza Rahman wrote:
>> 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
>>
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/MDB-Listening-on-external-ActiveMQ-broker-tp23470573p23983794.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Injection into Unit Tests

Posted by David Blevins <da...@visi.com>.
Highly requested feature, no doubt.  Worked on it a couple weeks ago,  
but had to put it down to focus on other things for a bit.  Dug it  
back up today and got it to the point where it works for local clients  
using the LocalInitialContextFactory.  Would still like to get similar  
support in for remote clients using the RemoteInitialContextFactory,  
but that will have to wait for another time.

Uploaded new maven2 snapshots[1] and a new server zip[2] to our repo  
so that people can give it a try.  Also an example here[3].

It's all driven via new @LocalClient annotation used like so:

   @LocalClient
   public class MoviesTest extends TestCase {

       @EJB
       private Movies movies;

       @Resource
       private UserTransaction userTransaction;

       @PersistenceContext
       private EntityManager entityManager;

       public void setUp() throws Exception {
           Properties p = new Properties();
           p.put(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");
           p.put("movieDatabase", "new://Resource?type=DataSource");
           p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
           p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");

           InitialContext initialContext = new InitialContext(p);

           // Here's the fun part
           initialContext.bind("inject", this);
       }

       // ...
   }

Just add an empty META-INF/ejb-jar.xml or an empty META-INF/ 
application-client.xml to your test source and we will pickup your  
@LocalClient annotated classes and make them injectable via the  
LocalInitialContextFactory.

Give it a try and definitely let me know if you encounter any issues.


-David


[1] http://repository.apache.org/snapshots/
[2] http://repository.apache.org/content/repositories/snapshots/org/apache/openejb/openejb-standalone/3.1.1-SNAPSHOT/openejb-standalone-3.1.1-20090512.062318-3.zip
[3] http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/testcase-injection/

On May 10, 2009, at 7:29 AM, Reza Rahman wrote:
> 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
>




Injection into Unit Tests

Posted by Reza Rahman <re...@rahmannet.net>.
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

Posted by Reza Rahman <re...@rahmannet.net>.
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
>
>