You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by boboop <lb...@gmail.com> on 2012/04/23 12:13:03 UTC

ConnectionFactory lookup issue

Hello,

I'm currently trying to use EJB/JPA/JMS in a specific context :

OpenJEB standalone server contains :
- A generic CRUD Stateless Session Bean for persist/merge/remove operations
- A Hibernate Interceptor to track transaction operations, which sends
events in a JMS topic at transaction commit
- A remote client as the receiver of the events in the topic

To acheive this, i have defined a ConnectionFactory and a Topic in openejb
configuration. The Hibernate Interceptor (which isn't managed by the EJB
container) does a lookup (on the Local Context) to get the topic and the
connectionfactory, without any problem.

The problem is with the remote client. I use the same lookup (on a remote
context) to get the connection factory and the topic, but i can only get the
Topic. The ConnectionFactory returned by the lookup is always null.
It doesn't seem to be a naming error, because if i put a wrong name, i get a
NamingException, but with the good name, i get no exception at all, only a
null object. The topic lookup is OK, the problem is only with the
ConnectionFactory.

The same code (with tweaks on the context initialization and the jndi names)
works well with glassfish server, but i want it to work with OpenEJB.

Is it possible to receive in the topic without looking up the connection
factory (with a client-instanciated connection factory) ?

Code :
In the Hibernate interceptor on the OpenEJB server :

Properties p=new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
p.setProperty(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201");
InitialContext ctx= new InitialContext(p); 
connectionFactory = (ConnectionFactory)
ctx.lookup("openejb:Resource/jms/MyCF"); // OK
topic = (Topic)ctx.lookup("openejb:Resource/jms/MyTopic"); // OK

In the client application :

Properties p=new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
p.setProperty(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201");
p.setProperty("openejb.validation.output.level", "verbose");  
InitialContext ctx = new InitialContext(p);
ConnectionFactory cf = (ConnectionFactory)
ctx.lookup("openejb:Resource/jms/MyCF"); // null
Destination dest = (Destination)ctx.lookup("openejb:Resource/jms/MyTopic");
// OK

openejb.xml :
<Resource id="MyMQAdapter" type="ActiveMQResourceAdapter">
	# Broker configuration URI as defined by ActiveMQ
	# see http://activemq.apache.org/broker-configuration-uri.html
	
	BrokerXmlConfig broker:(tcp://localhost:61616)?useJmx=true
	
	# Broker address
	
	ServerUrl vm://localhost?async=true
	
	# DataSource for persistence messages
	
	DataSource My Unmanaged DataSource
</Resource>


<Resource id="jms/MyCF" type="javax.jms.ConnectionFactory">
	ResourceAdapter MyMQAdapter
</Resource>

<Resource id="jms/MyTopic" type="javax.jms.Topic">
	destination MyTopic
</Resource>

--
View this message in context: http://openejb.979440.n4.nabble.com/ConnectionFactory-lookup-issue-tp4580009p4580009.html
Sent from the OpenEJB User mailing list archive at Nabble.com.