13 Replies Latest reply on Nov 7, 2008 5:26 PM by Shaolong Wu

    Help need to solve the jms not bound error

    Shaolong Wu Newbie

      Hi,

      I am learning JBoss/EJB3 using this tutorial:

      http://www.netbeans.org/kb/60/javaee/ejb30.html

      Getting Started with Java EE Applications

      I am using Netbeans 6.1. I just use the JBoss 5.0.0CR2 as the application server. I follow the instructions and Everything is fine until I click the Post Message link in the ListNews servlet. I got the following errors.

      Anybody can give me a clue what is wrong?

      HTTP Status 500 -

      --------------------------------------------------------------------------------

      type Exception report

      message

      description The server encountered an internal error () that prevented it from fulfilling this request.

      exception

      javax.servlet.ServletException: Error instantiating servlet class web.PostMessage
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:189)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:91)
      org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:92)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:325)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      java.lang.Thread.run(Thread.java:619)


      root cause

      java.lang.RuntimeException: Unable to inject jndi dependency: env/connectionFactory into property web.PostMessage.connectionFactory: jms not bound
      org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:82)
      org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
      org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:361)
      org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:244)
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:189)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:91)
      org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:92)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:325)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      java.lang.Thread.run(Thread.java:619)


      root cause

      javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: jms not bound]
      org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1257)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:760)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
      org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
      org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75)
      org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
      org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:361)
      org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:244)
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:189)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:91)
      org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:92)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:325)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      java.lang.Thread.run(Thread.java:619)


      root cause

      javax.naming.NameNotFoundException: jms not bound
      org.jnp.server.NamingServer.getBinding(NamingServer.java:564)
      org.jnp.server.NamingServer.getBinding(NamingServer.java:572)
      org.jnp.server.NamingServer.getObject(NamingServer.java:578)
      org.jnp.server.NamingServer.lookup(NamingServer.java:288)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
      javax.naming.InitialContext.lookup(InitialContext.java:392)
      org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1251)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:760)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
      org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
      org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75)
      org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
      org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:361)
      org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:244)
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:189)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:91)
      org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:92)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:325)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      java.lang.Thread.run(Thread.java:619)


      note The full stack trace of the root cause is available in the JBoss Web/2.1.1.CR7 logs.


      --------------------------------------------------------------------------------

      JBoss Web/2.1.1.CR7

        • 1. Re: Help need to solve the jms not bound error
          jaikiran pai Master

          I haven't completed read that tutorial - you could have posted the appropriate code here :-)

          But here's the code which i think is responsible for the exception:

          public class PostMessage extends HttpServlet {
           @Resource(mappedName="jms/NewMessageFactory")
           private ConnectionFactory connectionFactory;
          
           @Resource(mappedName="jms/NewMessage")
           private Queue queue;


          1) As far as i know, the connection factory in JBoss is by default bound at "ConnectionFactory". So the first injection should look like:

          @Resource(mappedName="ConnectionFactory")
           private ConnectionFactory connectionFactory;
          


          or even

          @Resource
           private ConnectionFactory connectionFactory;
          


          2) For the injection of the "queue" to happen, you should have deployed the queue through configuration file to be bound at jms/NewMessage. Have you done that?


          • 2. Re: Help need to solve the jms not bound error
            Shaolong Wu Newbie

            Jaikiran:

            Thanks for your reply.

            Could you tell me how to configure the queue as you suggested? I am new to JBoss and learning it through that tutorial. That tutorial does not say anything about it. And I could not found a good example how to configure the jms.

            • 3. Re: Help need to solve the jms not bound error
              Peter Johnson Master

              You can define a queue by creating a *-service.xml file (say, newmessage-destination-service.xml), with the following content, and place it in the server/default/deploy directory.

              <server>
               <mbean code="org.jboss.jms.server.destination.QueueService"
               name="jbia.jms:service=Queue,name=NewMessage"
               xmbean-dd="xmdesc/Topic-xmbean.xml">
               <depends optional-attribute-name="ServerPeer">
               jboss.messaging:service=ServerPeer
               </depends>
               <depends>jboss.messaging:service=PostOffice</depends>
               <attribute name="SecurityConfig">
               <security>
               <role name="vstore" write="true" />
               <role name="vcust" read="true" create="true" />
               </security>
               </attribute>
               </mbean>
              </server>


              In addition, you will want to change you queue reference to:

              @Resource(mappedName="queue/NewMessage")
              private Queue queue;


              That is the queue name based on the configuration file - note that the 'queue' prefix is assumed. I believe this prefix can be changed, but I would have to do some digging and testing to verify. Is is probably best to use the defaults.

              • 4. Re: Help need to solve the jms not bound error
                Peter Johnson Master

                Oops, the *-service.xml file should be:

                <server>
                 <mbean code="org.jboss.jms.server.destination.QueueService"
                 name="jbia.jms:service=Queue,name=NewMessage"
                 xmbean-dd="xmdesc/Topic-xmbean.xml">
                 <depends optional-attribute-name="ServerPeer">
                 jboss.messaging:service=ServerPeer
                 </depends>
                 <depends>jboss.messaging:service=PostOffice</depends>
                 </mbean>
                </server>


                The security stuff was for my app.

                • 5. Re: Help need to solve the jms not bound error
                  Shaolong Wu Newbie

                  Hi,

                  Thank you very much. But I still can not get through. Please look at what I did and let me know if you have any idea.

                  I am using JBoss5.0.0CR2. The configuration file I think is this one:

                  C:\jboss-5.0.0.CR2\server\default\deploy\messaging\destinations-service.xml. I added a new based the code you give me (with some modificaitons -- Change the Topic to Queue and the jia.jms to jboss.messaging.destination). I don't understand the yet but I assume it is not related to our problem.

                  I can not remove the
                  @Resource(mappedName="jms/NewMessageFactory")
                  private ConnectionFactory connectionFactory;

                  Since it will prevent me to compile the servlet on this line:
                  Connection connection = connectionFactory.createConnection();

                  Here is the modified configuration file:

                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <!--
                   Messaging Destinations deployment descriptor.
                  
                   $Id: destinations-service.xml 72251 2008-04-16 00:38:50Z clebert.suconic@jboss.com $
                   -->
                  
                  <server>
                  
                   <!--
                   The Default Dead Letter Queue. This destination is a dependency of an EJB MDB container.
                   -->
                  
                   <mbean code="org.jboss.jms.server.destination.QueueService"
                   name="jboss.messaging.destination:service=Queue,name=DLQ"
                   xmbean-dd="xmdesc/Queue-xmbean.xml">
                   <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)</annotation>
                   <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                   <depends>jboss.messaging:service=PostOffice</depends>
                   </mbean>
                  
                   <!--
                   The Default Expiry Queue.
                   -->
                  
                   <mbean code="org.jboss.jms.server.destination.QueueService"
                   name="jboss.messaging.destination:service=Queue,name=ExpiryQueue"
                   xmbean-dd="xmdesc/Queue-xmbean.xml">
                   <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)</annotation>
                   <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                   <depends>jboss.messaging:service=PostOffice</depends>
                   </mbean>
                  
                  
                  
                   <mbean code="org.jboss.jms.server.destination.QueueService"
                   name="jboss.messaging.destination:service=Queue,name=NewMessage"
                   xmbean-dd="xmdesc/Queue-xmbean.xml">
                   <depends optional-attribute-name="ServerPeer">
                   jboss.messaging:service=ServerPeer
                   </depends>
                   <depends>jboss.messaging:service=PostOffice</depends>
                   </mbean>
                  
                  
                  </server>





                  Here is the error message from the server:

                  15:23:05,769 INFO [EJBContainer] STARTED EJB: ejb.NewMessageBean ejbName: NewMessageBean
                  15:23:05,769 ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:ear=NewsApp.ear,jar=NewsApp-ejb.jar,name=NewMessageBean,service=EJB3 state=Create
                  org.jboss.deployers.spi.DeploymentException: Required config property RequiredConfigPropertyMetaData@1e655d8[name=destination descriptions=[DescriptionMetaData@ce0284[language=en]]] for messagingType 'javax.jms.MessageListener' not found in activation config [ActivationConfigProperty(destinationType=javax.jms.Queue), ActivationConfigProperty(acknowledgeMode=Auto-acknowledge), ActivationConfigProperty(subscriptionDurability=false)] ra=jboss.jca:service=RARDeployment,name='jms-ra.rar'
                  at org.jboss.resource.deployment.ActivationSpecFactory.createActivationSpec(ActivationSpecFactory.java:95)

                  at org.jboss.resource.deployers.RARDeployment.createActivationSpec(RARDeployment.java:313)
                  at org.jboss.resource.deployers.RARDeployment.internalInvoke(RARDeployment.java:277)
                  at org.jboss.system.ServiceDynamicMBeanSupport.invoke(ServiceDynamicMBeanSupport.java:156)
                  at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
                  at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
                  at org.jboss.ejb3.JmxClientKernelAbstraction.invoke(JmxClientKernelAbstraction.java:58)
                  at org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory.createActivationSpec(JBossMessageEndpointFactory.java:287)
                  at org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory.start(JBossMessageEndpointFactory.java:185)
                  at org.jboss.ejb3.mdb.MessagingContainer.startProxies(MessagingContainer.java:204)
                  at org.jboss.ejb3.mdb.MessagingContainer.lockedStart(MessagingContainer.java:173)
                  at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:858)
                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                  at java.lang.reflect.Method.invoke(Method.java:597)
                  at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
                  at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150)
                  at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
                  at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:241)
                  at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47)
                  at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:109)
                  at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:70)
                  at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:221)
                  at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
                  at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
                  at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
                  at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
                  at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
                  at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
                  at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
                  at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:124)
                  at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:51)
                  at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
                  at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
                  at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1285)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1003)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1024)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1056)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:944)
                  at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
                  at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:627)
                  at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:541)
                  at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:290)
                  at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
                  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
                  at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
                  at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
                  at java.lang.Thread.run(Thread.java:619)


                  • 7. Re: Help need to solve the jms not bound error
                    Shaolong Wu Newbie

                    PeterJ:

                    I was following the tutorial

                    http://www.netbeans.org/kb/60/javaee/ejb30.html

                    Thanks


                    /*
                     * To change this template, choose Tools | Templates
                     * and open the template in the editor.
                     */
                    
                    package ejb;
                    
                    import javax.annotation.Resource;
                    import javax.ejb.ActivationConfigProperty;
                    import javax.ejb.MessageDriven;
                    import javax.ejb.MessageDrivenContext;
                    import javax.jms.JMSException;
                    import javax.jms.Message;
                    import javax.jms.MessageListener;
                    import javax.jms.ObjectMessage;
                    import javax.persistence.EntityManager;
                    import javax.persistence.PersistenceContext;
                    
                    /**
                     *
                     * @author swu3
                     */
                    @MessageDriven(mappedName = "jms/NewMessage", activationConfig = {
                     @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
                     @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
                    
                     })
                    
                    public class NewMessageBean implements MessageListener {
                    
                     @Resource
                     private MessageDrivenContext mdc;
                    
                     @PersistenceContext
                     private EntityManager em;
                    
                     public NewMessageBean() {
                     }
                    
                     public void onMessage(Message message) {
                     ObjectMessage msg = null;
                     try {
                     if (message instanceof ObjectMessage) {
                     msg = (ObjectMessage) message;
                     NewsEntity e = (NewsEntity) msg.getObject();
                     save(e);
                     }
                     } catch (JMSException e) {
                     e.printStackTrace();
                     mdc.setRollbackOnly();
                     } catch (Throwable te) {
                     te.printStackTrace();
                     }
                     }
                    
                     public void save(Object object) {
                     em.persist(object);
                     }
                    
                    }
                    




                    /*
                     * To change this template, choose Tools | Templates
                     * and open the template in the editor.
                     */
                    
                    package ejb;
                    
                    import java.io.Serializable;
                    import javax.persistence.Entity;
                    import javax.persistence.GeneratedValue;
                    import javax.persistence.GenerationType;
                    import javax.persistence.Id;
                    
                    /**
                     *
                     * @author swu3
                     */
                    @Entity
                    public class NewsEntity implements Serializable {
                     private static final long serialVersionUID = 1L;
                     @Id
                     @GeneratedValue(strategy = GenerationType.AUTO)
                     private Long id;
                    
                     private String title;
                     private String body;
                    
                     public void setBody(String body) {
                     this.body = body;
                     }
                    
                     public void setTitle(String title) {
                     this.title = title;
                     }
                    
                     public String getBody() {
                     return body;
                     }
                    
                     public String getTitle() {
                     return title;
                     }
                    
                     public Long getId() {
                     return id;
                     }
                    
                     public void setId(Long id) {
                     this.id = id;
                     }
                    
                     @Override
                     public int hashCode() {
                     int hash = 0;
                     hash += (id != null ? id.hashCode() : 0);
                     return hash;
                     }
                    
                     @Override
                     public boolean equals(Object object) {
                     // TODO: Warning - this method won't work in the case the id fields are not set
                     if (!(object instanceof NewsEntity)) {
                     return false;
                     }
                     NewsEntity other = (NewsEntity) object;
                     if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                     return false;
                     }
                     return true;
                     }
                    
                     @Override
                     public String toString() {
                     return "ejb.NewsEntity[id=" + id + "]";
                     }
                    
                    }
                    


                    /*
                     * To change this template, choose Tools | Templates
                     * and open the template in the editor.
                     */
                    
                    package ejb;
                    
                    import java.util.List;
                    import javax.ejb.Stateless;
                    import javax.persistence.EntityManager;
                    import javax.persistence.PersistenceContext;
                    
                    /**
                     *
                     * @author swu3
                     */
                    @Stateless
                    public class NewsEntityFacade implements NewsEntityFacadeLocal {
                     @PersistenceContext
                     private EntityManager em;
                    
                     public void create(NewsEntity newsEntity) {
                     em.persist(newsEntity);
                     }
                    
                     public void edit(NewsEntity newsEntity) {
                     em.merge(newsEntity);
                     }
                    
                     public void remove(NewsEntity newsEntity) {
                     em.remove(em.merge(newsEntity));
                     }
                    
                     public NewsEntity find(Object id) {
                     return em.find(ejb.NewsEntity.class, id);
                     }
                    
                     public List<NewsEntity> findAll() {
                     return em.createQuery("select object(o) from NewsEntity as o").getResultList();
                     }
                    
                    }
                    


                    /*
                     * To change this template, choose Tools | Templates
                     * and open the template in the editor.
                     */
                    
                    package ejb;
                    
                    import java.util.List;
                    import javax.ejb.Local;
                    
                    /**
                     *
                     * @author swu3
                     */
                    @Local
                    public interface NewsEntityFacadeLocal {
                    
                     void create(NewsEntity newsEntity);
                    
                     void edit(NewsEntity newsEntity);
                    
                     void remove(NewsEntity newsEntity);
                    
                     NewsEntity find(Object id);
                    
                     List<NewsEntity> findAll();
                    
                    }
                    


                    /*
                     * To change this template, choose Tools | Templates
                     * and open the template in the editor.
                     */
                    
                    package web;
                    
                    import ejb.NewsEntity;
                    import ejb.NewsEntityFacadeLocal;
                    import java.io.IOException;
                    import java.io.PrintWriter;
                    import java.util.Iterator;
                    import java.util.List;
                    import javax.ejb.EJB;
                    import javax.servlet.ServletException;
                    import javax.servlet.http.HttpServlet;
                    import javax.servlet.http.HttpServletRequest;
                    import javax.servlet.http.HttpServletResponse;
                    
                    /**
                     *
                     * @author swu3
                     */
                    public class ListNews extends HttpServlet {
                     @EJB
                     private NewsEntityFacadeLocal newsEntityFacade;
                    
                     /**
                     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
                     * @param request servlet request
                     * @param response servlet response
                     */
                     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                     throws ServletException, IOException {
                     response.setContentType("text/html;charset=UTF-8");
                     PrintWriter out = response.getWriter();
                     try {
                    
                     out.println("<html>");
                     out.println("<head>");
                     out.println("<title>Servlet ListNews</title>");
                     out.println("</head>");
                     out.println("<body>");
                     out.println("<h1>Servlet ListNews at " + request.getContextPath () + "</h1>");
                     List news = newsEntityFacade.findAll();
                     for (Iterator it = news.iterator(); it.hasNext();) {
                     NewsEntity elem = (NewsEntity) it.next();
                     out.println(" <b>" + elem.getTitle() + " </b><br />");
                     out.println(elem.getBody() + "<br /> ");
                     }
                     out.println("<a href='PostMessage'>Add new message</a>");
                    
                     out.println("</body>");
                     out.println("</html>");
                    
                     } finally {
                     out.close();
                     }
                     }
                    
                     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
                     /**
                     * Handles the HTTP <code>GET</code> method.
                     * @param request servlet request
                     * @param response servlet response
                     */
                     protected void doGet(HttpServletRequest request, HttpServletResponse response)
                     throws ServletException, IOException {
                     processRequest(request, response);
                     }
                    
                     /**
                     * Handles the HTTP <code>POST</code> method.
                     * @param request servlet request
                     * @param response servlet response
                     */
                     protected void doPost(HttpServletRequest request, HttpServletResponse response)
                     throws ServletException, IOException {
                     processRequest(request, response);
                     }
                    
                     /**
                     * Returns a short description of the servlet.
                     */
                     public String getServletInfo() {
                     return "Short description";
                     }// </editor-fold>
                    
                    }
                    


                    /*
                     * To change this template, choose Tools | Templates
                     * and open the template in the editor.
                     */
                    
                    package web;
                    
                    import ejb.NewsEntity;
                    import java.io.IOException;
                    import java.io.PrintWriter;
                    import javax.annotation.Resource;
                    import javax.jms.Connection;
                    import javax.jms.ConnectionFactory;
                    import javax.jms.JMSException;
                    import javax.jms.MessageProducer;
                    import javax.jms.ObjectMessage;
                    import javax.jms.Session;
                    import javax.jms.Queue;
                    import javax.servlet.ServletException;
                    import javax.servlet.http.HttpServlet;
                    import javax.servlet.http.HttpServletRequest;
                    import javax.servlet.http.HttpServletResponse;
                    
                    /**
                     *
                     * @author swu3
                     */
                    public class PostMessage extends HttpServlet {
                    
                     @Resource(mappedName="jms/NewMessageFactory")
                     private ConnectionFactory connectionFactory;
                    
                     @Resource(mappedName="jms/NewMessage")
                     private Queue queue;
                    
                     /**
                     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
                     * @param request servlet request
                     * @param response servlet response
                     */
                     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                     throws ServletException, IOException {
                     response.setContentType("text/html;charset=UTF-8");
                    
                     // Add the following code to send the JMS message
                     String title = request.getParameter("title");
                     String body = request.getParameter("body");
                     if ((title != null) && (body != null)) {
                     try {
                     Connection connection = connectionFactory.createConnection();
                     Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                     MessageProducer messageProducer = session.createProducer(queue);
                    
                     ObjectMessage message = session.createObjectMessage();
                     // here we create NewsEntity, that will be sent in JMS message
                     NewsEntity e = new NewsEntity();
                     e.setTitle(title);
                     e.setBody(body);
                    
                     message.setObject(e);
                     messageProducer.send(message);
                     messageProducer.close();
                     connection.close();
                     response.sendRedirect("ListNews");
                    
                     } catch (JMSException ex) {
                     ex.printStackTrace();
                     }
                     }
                    
                    
                    
                    
                     PrintWriter out = response.getWriter();
                     try {
                    
                     out.println("<html>");
                     out.println("<head>");
                     out.println("<title>Servlet PostMessage</title>");
                     out.println("</head>");
                     out.println("<body>");
                     out.println("<h1>Servlet PostMessage at " + request.getContextPath () + "</h1>");
                    
                     // The following code adds the form to the web page
                     out.println("<form>");
                     out.println("Title: <input type='text' name='title'><br/>");
                     out.println("Message: <textarea name='body'></textarea><br/>");
                     out.println("<input type='submit'><br/>");
                     out.println("</form>");
                    
                    
                     out.println("</body>");
                     out.println("</html>");
                    
                     } finally {
                     out.close();
                     }
                     }
                    
                     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
                     /**
                     * Handles the HTTP <code>GET</code> method.
                     * @param request servlet request
                     * @param response servlet response
                     */
                     protected void doGet(HttpServletRequest request, HttpServletResponse response)
                     throws ServletException, IOException {
                     processRequest(request, response);
                     }
                    
                     /**
                     * Handles the HTTP <code>POST</code> method.
                     * @param request servlet request
                     * @param response servlet response
                     */
                     protected void doPost(HttpServletRequest request, HttpServletResponse response)
                     throws ServletException, IOException {
                     processRequest(request, response);
                     }
                    
                     /**
                     * Returns a short description of the servlet.
                     */
                     public String getServletInfo() {
                     return "Short description";
                     }// </editor-fold>
                    
                    }
                    


                    • 8. Re: Help need to solve the jms not bound error
                      jaikiran pai Master

                       

                      @MessageDriven(mappedName = "jms/NewMessage", activationConfig = {
                       @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
                       @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
                      
                       })
                      


                      You seem to be missing the destination property. Try this:

                      @MessageDriven(mappedName = "jms/NewMessage", activationConfig = {
                       @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
                       @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
                      @ActivationConfigProperty(propertyName="destination", propertyValue="queue/NewMessage")
                      
                       })
                      


                      Also, remember what Peter mentioned about the jndi-names of queues:

                      "PeterJ" wrote:
                      In addition, you will want to change you queue reference to:

                      @Resource(mappedName="queue/NewMessage")
                      private Queue queue;
                      




                      • 9. Re: Help need to solve the jms not bound error
                        Shaolong Wu Newbie

                        Thanks. I have tried the #1 you suggested, same error.

                        I can not remove


                        @Resource(mappedName="jms/NewMessageFactory")
                        private ConnectionFactory connectionFactory;

                        Since this line will give me compiler error:

                        Connection connection = connectionFactory.createConnection();

                        • 10. Re: Help need to solve the jms not bound error
                          Shaolong Wu Newbie

                          In GlassFish v2, the NetBean6.1 IDE generate this file automatically:

                          set/up/sun-resources.xml

                          <?xml version="1.0" encoding="UTF-8"?>
                          <!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
                          <resources>
                           <admin-object-resource enabled="true" jndi-name="jms/NewMessage" object-type="user" res-adapter="jmsra" res-type="javax.jms.Queue">
                           <description/>
                           <property name="Name" value="PhysicalQueue"/>
                           </admin-object-resource>
                           <connector-resource enabled="true" jndi-name="jms/NewMessageFactory" object-type="user" pool-name="jms/NewMessageFactoryPool">
                           <description/>
                           </connector-resource>
                           <connector-connection-pool associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-definition-name="javax.jms.QueueConnectionFactory" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="true" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="jms/NewMessageFactoryPool" pool-resize-quantity="2" resource-adapter-name="jmsra" steady-pool-size="8" validate-atmost-once-period-in-seconds="0"/>
                          </resources>


                          Just wondering where to have similar file and place we can have this in JBoss5.0.0

                          Thanks,

                          • 11. Re: Help need to solve the jms not bound error
                            Peter Johnson Master

                            The JBossAS equivalent is the *-service.xml file I mentioned earlier.

                            • 12. Re: Help need to solve the jms not bound error
                              Peter Johnson Master

                              I got it working. Here is what I did. First, I made several changes to the source code:

                              NewMessageBean.java:

                              // DIFF: removed mappedName
                              //DIFF: added destination
                              @MessageDriven(activationConfig = {
                               @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
                               @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                               @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/NewMessage")
                              })
                              ...
                               // DIFF: added unitName
                               @PersistenceContext(unitName = "newsPU")
                               private EntityManager em;
                              ...


                              NewsEntityFacade.java:
                              // DIFF: added unitName
                               @PersistenceContext(unitName = "newsPU")
                               private EntityManager em;


                              ListNews.java:
                              //DIFF: added mappedName
                               @EJB(mappedName = "NewsEntityFacade/local")
                               private NewsEntityFacadeLocal newsEntityFacade;


                              PostMessage.java:
                              //DIFF: changed mappedName
                               @Resource(mappedName = "ConnectionFactory")
                               private ConnectionFactory connectionFactory;
                              
                               //DIFF: changed mappedName
                               @Resource(mappedName = "queue/NewMessage")
                               private Queue queue;


                              I deployed four files:
                              news.jar
                              news.war
                              news-destinations-service.xml
                              news-postgresql-ds.xml

                              The contents of news.jar:
                              META-INF/persistence.xml
                              ejb/NewMessageBean.class
                              ejb/NewsEntity.class
                              ejb/NewsEntityFacade.class
                              ejb/NewsEntityFacadeLocal.class

                              The contents of news.war:
                              WEB-INF/web.xml
                              WEB-INF/classes/web/ListNews.class
                              WEB-INF/classes/web/PostMessage.class

                              I listed the contents of news-destinations-service.xml previously.

                              The contents of news-postgresql-ds.xml:
                              <datasources>
                               <local-tx-datasource>
                               <jndi-name>jdbc/newsDS</jndi-name>
                               <connection-url>jdbc:postgresql:newsdb</connection-url>
                               <driver-class>org.postgresql.Driver</driver-class>
                               <user-name>xxx</user-name>
                               <password>xxx</password>
                               </local-tx-datasource>
                              </datasources>


                              The contents of news.jar/META-INF/persistence.xml:
                              <?xml version="1.0" encoding="UTF-8"?>
                              <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                               version="1.0">
                               <persistence-unit name="newsPU">
                               <provider>org.hibernate.ejb.HibernatePersistence</provider>
                               <jta-data-source>java:/jdbc/newsDS</jta-data-source>
                               <properties>
                               <property name="hibernate.hbm2ddl.auto" value="update"/>
                               <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                               <property name="hibernate.show_sql" value="true"/>
                               <!-- These are the default for JBoss EJB3, but not for HEM: -->
                               <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                               <property name="jboss.entity.manager.factory.jndi.name" value="java:/newsEntityManagerFactory"/>
                               </properties>
                               </persistence-unit>
                              </persistence>


                              The contents of news.war/WEB-INF/web.xml:
                              <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                               version="2.5"
                              >
                               <servlet>
                               <servlet-name>ListServlet</servlet-name>
                               <servlet-class>org.jbia.jms.news.web.ListNews</servlet-class>
                               </servlet>
                               <servlet-mapping>
                               <servlet-name>ListServlet</servlet-name>
                               <url-pattern>/ListNews</url-pattern>
                               </servlet-mapping>
                              
                               <servlet>
                               <servlet-name>NewServlet</servlet-name>
                               <servlet-class>org.jbia.jms.news.web.PostMessage</servlet-class>
                               </servlet>
                               <servlet-mapping>
                               <servlet-name>NewServlet</servlet-name>
                               <url-pattern>/PostMessage</url-pattern>
                               </servlet-mapping>
                              </web-app>


                              That is it. Aimed Firefox at http://localhost:8080/news/PostMessage. filled in the form, the list page displayed with the news item.

                              I have no idea how to get NetBeans to do this. I could not even tell you how to get Eclipse to do this - I did edited all of these files in Eclipse but I did not use any wizards or 'magic' to accomplish it. In addition, I used Ant to build and deploy the various files (I reused/modified an existing build script that I used for some other MDBs).

                              • 13. Re: Help need to solve the jms not bound error
                                Shaolong Wu Newbie

                                Peter,

                                Thank you so much. I will try this out next Monday. Would you please send me all the source files which are working now, including the configuration file.

                                My email:

                                swu3@mdanderson.org

                                If possible, let's post your solution to the NetBean site. I am sure there many people will stuck there when they try the new NetBean 6.1 and JBoss 5.0.0. This will help people like me to get through with it.

                                Thanks again.