User: pra
Date: 01/04/26 14:18:52
Added: src/main/org/jboss/test/jmsra/bean Publisher.java
PublisherBean.java PublisherCMP.java
PublisherCMPBean.java PublisherCMPHome.java
PublisherHome.java TopicAdapter.java
TopicPublisherBean.java
Log:
Added small testsuite for JMS Connector ra, will only work against the current cvs
JBoss
Revision Changes Path
1.1 jbosstest/src/main/org/jboss/test/jmsra/bean/Publisher.java
Index: Publisher.java
===================================================================
package org.jboss.test.jmsra.bean;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Publisher extends EJBObject {
public static final String JMS_MESSAGE_NR = "MESSAGE_NR";
public void simple(int messageNr) throws RemoteException;
public void simpleFail(int messageNr) throws RemoteException;
public void beanOk(int messageNr) throws RemoteException;
public void beanError(int messageNr) throws RemoteException;
}
1.1 jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherBean.java
Index: PublisherBean.java
===================================================================
package org.jboss.test.jmsra.bean;
import java.rmi.RemoteException;
import java.util.*;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.EJBException;
import javax.naming.*;
import javax.jms.*;
public class PublisherBean implements SessionBean {
private static final String CONNECTION_JNDI =
"java:comp/env/jms/MyQueueConnection";
private static final String QUEUE_JNDI = "java:comp/env/jms/QueueName";
private static final String BEAN_JNDI = "java:comp/env/ejb/PublisherCMP";
private SessionContext ctx = null;
private Queue queue = null;
private QueueConnection queueConnection = null;
public PublisherBean() {
}
public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
}
public void ejbCreate() throws EJBException {
try {
Context context = new InitialContext();
queue = (Queue)context.lookup(QUEUE_JNDI);
QueueConnectionFactory factory =
(QueueConnectionFactory)context.lookup(CONNECTION_JNDI);
queueConnection = factory.createQueueConnection();
} catch (Exception ex) {
// JMSException or NamingException could be thrown
ex.printStackTrace();
throw new EJBException(ex.toString());
}
}
/**
* Send a message with a message nr in property MESSAGE_NR
*/
public void simple(int messageNr) throws EJBException {
sendMessage(messageNr);
}
/**
* Try send a message with a message nr in property MESSAGE_NR,
* but set rollback only
*/
public void simpleFail(int messageNr) throws EJBException {
sendMessage(messageNr);
// Roll it back, no message should be sent if transactins work
System.err.println("DEBUG: Setting rollbackOnly");
ctx.setRollbackOnly();
System.err.println("DEBUG rollback set: " + ctx.getRollbackOnly());
}
public void beanOk(int messageNr) throws EJBException{
// DO JMS - First transaction
sendMessage(messageNr);
PublisherCMPHome h = null;
try {
// DO entity bean - Second transaction
h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
PublisherCMP b = h.create(new Integer(messageNr));
b.ok(messageNr);
}catch(Exception ex) {
throw new EJBException("OPS exception in ok: " + ex);
} finally {
try {
h.remove(new Integer(messageNr));
}catch(Exception e) {
e.printStackTrace();
}
}
}
public void beanError(int messageNr) throws EJBException{
// DO JMS - First transaction
sendMessage(messageNr);
PublisherCMPHome h = null;
try {
// DO entity bean - Second transaction
h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
PublisherCMP b = h.create(new Integer(messageNr));
b.error(messageNr);
} catch(Exception ex) {
throw new EJBException("Exception in erro: " + ex);
}finally {
try {
h.remove(new Integer(messageNr));
}catch(Exception ex) {
ex.printStackTrace();
}
}
}
public void ejbRemove() throws RemoteException {
if(queueConnection != null) {
try {
queueConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void ejbActivate() {}
public void ejbPassivate() {}
private void sendMessage(int messageNr) throws EJBException{
QueueSession queueSession = null;
try {
QueueSender queueSender = null;
TextMessage message = null;
queueSession =
queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
message.setText(String.valueOf(messageNr));
message.setIntProperty(Publisher.JMS_MESSAGE_NR, messageNr);
queueSender.send(message);
} catch (JMSException ex) {
ex.printStackTrace();
ctx.setRollbackOnly();
throw new EJBException(ex.toString());
} finally {
if (queueSession != null) {
try {
queueSession.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
1.1 jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherCMP.java
Index: PublisherCMP.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.test.jmsra.bean;
import java.rmi.*;
import javax.ejb.*;
/**
* PublisherCMP.java
*
*
* Created: Tue Apr 24 22:37:41 2001
*
* @author
* @version
*/
public interface PublisherCMP extends EJBObject {
public Integer getNr() throws RemoteException;
public void setNr(Integer nr)throws RemoteException;
public void ok(int nr)throws RemoteException;
public void error(int nr)throws RemoteException;
} // PublisherCMP
1.1
jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherCMPBean.java
Index: PublisherCMPBean.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.test.jmsra.bean;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import org.jboss.test.util.ejb.EntitySupport;
/**
* PublisherCMPBean.java
*
*
* Created: Tue Apr 24 22:32:41 2001
*
* @author
* @version
*/
public class PublisherCMPBean extends EntitySupport {
public Integer nr;
public PublisherCMPBean() {
}
public Integer getNr()
{
return nr;
}
public void setNr(Integer nr)
{
this.nr = nr;
}
public void ok(int nr)throws EJBException {
// Do nothing
}
public void error(int nr)throws EJBException {
// Roll back throug an exception
throw new EJBException("Roll back!");
}
// EntityBean implementation -------------------------------------
public Integer ejbCreate(Integer nr)
throws CreateException
{
this.nr = nr;
return null;
}
public void ejbPostCreate(Integer nr)
throws CreateException
{
}
public void ejbLoad()
{
}
} // PublisherCMPBean
1.1
jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherCMPHome.java
Index: PublisherCMPHome.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.test.jmsra.bean;
import java.rmi.*;
import javax.ejb.*;
/**
* PublisherCMPHome.java
*
*
* Created: Tue Apr 24 22:39:21 2001
*
* @author
* @version
*/
public interface PublisherCMPHome extends EJBHome
{
public PublisherCMP create(Integer nr)
throws RemoteException, CreateException;
public PublisherCMP findByPrimaryKey(Integer nr)
throws RemoteException, FinderException;
} // PublisherCMPHome
1.1 jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherHome.java
Index: PublisherHome.java
===================================================================
package org.jboss.test.jmsra.bean;
import java.rmi.RemoteException;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
public interface PublisherHome extends EJBHome {
Publisher create() throws RemoteException, CreateException;
}
1.1 jbosstest/src/main/org/jboss/test/jmsra/bean/TopicAdapter.java
Index: TopicAdapter.java
===================================================================
/*
* Copyright (c) 2000 Peter Antman DN <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.test.jmsra.bean;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.EJBException;
import javax.naming.*;
import javax.jms.*;
/**
* Listen on a topic, send to queue
*
*
* Created: Sat Nov 25 18:07:50 2000
*
* @author
* @version
*/
public class TopicAdapter implements MessageDrivenBean, MessageListener{
private static final String CONNECTION_JNDI =
"java:comp/env/jms/MyQueueConnection";
private static final String QUEUE_JNDI = "java:comp/env/jms/QueueName";
private MessageDrivenContext ctx = null;
private Queue queue = null;
private QueueConnection queueConnection = null;
public TopicAdapter() {
}
public void setMessageDrivenContext(MessageDrivenContext ctx)
throws EJBException {
this.ctx = ctx;
}
public void ejbCreate() throws EJBException{
try {
Context context = new InitialContext();
queue = (Queue)context.lookup(QUEUE_JNDI);
QueueConnectionFactory factory =
(QueueConnectionFactory)context.lookup(CONNECTION_JNDI);
queueConnection = factory.createQueueConnection();
} catch (Exception ex) {
// JMSException or NamingException could be thrown
ex.printStackTrace();
throw new EJBException(ex.toString());
}
}
public void ejbRemove() {
if(queueConnection != null) {
try {
queueConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
ctx=null;
}
public void onMessage(Message message) {
System.err.println("DEBUG: TopicBean got message" + message.toString() );
QueueSession queueSession = null;
try {
QueueSender queueSender = null;
queueSession =
queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
queueSender.send(message);
} catch (JMSException ex) {
ex.printStackTrace();
ctx.setRollbackOnly();
throw new EJBException(ex.toString());
} finally {
if (queueSession != null) {
try {
queueSession.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
} // MessageBeanImpl
1.1
jbosstest/src/main/org/jboss/test/jmsra/bean/TopicPublisherBean.java
Index: TopicPublisherBean.java
===================================================================
package org.jboss.test.jmsra.bean;
import java.rmi.RemoteException;
import java.util.*;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.EJBException;
import javax.naming.*;
import javax.jms.*;
public class TopicPublisherBean implements SessionBean {
private static final String CONNECTION_JNDI =
"java:comp/env/jms/MyTopicConnection";
private static final String TOPIC_JNDI = "java:comp/env/jms/TopicName";
private static final String BEAN_JNDI = "java:comp/env/ejb/PublisherCMP";
private SessionContext ctx = null;
private Topic topic = null;
private TopicConnection topicConnection = null;
public TopicPublisherBean() {
}
public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
}
public void ejbCreate() throws EJBException {
try {
Context context = new InitialContext();
topic = (Topic)context.lookup(TOPIC_JNDI);
TopicConnectionFactory factory =
(TopicConnectionFactory)context.lookup(CONNECTION_JNDI);
topicConnection = factory.createTopicConnection();
} catch (Exception ex) {
// JMSException or NamingException could be thrown
ex.printStackTrace();
throw new EJBException(ex.toString());
}
}
/**
* Send a message with a message nr in property MESSAGE_NR
*/
public void simple(int messageNr) throws EJBException {
sendMessage(messageNr);
}
/**
* Try send a message with a message nr in property MESSAGE_NR,
* but set rollback only
*/
public void simpleFail(int messageNr) throws EJBException {
sendMessage(messageNr);
// Roll it back, no message should be sent if transactins work
System.err.println("DEBUG: Setting rollbackOnly");
ctx.setRollbackOnly();
System.err.println("DEBUG rollback set: " + ctx.getRollbackOnly());
}
public void beanOk(int messageNr) throws EJBException{
// DO JMS - First transaction
sendMessage(messageNr);
PublisherCMPHome h = null;
try {
// DO entity bean - Second transaction
h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
PublisherCMP b = h.create(new Integer(messageNr));
b.ok(messageNr);
}catch(Exception ex) {
throw new EJBException("OPS exception in ok: " + ex);
} finally {
try {
h.remove(new Integer(messageNr));
}catch(Exception e) {
e.printStackTrace();
}
}
}
public void beanError(int messageNr) throws EJBException{
// DO JMS - First transaction
sendMessage(messageNr);
PublisherCMPHome h = null;
try {
// DO entity bean - Second transaction
h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
PublisherCMP b = h.create(new Integer(messageNr));
b.error(messageNr);
} catch(Exception ex) {
throw new EJBException("Exception in erro: " + ex);
}finally {
try {
h.remove(new Integer(messageNr));
}catch(Exception ex) {
ex.printStackTrace();
}
}
}
public void ejbRemove() throws RemoteException {
if(topicConnection != null) {
try {
topicConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void ejbActivate() {}
public void ejbPassivate() {}
private void sendMessage(int messageNr) throws EJBException{
TopicSession topicSession = null;
try {
TopicPublisher topicPublisher = null;
TextMessage message = null;
topicSession =
topicConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
topicPublisher = topicSession.createPublisher(topic);
message = topicSession.createTextMessage();
message.setText(String.valueOf(messageNr));
message.setIntProperty(Publisher.JMS_MESSAGE_NR, messageNr);
topicPublisher.publish(message);
} catch (JMSException ex) {
ex.printStackTrace();
ctx.setRollbackOnly();
throw new EJBException(ex.toString());
} finally {
if (topicSession != null) {
try {
topicSession.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development