tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mho <...@corybant.com>
Subject question about using openEJB+tomcat with ear file
Date Sat, 05 Sep 2009 16:31:27 GMT

Hello,

Can anyone tell me about the magic incantations to use so that a servlet in
a web app can find the local interface of a session bean in a EJB where both
are in the same Enterprise application (EAR file). Below is the detail.

Thank you in advance for your help

Mho

I am using tomcat 6.0.20 and openEJB 3.1.1 . (BTW I am using Eclipse J2EE
Galileo as an IDE which even allowing for my lack of experties I think may
have some issues of its own but this problem I am pretty sure is not caused
by the IDE)

To demonstrate this problem I have created a simple ear file that looks like
this:

http://www.nabble.com/file/p25310121/aif6_ear.jpg 


ext is a web app with a servlet "Agent" that just tries to talk to a session
bean that is in an EJB called "service".

So I load up the ext.war file and also aif6.ear file in Tomcat and restart
Tomcat. 
( Note: I need to load the war file separately because Catalina looks for
the document root for web app in /ext. Naturally when the EAR file is
expanded the document root is in /aif6/ext and Catalina throws an exception
saying it cant find the web app. To make it happy I have to put the war file
in the webapp directory. -- that is another problem that I will have to fix 
-- I am not sure this is related to the problem I am asking about in this
email if anyone has a suggestion I will be grateful)

The closest I have come to making this work is to use a snippet that I found
in a previous response to someone in this forum. The Agen servlet has code
in it that looks like this  :

Properties p = new Properties();	
	
p.put("java.naming.factory.initial","org.apache.openejb.client.RemoteInitialContextFactory");

p.put("java.naming.provider.url", "http://127.0.0.1:8080/openejb/ejb");

initialContext = new InitialContext(p); 			

try{

	object = initialContext.lookup("ToDoSesBeanLocal");

}catch (Exception e){

	logger.info("Cant open context "+e.toString());

	return false;

}


(My specific question is about the counterpart to "java.naming.provider.url"
that would let me use a local resource


The EJB has a session bean with a local interface. When I run the servlet I
get this exception:

****** Cant open context javax.naming.NamingException: Not remotable:
'ToDoSesBeanLocal'. Business Local interfaces are not remotable as per the
EJB specification.  To disable this restriction, set the system property
'openejb.remotable.businessLocals=true' in the server.

It seems to me that doing what the exception says (BTW thank you openEJB
folks for the very informative Exception) will create a remote interface but
I should be able to hook this up with a local interface and avoid the
overhead. 

to complete the picture let me outline the rest. The session bean is really
a front for a MDB and it looks like this

(some import stuff here)

@Stateless(mappedName = "ToDoSesBeanMapped")

public class ToDoSesBean implements ToDoSesBeanLocal {

    public ToDoSesBean() {

        // TODO Auto-generated constructor stub

    }


	@Resource

	private ConnectionFactory connectionFactory;


	@Resource(name = "ToDoBean")

	private Queue todoQueue;


	@Resource(name = "ToDo_AcknowlegeQueue")

	private Queue todo_acknowlegeQueue;


	public void sendMessage(String text) throws JMSException {


		Connection connection = null;

		Session session = null;

		try {

			connection = connectionFactory.createConnection();

			connection.start();


			// Create a Session

			session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);


			// Create a MessageProducer from the Session to the Topic or Queue

			MessageProducer producer = session.createProducer(todoQueue);

			producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);


(and so on...)



The code snippet for the local test that works locally but for some reason
does not work in the servlet looks like this


Properties properties = new Properties();

properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.LocalInitialContextFactory");


InitialContext initialContext = new InitialContext(properties);

Object object = initialContext.lookup("ToDoSesBeanLocal");



-- 
View this message in context: http://www.nabble.com/question-about-using-openEJB%2Btomcat-with-ear-file-tp25310121p25310121.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message