📄 7.mht
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: Tutorial for building J2EE Applications using JBOSS and ECLIPSE
Date: Sun, 5 Dec 2004 11:58:44 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="----=_NextPart_000_024D_01C4DAC1.C5216560";
type="text/html"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
This is a multi-part message in MIME format.
------=_NextPart_000_024D_01C4DAC1.C5216560
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.tusc.com.au/tutorial/html/chap7.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Tutorial for building J2EE Applications using JBOSS =
and ECLIPSE</TITLE>
<META http-equiv=3DCONTENT-TYPE content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1479" name=3DGENERATOR>
<META content=3D"Glen McCallum and Vishal Sharma" name=3DAUTHOR>
<META content=3D20030729;9513900 name=3DCREATED>
<META content=3DVishal name=3DCHANGEDBY>
<META content=3D20031118;15354000 name=3DCHANGED>
<META=20
content=3D"Tutorial for building J2EE Applications using Eclipse, =
Lomboz, Jboss and Xdoclet."=20
name=3DDESCRIPTION>
<META=20
content=3D"J2EE, Traininig,Tutorial, J2EE, Lomboz, Eclipse, Jboss, =
Xdoclet, J2EE Patterns, EJB, Servlets, JSP, BMP, CMP, Session, =
Configuration, DAO"=20
name=3DKEYWORDS>
<META content=3D"14 days" name=3Drevisit-after><!-- Meta tags --><!-- =
Copyright =A9 2003 TUSC. All rights reserved.--><!--- Header --></HEAD>
<BODY lang=3Den-US dir=3Dltr>
<FORM name=3DsearchForm action=3D../../../../search/index.php =
method=3Dpost>
<TABLE style=3D"PAGE-BREAK-BEFORE: always" cellSpacing=3D0 =
cellPadding=3D4 width=3D957=20
bgColor=3D#0a6a91 border=3D0>
<COLGROUP>
<COL width=3D154>
<COL width=3D276>
<COL width=3D21>
<COL width=3D43>
<COL width=3D119>
<COL width=3D31>
<COL width=3D50>
<COL width=3D178>
<COL width=3D14>
<TBODY>
<TR>
<TD vAlign=3Dtop width=3D154>
<P><A href=3D"http://www.tusc.com.au./contact_us.php"><IMG =
height=3D125=20
alt=3DTUSC=20
=
src=3D"http://www.tusc.com.au/tutorial/images/header/tuscJ2eeLogo.gif"=20
width=3D149 align=3Dbottom border=3D0 =
name=3DGraphic1></A></P></TD>
<TD vAlign=3Dtop width=3D276>
<P><IMG height=3D73 alt=3D"Reliable, On-Time Delivery."=20
src=3D"http://www.tusc.com.au/tutorial/images/header/reliable.gif" =
width=3D268=20
align=3Dbottom border=3D0 name=3DGraphic2><!--search table =
--></P></TD>
<TD width=3D21></TD>
<TD width=3D43>
<P><IMG height=3D9 alt=3DSearch=20
src=3D"http://www.tusc.com.au/tutorial/images/elements/search.gif" =
width=3D41=20
align=3Dbottom border=3D0 name=3DGraphic3></P></TD>
<TD width=3D119>
<P><INPUT maxLength=3D50 size=3D12 name=3DKEYWORD></P></TD>
<TD width=3D31>
<P><INPUT type=3Dimage height=3D18 width=3D29=20
src=3D"http://www.tusc.com.au/tutorial/images/btns/go.gif" =
align=3Dbottom=20
name=3Dgo><INPUT type=3Dhidden value=3DY =
name=3DSECTION_ALL></P></TD>
<TD vAlign=3Dtop width=3D50>
<P><IMG height=3D73 alt=3DSpacer=20
src=3D"http://www.tusc.com.au/tutorial/images/invis.gif" =
width=3D50=20
align=3Dbottom border=3D0 name=3DGraphic5></P></TD>
<TD vAlign=3Dtop width=3D154>
<P><A href=3D"http://www.tusc.com.au./contact_us.php"><IMG =
height=3D125=20
alt=3DTUSC=20
=
src=3D"http://www.tusc.com.au/tutorial/images/header/tuscJ2eeLogo.gif"=20
width=3D149 align=3Dbottom border=3D0 =
name=3DGraphic1></A></P></TD>
<TD width=3D14>
<P><IMG height=3D10 alt=3Dspacer=20
src=3D"http://www.tusc.com.au/tutorial/images/invis.gif" =
width=3D14=20
align=3Dbottom border=3D0 name=3DGraphic58> =
</P></TD></TR></TBODY></TABLE></FORM>
<H2 align=3Dcenter><!--- Header finished -->Tutorial for building J2EE=20
Applications using JBOSS and ECLIPSE <IMG height=3D2=20
src=3D"http://www.tusc.com.au/tutorial/images/redrulr5.gif" width=3D775 =
align=3Dmiddle=20
border=3D0 name=3DGraphic1></H2>
<P><BR><BR></P>
<H1>Chapter 7. </H1>
<P><IMG height=3D2 =
src=3D"http://www.tusc.com.au/tutorial/images/blurulr6.gif"=20
width=3D785 align=3Dmiddle border=3D0 name=3DGraphic2></P>
<H2>Creating a Message Driven Bean</H2>
<P>This chapter covers how to create a Message Driven Bean (MDB) EJB =
component.=20
We will create two MDB beans, DeliverItems and RequestItems as shown =
below. The=20
DeliverItems bean will replenish the stocks of various items within =
MyStore, and=20
the RequestItems bean will send requests to various suppliers to deliver =
items=20
which are out of stock. The MyStore manager will issue/send this =
request. </P>
<P><IMG height=3D489=20
src=3D"http://www.tusc.com.au/tutorial/images/chap7/J2EEMDBFlowDiagram.pn=
g"=20
width=3D706 align=3Dleft border=3D0 name=3DGraphic7><BR =
clear=3Dleft><BR><BR></P>
<P><FONT color=3D#800000><I>Note : Both message-driven beans access the=20
StoreAccess bean through its remote interface, even though the =
StoreAcessBean is=20
in the same JVM. This is because we have implemented StoreAccessBean as =
a Remote=20
Bean, so it only exposes its remote interface. However, in accessing the =
Manager=20
and Item beans, which are also used by these message-driven beans we =
<U>can</U>=20
use their local interfaces as they are in the same JVM, and we have =
exposed=20
their local interfaces.</I></FONT></P>
<H3>Tasks :</H3>
<OL>
<LI>
<P>Create a MD bean named RequestItems under package =
au.com.tusc.mdb.</P>
<LI>
<P>Create an Immutable Value Object named RequestItem under package=20
au.com.tusc.mdb. Add attributes and implement their accessor and =
mutator=20
methods. The attributes are: </P>
<P><FONT color=3D#000000><B>private String username</B></FONT></P>
<P><FONT color=3D#000000><B>private String passwd</B></FONT></P>
<P><FONT color=3D#000000><B>private String itemID</B></FONT></P>
<P><FONT color=3D#000000><B>private int quantity</B></FONT></P>
<LI>
<P>Implement the onMessage method.</P>
<LI>
<P>Deploy the RequestItems Bean.</P>
<LI>
<P><FONT color=3D#000000><FONT face=3D"Bitstream Vera Serif">Create =
your test=20
client named RequestMDBClient under package au.com.tusc.mdb.=20
</FONT></FONT></P>
<LI>
<P><FONT face=3D"Nimbus Roman No9 L"><FONT =
color=3D#000000>A</FONT></FONT>dd a=20
method named testMDBBean with the following signature and implement =
it.</P>
<P><FONT color=3D#000000><B>public void testMDBBean</B> </FONT></P>
<LI>
<P><FONT color=3D#000000><FONT face=3D"Bitstream Vera Serif">Run your =
client and=20
test the bean.</FONT></FONT></P></LI></OL>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><BR></H3>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Create RequestItems =
MDB Bean=20
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P><B>Go To Package Explorer > Expand Mystore (project) node > =
select src,=20
right click and a menu will pop up.</B></P>
<P><B>On the pop up menu > New > Lomboz EJB Creation =
Wizard.</B></P>
<P><B>Enter package name au.com.tusc.mdb, bean name RequestItems and =
select bean=20
type as Message Drive Bean (Queue) as shown below.</B></P>
<P><IMG height=3D420=20
src=3D"http://www.tusc.com.au/tutorial/images/chap7/CreateNewEJB.png" =
width=3D516=20
align=3Dleft border=3D0 name=3DGraphic17><BR clear=3Dleft><BR><BR></P>
<P><B>Press Finish.</B></P>
<P><B>This will create a package named au.com.tusc.mdb under src and=20
RequestItemsBean within that package as shown below.</B></P>
<P align=3Dleft><IMG height=3D442=20
src=3D"http://www.tusc.com.au/tutorial/images/chap7/RequetItemsBean.png" =
width=3D662=20
align=3Dleft border=3D0 name=3DGraphic22><BR clear=3Dleft><FONT =
color=3D#800000><I>Note :=20
Message-driven beans listen for messages from a JMS Producer, which gets =
information from a producer (perhaps another bean) and transfers it to =
the=20
relevant Consumer bean. Since it is only responsible for processing such =
messages, it doesn't need any helper classes such as Remote and =
RemoteHome=20
interfaces, Util classes, DAO class, etc. like our previous types of =
beans. The=20
only helper classes we have to create are immutable value objects, which =
will be=20
responsible for holding the information extracted from messages and then =
transferred to the bean(s).</I></FONT></P>
<P><B>Let's examine what methods and tags are generated by the EJB =
creation=20
wizard..</B></P>
<P><B>It creates one @ejb.bean tag which assigns the name, transaction =
type,=20
destination type and some other properties as shown below. </B></P>
<P><IMG height=3D236=20
src=3D"http://www.tusc.com.au/tutorial/images/chap7/RequetItemsBeanTag.pn=
g"=20
width=3D546 align=3Dleft border=3D0 name=3DGraphic26><BR =
clear=3Dleft><BR><BR></P>
<P><B>Unlike our previous beans it has a setMessageContext method for =
setting=20
the context.</B></P>
<P><IMG height=3D128=20
src=3D"http://www.tusc.com.au/tutorial/images/chap7/RequetItemsBeanSetMes=
sageMethod.png"=20
width=3D527 align=3Dleft border=3D0 name=3DGraphic23><BR =
clear=3Dleft><BR><BR></P>
<P><B>It has ejbCreate and ejbRemove methods like the other types of =
beans, as=20
shown below. </B></P>
<P><IMG height=3D189=20
src=3D"http://www.tusc.com.au/tutorial/images/chap7/RequetItemsEjbMethods=
.png"=20
width=3D364 align=3Dleft border=3D0 name=3DGraphic24><BR =
clear=3Dleft><BR><BR></P>
<P><B>It has a new method named onMessage which is the one of =
significance to=20
us, where all the business logic will be written (as shown below). =
</B></P>
<P><IMG height=3D266=20
src=3D"http://www.tusc.com.au/tutorial/images/chap7/RequetItemOnMessage.p=
ng"=20
width=3D602 align=3Dleft border=3D0 name=3DGraphic6><BR =
clear=3Dleft><BR><BR></P>
<P>O<B>nce a message is received from the JMS producer as a Message =
object, its=20
data is extracted and filled into the immutable value object and then=20
transferred to the relevant bean. This is covered later on in this=20
chapter.</B></P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -