⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jaxr5.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  <head>    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />    <meta http-equiv="Content-Style-Type" content="text/css" />    <title>Using JAXR Clients in J2EE Applications</title>    <link rel="StyleSheet" href="document.css" type="text/css" media="all" />    <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" />    <link rel="Table of Contents" href="J2EETutorialTOC.html" />    <link rel="Previous" href="JAXR4.html" />    <link rel="Next" href="JAXR6.html" />    <link rel="Index" href="J2EETutorialIX.html" />  </head>  <body>    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="JAXR4.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JAXR6.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <blockquote><a name="wp150745"> </a><h2 class="pHeading1">Using JAXR Clients in J2EE Applications</h2><a name="wp150746"> </a><p class="pBody">You can create J2EE applications that use JAXR clients to access registries. This section explains how to write, compile, package, deploy, and run a J2EE application that uses JAXR to publish an organization to a registry and then query the registry for that organization. The application in this section uses two components, an application client and a stateless session bean.</p><a name="wp150747"> </a><p class="pBody">The section covers the following topics:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp150751"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150786">Coding the Application Client: MyAppClient.java</a></li></div><a name="wp150755"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150792">Coding the PubQuery Session Bean</a></li></div><a name="wp150759"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150800">Compiling the Source Files</a></li></div><a name="wp150763"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150805">Starting the J2EE Application Server</a></li></div><a name="wp150767"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150812">Creating JAXR Resources</a></li></div><a name="wp150771"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150822">Creating and Packaging the Application</a></li></div><a name="wp150775"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150950">Deploying the Application</a></li></div><a name="wp150779"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150961">Running the Application Client</a></li></div></ul></div><a name="wp150784"> </a><p class="pBody">You will find the source files for this section in the directory <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/jaxr/clientsession</code>. Path names in this section are relative to this directory.</p><a name="wp151064"> </a><p class="pBody">The following directory contains a built version of this application:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;<code class="cVariable">INSTALL</code>&gt;/j2eetutorial14/examples/jaxr/provided-ears<a name="wp151065"> </a></pre></div><a name="wp151066"> </a><p class="pBody">If you run into difficulty at any time, you can open the EAR file in <code class="cCode">deploytool</code> and compare that file to your own version. You will probably have to add a new version of the properties file that specifies a different Tomcat port.</p><a name="wp150786"> </a><h3 class="pHeading2">Coding the Application Client: MyAppClient.java</h3><a name="wp150787"> </a><p class="pBody">The application client class, <code class="cCode"><a  href="../examples/jaxr/clientsession/src/MyAppClient.java" target="_blank">src/MyAppClient.java, </a></code>obtains a handle to the PubQuery enterprise bean's remote home interface, using the JNDI API naming context <code class="cCode">java:comp/env</code>. The program then creates an instance of the bean and calls the bean's two business methods, <code class="cCode">executePublish</code> and <code class="cCode">executeQuery</code>.</p><a name="wp150788"> </a><p class="pBody">Before you compile the application, edit the <code class="cCode">PubQueryBeanExamples.properties</code> file the same way you edited the <code class="cCode">JAXRExamples.properties</code> file to run the simple examples.</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp150789"> </a><div class="pSmartList1"><li>If you are using the Java WSDP Registry Server, specify the correct host and port values for the <code class="cCode">queryManagerURL</code> and <code class="cCode">lifeCycleManagerURL</code> entries. To use another registry, comment out the property that specifies the Registry Server and remove the comment from the other registry.</li></div><a name="wp150790"> </a><div class="pSmartList1"><li>If you are using a public registry, change the values for the <code class="cCode">http.proxyHost</code> and <code class="cCode">https.proxyHost</code> entries so that they specify the the system on your network through which you access the Internet.</li></div></ol></div><a name="wp150792"> </a><h3 class="pHeading2">Coding the PubQuery Session Bean</h3><a name="wp150793"> </a><p class="pBody">The PubQuery bean is a stateless session bean with one <code class="cCode">create</code> method and two business methods. The bean uses remote interfaces rather than local interfaces because it is accessed from outside the EJB container.</p><a name="wp150794"> </a><p class="pBody">The remote home interface source file is <code class="cCode"><a  href="../examples/jaxr/clientsession/src/PubQueryHome.java" target="_blank">src/PubQueryHome.java</a></code>.</p><a name="wp150795"> </a><p class="pBody">The remote interface, <code class="cCode"><a  href="../examples/jaxr/clientsession/src/PubQueryRemote.java" target="_blank">src/PubQueryRemote.java</a></code>, declares two business methods, <code class="cCode">executePublish</code> and <code class="cCode">executeQuery</code>. The bean class, <code class="cCode"><a  href="../examples/jaxr/clientsession/src/PubQueryBean.java" target="_blank">src/PubQueryBean.java,</a></code> implements the <code class="cCode">executePublish</code> and <code class="cCode">executeQuery</code> methods and their helper methods <code class="cCode">getName</code>, <code class="cCode">getDescription</code>, and <code class="cCode">getKey</code>. These methods are very similar to the methods of the same name in the simple examples <code class="cCode">JAXRQuery.java</code> and <code class="cCode">JAXRPublish.java</code>. The <code class="cCode">executePublish</code> method uses information in the file <code class="cCode">PubQueryBeanExample.properties</code> to create an organization named The Coffee Enterprise Bean Break. The <code class="cCode">executeQuery</code> method uses the string &quot;Coff&quot;, specified in the application client code, to locate this organization.</p><a name="wp150796"> </a><p class="pBody">The bean class also implements the required methods <code class="cCode">ejbCreate</code>, <code class="cCode">setSessionContext</code>, <code class="cCode">ejbRemove</code>, <code class="cCode">ejbActivate</code>, and <code class="cCode">ejbPassivate</code>.</p><a name="wp150797"> </a><p class="pBody">The <code class="cCode">ejbCreate</code> method of the bean class allocates resources--in this case, by looking up the <code class="cCode">ConnectionFactory</code> and creating the <code class="cCode">Connection</code>.</p><a name="wp150798"> </a><p class="pBody">The <code class="cCode">ejbRemove</code> method must deallocate the resources that were allocated by the <code class="cCode">ejbCreate</code> method. In this case, the <code class="cCode">ejbRemove</code> method closes the <code class="cCode">Connection</code>.</p><a name="wp150800"> </a><h3 class="pHeading2">Compiling the Source Files</h3><a name="wp150801"> </a><p class="pBody">To compile the application source files, go to the directory <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/jaxr/clientsession</code>. Use the following command:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asant compile<a name="wp150802"> </a></pre></div><a name="wp150803"> </a><p class="pBody">The <code class="cCode">compile</code> target places the properties file and the class files in the <code class="cCode">build</code> directory.</p><a name="wp150805"> </a><h3 class="pHeading2">Starting the J2EE Application Server</h3><a name="wp150806"> </a><p class="pBody">To run this example, you need to start the J2EE Application Server. Follow the instructions in <a  href="WebApp3.html#wp213803">Starting and Stopping the J2EE Application Server</a>.</p><a name="wp150812"> </a><h3 class="pHeading2">Creating JAXR Resources</h3><a name="wp150813"> </a><p class="pBody">In order to use JAXR in a J2EE application that uses the J2EE 1.4 Application Server, you need to access the JAXR resource adapter (see <a  href="JAXR3.html#wp88034">Implementing a JAXR Client</a> through a connector connection pool and a connector resource. You can create these resources in the Admin Console.</p><a name="wp151606"> </a><p class="pBody">If you have not done so, start the Admin Console as described in <a  href="WebApp3.html#wp213824">Starting the Admin Console</a>.</p><a name="wp151613"> </a><p class="pBody">To create the connector connection pool, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp151593"> </a><div class="pSmartList1"><li>Expand the Connectors node, then click Connector Connection Pools.</li></div><a name="wp151594"> </a><div class="pSmartList1"><li>Click New. The Create Connector Connection Pool wizard starts.</li></div><a name="wp151597"> </a><div class="pSmartList1"><li>In the Select Connector Module screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp151598"> </a><div class="pSmartList2"><li>Type <code class="cCode">jaxr-pool</code> in the Name field.</li></div><a name="wp151599"> </a><div class="pSmartList2"><li>Choose <code class="cCode">jaxr-ra</code> from the Resource Adapter menu.</li></div><a name="wp151600"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp151601"> </a><div class="pSmartList1"><li>In the Select Connection Definition screen, choose <code class="cCode">javax.xml.registry.ConnectionFactory</code> (the only choice) from the menu and click Next.</li></div><a name="wp151602"> </a><div class="pSmartList1"><li>In the next two screens, Specify Properties and Enter Pool Settings, click Next.</li></div><a name="wp151603"> </a><div class="pSmartList1"><li>In the Summary screen, click Finish.</li></div></ol></div><a name="wp151614"> </a><p class="pBody">To create the connector resource, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp151620"> </a><div class="pSmartList1"><li>Under the Connectors node, click Connector Resources.</li></div><a name="wp151621"> </a><div class="pSmartList1"><li>Click New. The Create Connector Resource screen appears.</li></div><a name="wp151628"> </a><div class="pSmartList1"><li>In the JNDI Name field, type <code class="cCode">eis/JAXR</code>.</li></div><a name="wp151629"> </a><div class="pSmartList1"><li>Choose <code class="cCode">jaxr-pool</code> from the Pool Name menu.</li></div><a name="wp151634"> </a><div class="pSmartList1"><li>Click OK.</li></div></ol></div><a name="wp150818"> </a><p class="pBody">If you are in a hurry, you can create these objects using the following <code class="cCode">asant</code> target in the <code class="cCode">build.xml</code> file for this example:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asant create-resource<a name="wp150820"> </a></pre></div><a name="wp150822"> </a><h3 class="pHeading2">Creating and Packaging the Application</h3><a name="wp150823"> </a><p class="pBody">Creating and packaging this application involve several steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp150827"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150841">Starting deploytool and Creating the Application</a></li></div><a name="wp150835"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp150867">Packaging the Session Bean</a></li></div><a name="wp153521"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp151031">Packaging the Application Client</a></li></div><a name="wp150839"> </a><div class="pSmartList1"><li><a  href="JAXR5.html#wp151053">Checking the JNDI Names</a></li></div></ol></div><a name="wp150841"> </a><h4 class="pHeading3">Starting deploytool and Creating the Application</h4><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp150842"> </a><div class="pSmartList1"><li>Start <code class="cCode">deploytool</code>. On Windows systems, choose Start<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Programs<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Sun Microsystems<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>J2EE 1.4 SDK<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Deploytool. On UNIX systems, use the <code class="cCode">deploytool</code> command.</li></div><a name="wp150844"> </a><div class="pSmartList1"><li>Choose File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Application. </li></div><a name="wp150845"> </a><div class="pSmartList1"><li>Click Browse next to the Application File Name field and use the file chooser to locate the directory <code class="cCode">clientsession</code>. </li></div><a name="wp150846"> </a><div class="pSmartList1"><li>In the File Name field, type <code class="cCode">ClientSessionApp</code>.</li></div><a name="wp150847"> </a><div class="pSmartList1"><li>Click New Application.</li></div><a name="wp150848"> </a><div class="pSmartList1"><li>Click OK.</li></div></ol></div><a name="wp150867"> </a><h4 class="pHeading3">Packaging the Session Bean</h4><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp150868"> </a><div class="pSmartList1"><li>Choose File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Enterprise Bean to start the Enterprise Bean Wizard, then click Next.</li></div><a name="wp150869"> </a><div class="pSmartList1"><li>In the EJB JAR screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp150870"> </a><div class="pSmartList2"><li>Select Create New JAR Module in Application and make sure that the application is <code class="cCode">ClientSessionApp</code>.</li></div><a name="wp150871"> </a><div class="pSmartList2"><li>In the JAR Name field, type <code class="cCode">PubQueryJAR</code>.</li></div><a name="wp150872"> </a><div class="pSmartList2"><li>Click the Edit button next to the Contents text area. </li></div><a name="wp150873"> </a><div class="pSmartList2"><li>In the dialog box, locate the <code class="cCode">clientsession/build</code> directory. Select <code class="cCode">PubQueryBean.class</code>, <code class="cCode">PubQueryHome.class</code>, <code class="cCode">PubQueryRemote.class</code>, and <code class="cCode">PubQueryBeanExample.properties</code> from the Available Files tree area and click Add, then OK.</li></div></ol></div><a name="wp150874"> </a><div class="pSmartList1"><li>In the General screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp150875"> </a><div class="pSmartList2"><li>From the Enterprise Bean Class menu, choose <code class="cCode">PubQueryBean</code>.</li></div><a name="wp150876"> </a><div class="pSmartList2"><li>In the Enterprise Bean Name field, type <code class="cCode">PubQuery</code>.</li></div><a name="wp150877"> </a><div class="pSmartList2"><li>Verify that the Enterprise Bean Type is Stateless Session.</li></div><a name="wp150878"> </a><div class="pSmartList2"><li>In the Remote Interfaces area, choose <code class="cCode">PubQueryHome</code> from the Remote Home Interface menu and <code class="cCode">PubQueryRemote</code> from the Remote Interface menu.</li></div></ol></div></ol></div><a name="wp150879"> </a><p class="pBody">After you finish the wizard, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp150880"> </a><div class="pSmartList1"><li>Click the <code class="cCode">PubQuery</code> node, then click the Transactions tab. In the inspector pane, select the Container-Managed radio button.</li></div><a name="wp150881"> </a><div class="pSmartList1"><li>Click the <code class="cCode">PubQuery</code> node, then click the Resource Refs tab. In the inspector pane:</li></div>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -