Movatterモバイル変換


[0]ホーム

URL:


Document Information

Preface

Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  Java Servlet Technology

5.  JavaServer Pages Technology

6.  JavaServer Pages Documents

7.  JavaServer Pages Standard Tag Library

8.  Custom Tags in JSP Pages

9.  Scripting in JSP Pages

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

Part III Web Services

16.  Building Web Services with JAX-WS

17.  Binding between XML Schema and Java Classes

18.  Streaming API for XML

19.  SOAP with Attachments API for Java

Part IV Enterprise Beans

20.  Enterprise Beans

21.  Getting Started with Enterprise Beans

22.  Session Bean Examples

23.  A Message-Driven Bean Example

Part V Persistence

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

Part VI Services

28.  Introduction to Security in the Java EE Platform

29.  Securing Java EE Applications

30.  Securing Web 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

33.  Transactions

34.  Resource Connections

35.  Connector Architecture

Part VII Case Studies

36.  The Coffee Break Application

37.  The Duke's Bank Application

Part VIII Appendixes

A.  Java Encoding Schemes

B.  About the Authors

Index

 

The Java EE 5 Tutorial

Java Coffee Cup logo
PreviousContentsNext

An Application Example That Consumes Messages from a Remote Server

This section and the following section explain how to write, compile, package, deploy,and run a pair of Java EE modules that run on twoJava EE servers and that use the JMS API to interchange messages witheach other. It is a common practice to deploy different components of anenterprise application on different systems within a company, and these examples illustrate ona small scale how to do this for an application that uses theJMS API.

However, the two examples work in slightly different ways. In this first example,the deployment information for a message-driven bean specifies the remote server from whichit willconsume messages. In the next example, the same bean is deployedon two different servers, so it is the client module that specifies theservers (one local, one remote) to which it issending messages.

This first example divides the example inChapter 23, A Message-Driven Bean Example into two modules (notapplications): one containing the application client, and the other containing the message-driven bean.

This section covers the following topics:

You will find the source files for this section intut-install/javaeetutorial5/examples/jms/consumeremote/. Pathnames in this section are relative to this directory.

Overview of theconsumeremote Example Modules

Except for the fact that it is packaged as two separate modules,this example is very similar to the one inChapter 23, A Message-Driven Bean Example:

  • One module contains the application client, which runs on the remote system and sends three messages to a queue.

  • The other module contains the message-driven bean, which is deployed on the local server and consumes the messages from the queue on the remote server.

The basic steps of the modules are as follows.

  1. The administrator starts two Java EE servers, one on each system.

  2. On the local server, the administrator deploys the message-driven bean module, which uses a connection factory that specifies the remote server where the client is deployed.

  3. On the remote server, the administrator places the client JAR file.

  4. The client module sends three messages to a queue.

  5. The message-driven bean consumes the messages.

Figure 32-3 illustrates the structure of this application. You can see that it isalmost identical toFigure 23-1 except that there are two Java EE servers. The queueused is the one on the remote server; the queue must also existon the local server for resource injection to succeed.

Figure 32-3 A Java EE Application That Consumes Messages from a Remote Server

Diagram of application showing a message-driven bean that consumes messages from an application client on a remote server

Writing the Module Components for theconsumeremote Example

Writing the components of the modules involves

  • Coding the application client

  • Coding the message-driven bean

The application client,jupiterclient/src/java/SimpleClient.java, is almost identical to the one inThesimplemessage Application Client.

Similarly, the message-driven bean,earthmdb/src/java/MessageBean.java, is almost identical to the one inThe Message-Driven Bean Class.

The only major difference is that the client and the bean arepackaged in two separate modules.

Creating Resources for theconsumeremote Example

For this example, the message-driven bean uses the connection factory namedjms/JupiterConnectionFactory, whichyou created inCreating Administered Objects for Multiple Systems. Use the Admin Console to verify that the connectionfactory still exists and that itsAddressList property is set to the nameof the remote system. Because this bean must use a specific connection factory, theconnection factory is specified in themdb-connection-factory element of thesun-ejb-jar.xml file.

If you deleted the connection factory, you can recreate it as follows:

  1. Go to the following directory:

    tut-install/javaeetutorial5/examples/jms/consumeremote/earthmdb/
  2. Type the following command:

    ant create-remote-factory -Dsys=remote-system-name

    Replaceremote-system-name with the actual name of the remote system.

The application client can use any connection factory that exists on the remoteserver; it usesjms/ConnectionFactory. Both components use the queue namedjms/Queue, which youcreated inCreating JMS Administered Objects for the Synchronous Receive Example.

Using Two Application Servers for theconsumeremote Example

As inRunning JMS Client Programs on Multiple Systems, the two servers are namedearth andjupiter.

The Application Server must be running on both systems.

Which system you use to package and deploy the modules and whichsystem you use to run the client depend on your network configuration (whichfile system you can access remotely). These instructions assume that you can access thefile system ofjupiter fromearth but cannot access the file system ofearth fromjupiter. (You can use the same systems forjupiter andearththat you used inRunning JMS Client Programs on Multiple Systems.)

You can package both modules onearth and deploy the message-driven bean there.The only action you perform onjupiter is running the client module.

Building, Deploying, and Running theconsumeremoteModules Using NetBeans IDE

To package the modules using NetBeans IDE, perform these steps:

  1. In NetBeans IDE, choose Open Project from the File menu.

  2. In the Open Project dialog, navigate totut-install/javaeetutorial5/examples/jms/consumeremote/.

  3. Select theearthmdb folder.

  4. Select the Open as Main Project check box.

  5. Click Open Project.

  6. Right-click theearthmdb project and choose Build.

    This command creates a JAR file that contains the bean class file and thesun-ejb-jar.xml deployment descriptor file.

  7. Choose Open Project from the File menu.

  8. Select thejupiterclient folder.

  9. Select the Open as Main Project check box.

  10. Click Open Project.

  11. Right-click thejupiterclient project and choose Build.

    This target creates a JAR file that contains the client class file and a manifest file.

To deploy theearthmdb module and run the application client, perform these steps:

  1. Right-click theearthmdb project and choose Set as Main Project.

  2. Right-click theearthmdb project and choose Undeploy and Deploy.

  3. Copy thejupiterclient module to the remote system (jupiter):

    1. In a terminal window, change to the directorytut-install/javaeetutorial5/examples/jms/consumeremote/jupiterclient/dist/.

    2. Type a command like the following:

      cp jupiterclient.jar F:/

      That is, copy the client JAR file to a location on the remote filesystem.

  4. Go to the directory on the remote system where you copied the client JAR file.

  5. Use the following command:

    appclient -client jupiterclient.jar

Onjupiter, the output of theappclient command looks like this:

Sending message: This is message 1Sending message: This is message 2Sending message: This is message 3

Onearth, the output in the server log looks something like this (wrappedin logging information):

MESSAGE BEAN: Message received: This is message 1MESSAGE BEAN: Message received: This is message 2MESSAGE BEAN: Message received: This is message 3

Undeploy the message-driven bean after you finish running the client. To undeploy theearthmdb module, perform these steps:

  1. Click the Services tab.

  2. Expand the Servers node.

  3. Expand the Application Server node.

  4. Expand the Applications node.

  5. Expand the EJB Modules node.

  6. Right-clickearthmdb and choose Undeploy.

To remove the generated files, follow these steps:

  1. Right-click theearthmdb project and choose Clean.

  2. In the command line window from which you copied the client JAR file, go to a directory other than thejupiterclient/dist directory.

  3. Right-click thejupiterclient project and choose Clean.

You can also delete thejupiterclient.jar file from the remote filesystem.

Building, Deploying, and Running theconsumeremote Modules Using Ant

To package the modules using Ant, perform these steps:

  1. Go to the following directory:

    tut-install/javaeetutorial5/examples/jms/consumeremote/earthmdb/
  2. Type the following command:

    ant

    This command creates a JAR file that contains the bean class file and thesun-ejb-jar.xml deployment descriptor file.

  3. Go to thejupiterclient directory:

    cd ../jupiterclient
  4. Type the following command:

    ant

    This target creates a JAR file that contains the client class file and a manifest file.

To deploy theearthmdb module, perform these steps:

  1. Change to the directoryearthmdb:

    cd ../earthmdb
  2. Type the following command:

    ant deploy

To copy thejupiterclient module to the remote system, perform these steps:

  1. Change to the directoryjupiterclient/dist:

    cd ../jupiterclient/dist
  2. Type a command like the following:

    cp jupiterclient.jar F:/

    That is, copy the client JAR file to a location on the remote filesystem.

To run the client, perform the following steps:

  1. Go to the directory on the remote system (jupiter) where you copied the client JAR file.

  2. Use the following command:

    appclient -client jupiterclient.jar

Onjupiter, the output of theappclient command looks like this:

Sending message: This is message 1Sending message: This is message 2Sending message: This is message 3

Onearth, the output in the server log looks something like this (wrappedin logging information):

MESSAGE BEAN: Message received: This is message 1MESSAGE BEAN: Message received: This is message 2MESSAGE BEAN: Message received: This is message 3

Undeploy the message-driven bean after you finish running the client. To undeploy theearthmdb module, perform these steps:

  1. Change to the directoryearthmdb.

  2. Type the following command:

    ant undeploy

You can also delete thejupiterclient.jar file from the remote filesystem.

To remove the generated files, use the following command in both theearthmdb andjupiterclient directories:

ant clean
PreviousContentsNext

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices


[8]ページ先頭

©2009-2025 Movatter.jp