2. Using the Tutorial Examples 3. Getting Started with Web Applications 5. JavaServer Pages Technology 7. JavaServer Pages Standard Tag Library 10. JavaServer Faces Technology 11. Using JavaServer Faces Technology in JSP Pages 12. Developing with JavaServer Faces Technology 13. Creating Custom UI Components 14. Configuring JavaServer Faces Applications 15. Internationalizing and Localizing Web Applications 16. Building Web Services with JAX-WS 17. Binding between XML Schema and Java Classes 19. SOAP with Attachments API for Java 21. Getting Started with Enterprise Beans 23. A Message-Driven Bean Example 24. Introduction to the Java Persistence API 25. Persistence in the Web Tier 26. Persistence in the EJB Tier 27. The Java Persistence Query Language 28. Introduction to Security in the Java EE Platform 29. Securing Java EE Applications 31. The Java Message Service API 32. Java EE Examples Using the JMS API A Java EE Application That Uses the JMS API with a Session Bean Writing the Application Components for theclientsessionmdb Example Coding the Application Client:MyAppClient.java Coding the Publisher Session Bean Coding the Message-Driven Bean:MessageBean.java Creating Resources for theclientsessionmdb Example Building, Deploying, and Running theclientsessionmdb Example Using NetBeans IDE Building, Deploying, and Running theclientsessionmdb Example Using Ant A Java EE Application That Uses the JMS API with an Entity Overview of theclientmdbentity Example Application Writing the Application Components for theclientmdbentity Example Coding the Application Client:HumanResourceClient.java Coding the Message-Driven Beans for theclientmdbentity Example Coding the Entity Class for theclientmdbentity Example Creating Resources for theclientmdbentity Example Building, Deploying, and Running theclientmdbentity Example Using NetBeans IDE Building, Deploying, and Running theclientmdbentity Example Using Ant An Application Example That Consumes Messages from a Remote Server Overview of theconsumeremote Example Modules Writing the Module Components for theconsumeremote Example Creating Resources for theconsumeremote Example Using Two Application Servers for theconsumeremote Example Building, Deploying, and Running theconsumeremoteModules Using NetBeans IDE Building, Deploying, and Running theconsumeremote Modules Using Ant An Application Example That Deploys a Message-Driven Bean on Two Servers Overview of thesendremote Example Modules Writing the Module Components for thesendremote Example Coding the Application Client:MultiAppServerClient.java Coding the Message-Driven Bean:ReplyMsgBean.java Creating Resources for thesendremote Example Using Two Application Servers for thesendremote Example Building, Deploying, and Running thesendremote Modules Using NetBeans IDE Building, Deploying, and Running thesendremote Modules Using Ant 36. The Coffee Break Application | An Application Example That Deploys a Message-Driven Bean on Two ServersThis section, like the preceding one, explains how to write, compile, package, deploy,and run a pair of Java EE modules that use the JMSAPI and run on two Java EE servers. The modules are slightly morecomplex than the ones in the first example. The modules use the following components:
In this section, the termlocal server means the server on which both theapplication client and the message-driven bean are deployed (earth in the preceding example).The termremote server means the server on which only the message-driven bean isdeployed (jupiter in the preceding example). The section covers the following topics:
You will find the source files for this section intut-install/javaeetutorial5/examples/jms/sendremote/. Pathnames in this section are relative to this directory. Overview of thesendremote Example ModulesThis pair of modules is somewhat similar to the modules inAn Application Example That Consumes Messages from a Remote Serverin that the only components are a client and a message-driven bean. However,the modules here use these components in more complex ways. One module consistsof the application client. The other module contains only the message-driven bean andis deployed twice, once on each server. The basic steps of the modules are as follows.
Figure 32-4 illustrates the structure of this application. M1 represents the first message sentusing the local connection factory, and RM1 represents the first reply message sent bythe local MDB. M2 represents the first message sent using the remoteconnection factory, and RM2 represents the first reply message sent by the remoteMDB. Figure 32-4 A Java EE Application That Sends Messages to Two Servers ![]() Writing the Module Components for thesendremote ExampleWriting the components of the modules involves two tasks: Coding the Application Client:MultiAppServerClient.javaThe application client class,multiclient/src/java/MultiAppServerClient.java, does the following.
Coding the Message-Driven Bean:ReplyMsgBean.javaThe message-driven bean class,replybean/src/ReplyMsgBean.java, does the following:
TheonMessage method of the message-driven bean class does the following:
On both servers, the bean will consume messages from the topicjms/Topic. Creating Resources for thesendremote ExampleThis example uses the connection factory namedjms/ConnectionFactory and the topic namedjms/Topic. These objects must exist on both the local and the remote servers. This example uses an additional connection factory,jms/JupiterConnectionFactory, which communicates with theremote system; you created it inCreating Administered Objects for Multiple Systems. This connection factory must exist onthe local server. Thebuild.xml file for themulticlient module contains targets that you can useto create these resources if you deleted them previously. Using Two Application Servers for thesendremote ExampleIf you are using NetBeans IDE, you need to add the remoteserver in order to deploy the message-driven bean there. To do so, performthese steps:
Building, Deploying, and Running thesendremote Modules Using NetBeans IDETo package the modules using NetBeans IDE, perform these steps:
To deploy themulticlient module on the local server, perform these steps:
To deploy thereplybean module on the local and remote servers, perform thesesteps:
You can use the Services tab to verify thatmulticlient is deployed asan App Client Module on the local server and thatreplybean is deployedas an EJB Module on both servers. To run the application client, right-click themulticlient project and choose Run. This command returns a JAR file namedmulticlientClient.jar and then executes it. On the local system, the output of theappclient command looks something likethis: running application client container.Sent message: text: id=1 to local app serverSent message: text: id=2 to remote app serverReplyListener: Received message: id=1, text=ReplyMsgBean processed message: text: id=1 to local app serverSent message: text: id=3 to local app serverReplyListener: Received message: id=3, text=ReplyMsgBean processed message: text: id=3 to local app serverReplyListener: Received message: id=2, text=ReplyMsgBean processed message: text: id=2 to remote app serverSent message: text: id=4 to remote app serverReplyListener: Received message: id=4, text=ReplyMsgBean processed message: text: id=4 to remote app serverSent message: text: id=5 to local app serverReplyListener: Received message: id=5, text=ReplyMsgBean processed message: text: id=5 to local app serverSent message: text: id=6 to remote app serverReplyListener: Received message: id=6, text=ReplyMsgBean processed message: text: id=6 to remote app serverSent message: text: id=7 to local app serverReplyListener: Received message: id=7, text=ReplyMsgBean processed message: text: id=7 to local app serverSent message: text: id=8 to remote app serverReplyListener: Received message: id=8, text=ReplyMsgBean processed message: text: id=8 to remote app serverSent message: text: id=9 to local app serverReplyListener: Received message: id=9, text=ReplyMsgBean processed message: text: id=9 to local app serverSent message: text: id=10 to remote app serverReplyListener: Received message: id=10, text=ReplyMsgBean processed message: text: id=10 to remote app serverWaiting for 0 message(s) from local app serverWaiting for 0 message(s) from remote app serverFinishedClosing connection 1Closing connection 2 On the local system, where the message-driven bean receives the odd-numbered messages, theoutput in the server log looks like this (wrapped in logging information): ReplyMsgBean: Received message: text: id=1 to local app serverReplyMsgBean: Received message: text: id=3 to local app serverReplyMsgBean: Received message: text: id=5 to local app serverReplyMsgBean: Received message: text: id=7 to local app serverReplyMsgBean: Received message: text: id=9 to local app server On the remote system, where the bean receives the even-numbered messages, the outputin the server log looks like this (wrapped in logging information): ReplyMsgBean: Received message: text: id=2 to remote app serverReplyMsgBean: Received message: text: id=4 to remote app serverReplyMsgBean: Received message: text: id=6 to remote app serverReplyMsgBean: Received message: text: id=8 to remote app serverReplyMsgBean: Received message: text: id=10 to remote app server Undeploy the modules after you finish running the client. To undeploy the modules,perform these steps:
To remove the generated files, follow these steps:
Building, Deploying, and Running thesendremote Modules Using AntTo package the modules, perform these steps:
To deploy thereplybean module on the local and remote servers, perform thefollowing steps:
To deploy and run the client, perform these steps:
On the local system, the output looks something like this: running application client container.Sent message: text: id=1 to local app serverSent message: text: id=2 to remote app serverReplyListener: Received message: id=1, text=ReplyMsgBean processed message: text: id=1 to local app serverSent message: text: id=3 to local app serverReplyListener: Received message: id=3, text=ReplyMsgBean processed message: text: id=3 to local app serverReplyListener: Received message: id=2, text=ReplyMsgBean processed message: text: id=2 to remote app serverSent message: text: id=4 to remote app serverReplyListener: Received message: id=4, text=ReplyMsgBean processed message: text: id=4 to remote app serverSent message: text: id=5 to local app serverReplyListener: Received message: id=5, text=ReplyMsgBean processed message: text: id=5 to local app serverSent message: text: id=6 to remote app serverReplyListener: Received message: id=6, text=ReplyMsgBean processed message: text: id=6 to remote app serverSent message: text: id=7 to local app serverReplyListener: Received message: id=7, text=ReplyMsgBean processed message: text: id=7 to local app serverSent message: text: id=8 to remote app serverReplyListener: Received message: id=8, text=ReplyMsgBean processed message: text: id=8 to remote app serverSent message: text: id=9 to local app serverReplyListener: Received message: id=9, text=ReplyMsgBean processed message: text: id=9 to local app serverSent message: text: id=10 to remote app serverReplyListener: Received message: id=10, text=ReplyMsgBean processed message: text: id=10 to remote app serverWaiting for 0 message(s) from local app serverWaiting for 0 message(s) from remote app serverFinishedClosing connection 1Closing connection 2 On the local system, where the message-driven bean receives the odd-numbered messages, theoutput in the server log looks like this (wrapped in logging information): ReplyMsgBean: Received message: text: id=1 to local app serverReplyMsgBean: Received message: text: id=3 to local app serverReplyMsgBean: Received message: text: id=5 to local app serverReplyMsgBean: Received message: text: id=7 to local app serverReplyMsgBean: Received message: text: id=9 to local app server On the remote system, where the bean receives the even-numbered messages, the outputin the server log looks like this (wrapped in logging information): ReplyMsgBean: Received message: text: id=2 to remote app serverReplyMsgBean: Received message: text: id=4 to remote app serverReplyMsgBean: Received message: text: id=6 to remote app serverReplyMsgBean: Received message: text: id=8 to remote app serverReplyMsgBean: Received message: text: id=10 to remote app server Undeploy the modules after you finish running the client. To undeploy themulticlientmodule, perform these steps:
To undeploy thereplybean module, perform these steps:
To remove the generated files, use the following command in both thereplybean andmulticlient directories: ant clean Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices |