User: user57  
  Date: 01/07/05 00:05:58

  Modified:    src/main/org/jboss/test/jmsra/bean PublisherBean.java
                        PublisherCMPBean.java
  Log:
  
  
  Revision  Changes    Path
  1.4       +102 -42   jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherBean.java
  
  Index: PublisherBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PublisherBean.java        2001/07/04 01:27:34     1.3
  +++ PublisherBean.java        2001/07/05 07:05:58     1.4
  @@ -1,3 +1,9 @@
  +/*
  + * JBoss, the OpenSource EJB server
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.test.jmsra.bean;
   
   import java.rmi.RemoteException;
  @@ -8,97 +14,145 @@
   import javax.naming.*;
   import javax.jms.*;
   
  +import org.apache.log4j.Category;
   
  -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;
  +/**
  + * Bean to help JMS RA test publish/send JMS messages and test transactional
  + * behavior.
  + *
  + * <p>Created: Mon Apr 23 21:35:25 2001
  + *
  + * @author  Unknown
  + * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.4 $
  + */
  +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 final Category log = Category.getInstance(this.getClass());
  +   
  +    private SessionContext ctx; // = null;
  +    private Queue queue; // = null;
  +    private QueueConnection queueConnection; // = null;
       
       public PublisherBean() {
  +        // empty
       }
   
  -    public void setSessionContext(SessionContext ctx) {
  +    public void setSessionContext(final SessionContext ctx) {
           this.ctx = ctx;
       }
   
  -    public void ejbCreate()  {
  +    public void ejbCreate() {
           try {
               Context context = new InitialContext();
               queue = (Queue)context.lookup(QUEUE_JNDI);
   
  -            QueueConnectionFactory factory = 
(QueueConnectionFactory)context.lookup(CONNECTION_JNDI);
  +            QueueConnectionFactory factory =
  +                (QueueConnectionFactory)context.lookup(CONNECTION_JNDI);
               queueConnection = factory.createQueueConnection();
  -    
  -        } catch (Exception ex) {
  +        }
  +        catch (Exception e) {
               // JMSException or NamingException could be thrown
  -            ex.printStackTrace();
  -            throw new EJBException(ex.toString());
  +            log.error("failed to create bean", e);
  +            throw new EJBException(e);
           }
       }
   
       /**
        * Send a message with a message nr in property MESSAGE_NR
        */
  -    public void simple(int messageNr)  {
  +    public void simple(int messageNr) {
  +        log.info("sending message");
           sendMessage(messageNr);
  +        log.info("sent");
       }
       
       /**
        * Try send a message with a message nr in property MESSAGE_NR,
        * but set rollback only
        */
  -    public void simpleFail(int messageNr)  {
  +    public void simpleFail(int messageNr) {
  +        log.info("sending message");
           sendMessage(messageNr);
  +        log.info("sent");
  +        
           // Roll it back, no message should be sent if transactins work
  -        System.err.println("DEBUG: Setting rollbackOnly");
  +        log.info("Setting rollbackOnly");
           ctx.setRollbackOnly();
  -        System.err.println("DEBUG rollback set: " + ctx.getRollbackOnly());
  -    
  +        log.info("rollback set: " + ctx.getRollbackOnly());
       }
   
       public void beanOk(int messageNr) {
  +        log.info("sending message");        
           // DO JMS - First transaction
           sendMessage(messageNr);
  +        log.info("sent");
  +        
           PublisherCMPHome h = null;
           try {
               // DO entity bean - Second transaction
               h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
               PublisherCMP b = h.create(new Integer(messageNr));
  +            log.info("calling bean");                        
               b.ok(messageNr);
  -        } catch(Exception ex) {
  -            throw new EJBException("OPS exception in ok: " + ex);
  -        } finally {
  +            log.info("called bean");
  +        }
  +        catch (Exception e) {
  +            log.error("failed to contact 3rdparty bean", e);
  +            throw new EJBException(e);
  +        }
  +        finally {
               try {
                   h.remove(new Integer(messageNr));
  -            } catch(Exception e) {
  -                e.printStackTrace();
               }
  +            catch (Exception e) {
  +                log.error("failed to remove 3rdparty bean", e);
  +            }
  +            finally {
  +                log.info("done");
  +            }
           }
       }
   
       public void beanError(int messageNr) {
  +        log.info("sending message");                
           // DO JMS - First transaction
           sendMessage(messageNr);
  +        log.info("sent");
  +        
           PublisherCMPHome h = null;
           try {
               // DO entity bean - Second transaction
               h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
               PublisherCMP b = h.create(new Integer(messageNr));
  +            log.info("calling bean");            
               b.error(messageNr);
  -        } catch(Exception ex) {
  -            throw new EJBException("Exception in erro: " + ex);
  -        }finally {
  +            log.info("bean called (should never get here)");
  +        }
  +        catch (Exception e) {
  +            log.info("caught exception (as expected)");
  +            throw new EJBException("Exception in erro: " + e);
  +        }
  +        finally {
               try {
                   h.remove(new Integer(messageNr));
  -            }catch(Exception ex) {
  -                ex.printStackTrace();
               }
  +            catch (Exception e) {
  +                log.error("failed to remove 3rdparty bean", e);
  +            }
  +            finally {
  +                log.info("done");
  +            }
           }
       }
   
  @@ -106,9 +160,10 @@
           if (queueConnection != null) {
               try {
                   queueConnection.close();
  -            } catch (Exception e) {
  -                e.printStackTrace();
               }
  +            catch (Exception e) {
  +                log.error("failed to close connection", e);
  +            }
           }
       }
   
  @@ -116,32 +171,37 @@
       public void ejbPassivate() {}
   
       private void sendMessage(int messageNr) {
  +        log.info("sending message wtih nr: " + messageNr);
           QueueSession queueSession = null;
           try {
               QueueSender queueSender = null;
               TextMessage message = null;
  -    
               queueSession =
  -                queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
  +                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);
  -            System.out.println("sent message with nr = " + messageNr);
  +            log.info("sent message with nr = " + messageNr);
           }
  -        catch (JMSException ex) {
  -            ex.printStackTrace();
  +        catch (JMSException e) {
  +            log.debug("failed to send", e);
               ctx.setRollbackOnly();
  -            throw new EJBException(ex.toString());
  +            throw new EJBException(e);
           }
           finally {
               if (queueSession != null) {
                   try {
                       queueSession.close();
  -                } catch (Exception e) {
  -                    e.printStackTrace();
  +                }
  +                catch (Exception e) {
  +                    log.error("failed to close session", e);
  +                }
  +                finally {
  +                    log.info("done sending message");
                   }
               }
           }
  
  
  
  1.3       +37 -33    
jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherCMPBean.java
  
  Index: PublisherCMPBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherCMPBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PublisherCMPBean.java     2001/05/19 23:13:11     1.2
  +++ PublisherCMPBean.java     2001/07/05 07:05:58     1.3
  @@ -17,59 +17,63 @@
    */
   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
  - *
  + * 3rdparty bean to help test JMS RA transactions.
    *
  - * Created: Tue Apr 24 22:32:41 2001
  + * <p>Created: Tue Apr 24 22:32:41 2001
    *
  - * @author
  - * @version
  + * @author  <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>
  + * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.3 $
    */
  -
  -public class PublisherCMPBean  extends EntitySupport {
  +public class PublisherCMPBean
  +    extends EntitySupport
  +{
       public Integer nr;
  +    
       public PublisherCMPBean() {
  +        // empty
  +    }
       
  +    public Integer getNr() {
  +        return nr;
       }
  -    public Integer getNr()
  -   {
  -      return nr;
  -   }
   
  -    public void setNr(Integer nr)
  -    {
  -    this.nr = nr;
  +    public void setNr(Integer nr) {
  +        this.nr = nr;
       }
   
       public void ok(int nr) {
  -    // Do nothing
  +        // Do nothing
       }
   
       public void error(int nr) {
  -    // Roll back throug an exception
  -    throw new EJBException("Roll back!");
  +        // 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()
  -   {
  -   }
  +    
  +    public Integer ejbCreate(Integer nr)
  +        throws CreateException
  +    {
  +        this.nr = nr;
  +        return null;
  +    }
  +
  +    public void ejbPostCreate(Integer nr)
  +        throws CreateException
  +    {
  +    }
  +
  +    public void ejbLoad()
  +    {
  +    }
  +    
   } // PublisherCMPBean
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to