...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<%@ page contentType="text/html" import="javax.naming.Context, javax.naming.InitialContext " %> <%@ page import="org.apache.geronimo.samples.myphonebookpak.MyPhonebookLocal" %> <%@ page import="org.apache.geronimo.samples.myphonebookpak.PhoneBook" %> <% String searchName = ""; if (request.getParameter("searchname") != null) { searchName = request.getParameter("searchname"); } %> <html> <head><title>Phonebook</title></head> <body> <form action="index.jsp"> <b>Search number</b>:<br> Enter name: <input type="text" name="searchname" value="<%=searchName%>"> <input type="submit" value="Search"> (Test with <a href="index.jsp?searchname=Joe">Joe</a>) </form> <% if (!searchName.equals("")) { String number = ""; try { Context context = new InitialContext(); MyPhonebookLocal myPhonebookLocal = (MyPhonebookLocal) context.lookup("java:comp/env/ejb/MyPhonebookBean"); PhoneBook phonebook = myPhonebookLocal.findByPrimaryKey(searchName); if (phonebook != null) { number = phonebook.getNumber(); } } catch (Exception e) { number = e.toString(); } out.println("This is the number returned from the EJB when searching for '" + searchName + "' : " + number); } %> </body> </html> |
Deployment Plans
...
openejb-jarpersistence.xml specifies the module's information such as the group and artifact IDs and the verion and module type. will specify the name of the PersistenceUnit. This name is used when referencing for the EntityManagerFactory. I have denoted it as PhonePU. I added an extra property called SynchronizeMappings so that the data in the database will not be overwritten.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Code Block | ||||||||
| ||||||||
<?xml version="1.0" encoding="UTF-8"?> <openejb-jar <persistence xmlns="http://wwwjava.openejbsun.orgcom/xml/ns/openejb-jar-2.1" xmlns:nampersistence" xmlns:xsi="http://geronimowww.apachew3.org/xml2001/ns/naming-XMLSchema-instance" version="1.1" xmlns:pkgen0" xsi:schemaLocation="http://wwwjava.openejbsun.orgcom/xml/ns/pkgen-2.0" xmlns:sec="persistence http://geronimojava.apachesun.orgcom/xml/ns/persistence/security-persistence_1_0.1xsd" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>org.apache.geronimo.samples</sys:groupId> <sys:artifactId>MyPhonebookBean</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>car</sys:type> </sys:moduleId> </sys:environment> </openejb-jar> > <persistence-unit name="PhonePU"> <description>Phone Book</description> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <jta-data-source>SampleTxDatasource</jta-data-source> <non-jta-data-source>SampleNoTxDatasource</non-jta-data-source> <class>org.apache.geronimo.samples.myphonebookpak.PhoneBook</class> <properties> <property name="openjpa.jdbc.SynchronizeMappings" value="false"/> </properties> </persistence-unit> </persistence> |
Deployment Plan for the Application
plan.xml is generated by building the sample and can be found under ./myphonebook-jetty/target/resources/META-INF/plan.xml to deploy on jetty or ./myphonebook-tomcat/target/resources/META-INF/plan.xml to deploy on tomcat. Shown below is the deployment plan for tomcatpersistence.xml will specify the name of the PersistenceUnit. This name is used when referencing for the EntityManagerFactory. I have denoted it as PhonePU. I added an extra property called SynchronizeMappings so that the data in the database will not be overwritten.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" <!--Licensed to the Apache Software Foundation (ASF) under one or more contributor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" license agreements. See the NOTICE file distributed with this work xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">for additional information <persistence-unit name="PhonePU"> <description>Phone Book</description> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <jta-data-source>SampleTxDatasource</jta-data-source> <non-jta-data-source>SampleNoTxDatasource</non-jta-data-source> <class>org.apache.geronimo.samples.myphonebookpak.PhoneBook</class> <properties> <property name="openjpa.jdbc.SynchronizeMappings" value="false"/> </properties> </persistence-unit> </persistence> |
Deployment Plans for the Web-App
web.xml references the EJB by specifying the package to which the MyPhonebookLocal belongs to.
...
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>MyPhonebookWeb</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<ejb-local-ref>
<ejb-ref-name>ejb/MyPhonebookBean</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local>org.apache.geronimo.samples.myphonebookpak.MyPhonebookLocal</local>
</ejb-local-ref>
</web-app>
geronimo-web.xml specifies the module's information and the context-root for the web-app.
Code Block | |
---|---|
xml | xml |
borderStyle | solid |
title | geronimo-web.xml | <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1" xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--> <!--$Rev: 497879 $ $Date: 2007-01-19 12:11:01 -0500 (Fri, 19 Jan 2007) $--> <application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.2"> <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dep:moduleId> <dep:groupId>org.apache.geronimo.samples</dep:groupId> <dep:artifactId>myphonebook-tomcat</dep:artifactId> <dep:version>2.1-SNAPSHOT</dep:version> <dep:type>car</dep:type> </dep:moduleId> <dep:dependencies> <dep:dependency> <dep:groupId>org.apache.geronimo.samples</dep:groupId> <dep:artifactId>sample-datasource</dep:artifactId> <dep:version>2.1-SNAPSHOT</dep:version> <dep:type>car</dep:type> </dep:dependency> <dep:dependency> <dep:groupId>org.apache.geronimo.configs</dep:groupId> xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"<dep:artifactId>jasper</dep:artifactId> xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"> <sys:environment> <dep:version>2.1</dep:version> <sys:moduleId><dep:type>car</dep:type> <sys:groupId>${pom.groupId}</sysdep:groupId>dependency> <sys:artifactId>${pom.artifactId}</sys:artifactId><dep:dependency> <sys:version>${version}</sys:version> <dep:groupId>org.apache.geronimo.configs</dep:groupId> <sys <dep:type>war<artifactId>tomcat6</sysdep:type>artifactId> </sys:moduleId><dep:version>2.1</dep:version> </sys:environment> <dep:type>car</dep:type> <context-root>/myphonebook</context-root> </web-app> |
Deployment Plan for the Application
geronimo-application.xml tells the application that there is a database pool that needs to be deployed as well. The db pool is defined in PhoneBookPool.xml and the driver that is needs in order to be deployed is the tranql-connector-ra-1.3.rar file--these two files will reside on the top level layer of the resultant EAR file.
Code Block | |
---|---|
xml | xml |
borderStyle | solid |
title | geronimo-application.xml | <?xml version="1.0" encoding="UTF-8"?> <application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1" application-name="t6"> <sys:environment> <sys:moduleId> <sys:groupId>${pom.groupId}</sys:groupId> <sys:artifactId>${pom.artifactId}</sys:artifactId> <sys:version>${version}</sys:version> <sys:type>ear</sys:type> </sys:moduleId> </sys:environment> <module> </dep:dependency> <dep:dependency> <dep:groupId>org.apache.geronimo.configs</dep:groupId> <connector>tranql-connector-ra-1.3.rar</connector> <alt-dd>PhoneBookPool.xml</alt-dd> </module> </application> |
Configuring, Building, and Deploying the Application
Download the MyPhoneBook application from the following link:
MyPhoneBook
After decompressing the given file, the myphonebook directory will be created.
Source Code
You can checkout the source code of this sample from SVN:
svn checkout http://svn.apache.org/repos/asf/geronimo/samples/trunk/samples/myphonebook
Creating and Populating Database
After starting Apache Geronimo log into the console and follow the given steps to create the PhoneBookDB.
...
CREATE TABLE phonebook ( name VARCHAR(255) PRIMARY KEY, number VARCHAR(255) );
INSERT INTO phonebook VALUES ('John', '1234');
INSERT INTO phonebook VALUES ('Joe', '5678');
<dep:artifactId>openejb</dep:artifactId>
<dep:version>2.1</dep:version>
<dep:type>car</dep:type>
</dep:dependency>
</dep:dependencies>
<dep:hidden-classes/>
<dep:non-overridable-classes/>
</dep:environment>
<gbean name="DBInitialization" class="org.apache.geronimo.connector.DatabaseInitializationGBean">
<!--<attribute name="testSQL">select * from phonebook</attribute>-->
<attribute name="path">PhoneBook.sql</attribute>
<reference name="DataSource">
<name>SampleTxDatasource</name>
</reference>
</gbean>
</application>
|
Configuring, Building, and Deploying the Application
Source Code
You can checkout the source code of this sample from SVN:
svn checkout http://svn.apache.org/repos/asf/geronimo/samples/trunk/samples/myphonebook
Creating and Populating Database
The datasource necessary for this example can be installed using the sample-datasource plugin. Use the administration console to first install this plugin. When you deploy the sample application the necessary database table and entries will be created
...
.
Building
Use a command prompt to navigate into the myphonebook directory and just give mvn install followed by mvn site command to build. It will create the myphonebook-ear-2.0-SNAPSHOT.ear under the myphonebook folder. Now, you are ready to deploy myphonebook application in the Geronimo Application server.
...
- Scroll down to Deploy New from the Console Navigation panel.
- Load myphonebook-ear-2.01-SNAPSHOT.ear from myphonebook folder ./myphonebook-ear/target/ in to the Archive input box.
- Load plan.xml from ./myphonebook-jetty/target/resources/META-INF/ or ./myphonebook-tomcat/target/resources/META-INF/ depending on the target server (jetty or tomcat).
- Press Install button to deploy application in the server.
...