📄 connect the enterprise with the jca, part 2.htm
字号:
desc;<BR> }<BR><BR> public void
setDescription(String
desc)<BR> {<BR> this.desc
= desc;<BR> }<BR><BR> public void
setReference(Reference
reference)<BR> {<BR> this.reference
= reference;<BR> }<BR><BR> public
Reference
getReference()<BR> {<BR> return
reference;<BR> }<BR>}<BR></CODE>
<P><FONT size=+1><STRONG>Compile and build myjca.rar </STRONG></FONT><BR>Now
that you've seen the adapter' source code, it's time to build the
<CODE>myjca.rar</CODE> file. First, I assume you have a source directory
containing two subdirectories: <CODE>myjca</CODE> containing the
<CODE>.java</CODE> files, and <CODE>META-INF</CODE> containing the configuration
files.
<P>To compile and build the rar file:
<OL>
<LI>Compile the class files by typing <CODE>javac *.java</CODE> in the
<CODE>myjca</CODE> directory
<LI>Build the <CODE>myjca.jar</CODE> from the source directory by entering
<CODE>jar cvf myjca.jar myjca</CODE>
<LI>Create the rar file using the <CODE>myjca.jar</CODE> and the
<CODE>META-INF</CODE> directory by typing <CODE>jar cvf myjca.rar myjca.jar
META-INF</CODE> </LI></OL>
<P><FONT size=+1><STRONG>Deployment output </STRONG></FONT><BR>Once you deploy
the adapter rar file (using the steps outlined in the beginning of the article),
you should see the output of the <CODE>println</CODE> statements contained in
most of the adapter's methods. You should see output similar to the following as
the adapter deploys:
<P><CODE>
<P><BR>In MyManagedConnectionFactory.constructor<BR>In
MyManagedConnectionFactory.createManagedConnection<BR>In
MyManagedConnection<BR>In MyConnectionEventListener<BR>In
MyManagedConnection.getMetaData<BR>In MyConnectionMetaData.constructor<BR>In
MyConnectionMetaData.getEISProductName<BR>In
MyConnectionMetaData.getEISProductVersion<BR>In
MyConnectionMetaData.getMaxConnections<BR></CODE>
<P>The output above shows the <CODE>ManagedConnectionFactory</CODE>'s creation,
which then invoked the <CODE>ManagedConnection</CODE>, which in turn created the
<CODE>ConnectionEventListener</CODE>. Finally, you see that the application
server called the <CODE>ConnectionMetaData</CODE>.
<P><FONT size=+1><STRONG>Get a connection </STRONG></FONT><BR>Now that you've
deployed the adapter successfully, let's use the adapter to obtain a connection.
The following JSP (JavaServer Pages) file does just that, by looking up the
connection using JNDI (Java Naming and Directory Interface), then calling the
<CODE>getConnection()</CODE> method on the <CODE>DataSource</CODE>:
<P><CODE>
<P><BR><html><BR><head><BR>
<title>Connector example</title><BR></head><BR><body
bgcolor=#ffffff><BR><%@ page import="javax.naming.*, java.sql.*,
javax.sql.*" %><BR><% <BR> InitialContext initCtx =
null;<BR> Object obj =
null;<BR> try
{<BR> initCtx = new
InitialContext();<BR> DataSource ds =
(javax.sql.DataSource)<BR> initCtx.lookup("MyConnector"); <BR> obj
= ds.getConnection();<BR> } catch(NamingException ne)
{<BR> System.out.println("Error
with context: " +
ne); <BR> }<BR><BR>%><BR><h2>Performed
a lookup and got a connection</h2><BR></body><BR></html>
<BR></CODE>
<P>You'll see the following output when the adapter acquires the connection:
<P><CODE>
<P><BR>In MyManagedConnectionFactory.createConnectionFactory,1<BR>In
MyDataSource<BR>In MyDataSource.getConnection,1<BR>In
MyManagedConnectionFactory.matchManagedConnections<BR>In
MyManagedConnectionFactory.createManagedConnection<BR>In
MyManagedConnection<BR>In MyConnectionEventListener<BR>In
MyManagedConnection.getMetaData<BR>In MyConnectionMetaData.constructor<BR>In
MyConnectionMetaData.getEISProductName<BR>In
MyConnectionMetaData.getEISProductVersion<BR>In
MyConnectionMetaData.getMaxConnections<BR>In
MyManagedConnection.getUserName<BR>In MyManagedConnection.getConnection<BR>In
MyConnection<BR>In MyManagedConnection.addMyConnection<BR>In
MyManagedConnection.addConnectionEventListener<BR></CODE>
<P>As you can see, many classes help obtain the connection.
<P><FONT size=+1><STRONG>Lessons learned </STRONG></FONT><BR>As you've likely
figured out, the JCA specification's complexity makes implementing even a basic
adapter a large undertaking. Moreover, the task grows larger when you add the
transaction and security contracts (not implemented for this sample adapter), as
well as the CCI interfaces.
<P>The complexity shows that the JCA specification is really oriented towards
commercial software vendors implementing adapters and their consulting/IT
customers using them. In this context, the JCA interfaces' complexity makes
sense, although a less flexible, simpler interface version would be nice.
<P>Therefore, if you are considering using JCA to connect to a legacy system in
your enterprise, you'd benefit from leveraging an off-the-shelf adapter rather
than developing your own. If the system to which you need connectivity does not
have a JCA adapter (that is, for a homegrown system), consider an alternative
approach. Using Web services to connect to such a system may offer the best
solution.
<P>For its part, while JCA is still a new standard, it shows promise for making
the task of integrating with an EIS less daunting. <IMG height=12
src="Connect the enterprise with the JCA, Part 2.files/jw-dingbat.gif" width=22>
<P><BR></P>
<P><STRONG>About the author</STRONG><BR><A href="javascript:openBrWindow()">Dirk
Reinshagen</A>, an architect at Zaplet, Inc., a commercial software vendor in
the San Francisco Bay Area, has more than eight years of software architecture
and development experience. He holds a B.S. in computer science from Tufts
University. <BR></P>
<P>
<UL><A name=resources></A><STRONG>Resources</STRONG> <BR>
<LI>To obtain the myjca.rar source code file (contained in jw-0201-jca2.zip),
go to: <BR><A
href="http://www.javaworld.com/javaworld/jw-02-2002/jca/jw-0201-jca2.zip">http://www.javaworld.com/javaworld/jw-02-2002/jca/jw-0201-jca2.zip</A><BR>
<LI>"Connect the Enterprise with the JCA," Dirk Reinshagen
(<EM>JavaWorld</EM>)
<UL>
<LI><A
href="http://www.javaworld.com/javaworld/jw-11-2001/jw-1121-jca.html">Part
1. A look at the J2EE Connector Architecture</A> (November 2001)
<LI><A
href="http://www.javaworld.com/javaworld/jw-02-2002/jw-0201-jca2.html">Part
2. Build your own J2EE Connector Architecture adapter</A> (February 2002)
</LI></UL>
<LI>Dirk Reinshagen's "XML Messaging" series <EM>(JavaWorld):</EM>
<UL>
<LI><A
href="http://www.javaworld.com/javaworld/jw-03-2001/jw-0302-xmlmessaging.html">Part
1: Write a simple XML message broker for custom XML messages</A> (March
2001)
<LI><A
href="http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-xmlmessaging2.html">Part
2: XML messaging the SOAP way</A> (June 2001)
<LI><A
href="http://www.javaworld.com/javaworld/jw-09-2001/jw-0914-xmlmessage3.html?">Part
3: JAXM and ebXML set the new standard for XML messaging</A> (September
2001) </LI></UL>
<LI>The JCA page from java.sun.com: <BR><A
href="http://java.sun.com/j2ee/connector/">http://java.sun.com/j2ee/connector/</A><BR>
<LI>The Java Community Process's JSR 112 page, from which JCA 2.0 will spring:
<BR><A
href="http://www.jcp.org/jsr/detail/112.jsp">http://www.jcp.org/jsr/detail/112.jsp</A><BR>
<LI>For more Java 2 Platform, Enterprise Edition stories, visit the
<STRONG>J2EE</STRONG> section of <EM>JavaWorld</EM>'s Topical Index: <BR><A
href="http://www.javaworld.com/channel_content/jw-j2ee-index.shtml">http://www.javaworld.com/channel_content/jw-j2ee-index.shtml</A><BR>
<LI>Talk about the JCA in our <STRONG>Enterprise Java</STRONG> discussion:
<BR><A
href="http://forums.devworld.com/webx?50@@.ee6b80a">http://forums.devworld.com/webx?50@@.ee6b80a</A><BR>
<LI>Sign up for <EM>JavaWorld</EM>'s free weekly <EM>Enterprise Java</EM>
email newsletter: <BR><A
href="http://www.javaworld.com/subscribe">http://www.javaworld.com/subscribe</A><BR>
<LI>You'll find a wealth of IT-related articles from our sister publications
at <A href="http://www.idg.net/jump?id=1100">IDG.net</A> </LI></UL><BR>
<P></P><!-- REPLACE SIDEBAR --></FONT><!-- ## MAIN CONTENT ENDS HERE ### --></TD><TD
width="8"><IMG height=1
src="Connect the enterprise with the JCA, Part 2.files/spacer.gif" width=8
border=0></TD> </TR></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TBODY>
<TR>
<TD align=middle width=186 bgColor=#006699><NOBR><FONT
face=Verdana,Geneva,Arial,Helvetica,sans-serif size=1></FONT></NOBR><A
href="http://www.javaworld.com/"><IMG height=81
src="Connect the enterprise with the JCA, Part 2.files/top_jwlogo.gif"
width=186 border=0></A></TD>
<TD vAlign=bottom width=8 bgColor=#cccccc><IMG height=8
src="Connect the enterprise with the JCA, Part 2.files/c_blgrylftbottom.gif"
width=8 border=0></TD>
<TD vAlign=center align=middle width="100%" bgColor=#cccccc><!-- BOTTOM 468x60 AD STARTS HERE jw-articles-bottom-ad.txt -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><FONT face=Arial,Helvetica,Sans-serif color=#000000
size=-2>Advertisement: Support JavaWorld, click here!</FONT><BR>
<SCRIPT language=JavaScript
src="Connect the enterprise with the JCA, Part 2.files/spinbox.macworld[2]"></SCRIPT>
<NOSCRIPT><A href="http://spinbox.macworld.com/?SHT=jw-BottomBanner"
target=_top><IMG
src="Connect the enterprise with the JCA, Part 2.files/jw_house468x60.gif"></A>
</NOSCRIPT></TD></TR></TBODY></TABLE><!-- BOTTOM 468x60 AD ENDS HERE --></TD>
<TD width=8><IMG height=8
src="Connect the enterprise with the JCA, Part 2.files/spacer.gif" width=8
border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center bgColor=#006699
border=0>
<TBODY>
<TR>
<TD vAlign=center align=middle width="100%"><FONT
face=Verdana,Geneva,Arial,Helvetica,sans-serif color=#ffffff size=1>
<P><BR><A href="http://www.javaworld.com/"><FONT
color=#ffffff>HOME</FONT></A> | <A
href="http://www.javaworld.com/features/index.shtml"><FONT
color=#ffffff>FEATURED TUTORIALS</FONT></A> | <A
href="http://www.javaworld.com/columns/index.shtml"><FONT
color=#ffffff>COLUMNS</FONT></A> | <A
href="http://www.javaworld.com/news-reviews/index.shtml"><FONT
color=#ffffff>NEWS & REVIEWS</FONT></A> | <A
href="http://forums.devworld.com/webx?13@@.ee6b802"><FONT
color=#ffffff>FORUM</FONT></A> | <A
href="http://www.javaworld.com/resources/index.shtml"><FONT
color=#ffffff>JW RESOURCES</FONT></A> | <A
href="http://www.javaworld.com/info/jw-about-index.shtml"><FONT
color=#ffffff>ABOUT JW</FONT></A> | <A
href="http://www.javaworld.com/feedback"><FONT
color=#ffffff>FEEDBACK</FONT></A> </P>
<P><A
href="http://www.javaworld.com/javaworld/common/jw-copyright.html"><FONT
color=#ffffff>Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -