Hi,
You will have to download the "J2EE 1.4 Tutorial Update 2 (for Sun Java System
Application Server Platform Edition 8 Update 1) June 22, 2004". The link is
http://java.sun.com/j2ee/1.4/previous_downloads.html. You will find it at the bottom of
the page.
You can find a tutorial about the Dukeâs Bank on
http://www.student.nada.kth.se/~d95-cro/j2eetutorial14/doc/Ebank.html
The first thing you have to do is protecting the Web Client Resources. I have used MySQL
as follow,
#1.- Create two tables
-users, with two fields (username, passwd) and fill the table with the users as your own.
In my case I followed the tutorial,
username passwd
200 j2ee
admin admin
and some other users that I have created on the desktop client. I mean (201, 201), (164,
164), etc where user and pass are the same value
-userroles, with two fields (username, userRoles) and fill the table as follow
username userRoles
200 bankCustomer
admin bankAdmin
and the rest of the users with the role bankCustomer.
#2.- The next step is setup the datasource and security policy on JBoss
In your mysql-ds.xml, in the directory jboss-4.2.2.GA\server\default\deploy create de
datasource as follow,
| <datasources>
| <local-tx-datasource>
| <jndi-name>DefaultDS</jndi-name>
| <connection-url>jdbc:mysql://localhost:3306/yourDB</connection-url>
| <driver-class>com.mysql.jdbc.Driver</driver-class>
| <user-name>yourUser</user-name>
| <password>yourPasswd</password>
| <exception-sorter-class-name>
| org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
| </exception-sorter-class-name>
| <metadata>
| <type-mapping>mySQL</type-mapping>
| </metadata>
| </local-tx-datasource>
| </datasources>
|
And the security policy, in the directory
jboss-4.2.2.GA\server\default\conf\login-config.xml, as follow,
| <application-policy name="dukesbank">
| <authentication>
| <login-module
code="org.jboss.security.auth.spi.DatabaseServerLoginModule"
flag="required">
| <module-option
name="dsJndiName">java:/DefaultDS</module-option>
| <module-option name="principalsQuery">
| select passwd from Users where username=?
| </module-option>
| <module-option name="rolesQuery">
| select userRoles,'Roles' from UserRoles where
username=?
| </module-option>
| </login-module>
| </authentication>
| </application-policy>
|
#3.- Now the structure of our application
I have developed the application on Eclipse 3.2.2 IDE so my tree is as follow,
The root of the application will be the name of it. I named it JBossDukesBank. So,
| JBossDukesBank
| src
| com.sun.ebank.appclient
| BankAdmin.java
| DataModel.java
| EventHandle.java
| AdminMessages_es.properties
| AdminMessages.properties
| com.sun.ebank.ejb.account
| Account.java
| AccountBean.java
| AccountController.java
| AccountControllerBean.java
| AccountControllerHome.java
| AccountHome.java
| com.sun.ebank.ejb.customer
| Customer.java
| CustomerBean.java
| CustomerController.java
| CustomerControllerBean.java
| CustomerControllerHome.java
| CustomerHome.java
| com.sun.ebank.ejb.exception
| (All the ejb exception classes)
| com.sun.ebank.ejb.tx
| Tx.java
| TxBean.java
| TxController.java
| TxControllerBean.java
| TxControllerHome.java
| TxHome.java
| com.sun.ebank.util
| AccountDetails.java
| CodedNames.java
| CustomerDetails.java
| DateHelper.java
| DBHelper.java
| Debug.java
| DomainUtil.java
| EJBGetter.java
| TxDetails.java
| com.sun.ebank.web
| AccountHistoryBean.java
| ATMBean.java
| BeanManager.java
| ContextListener.java
| CustomerBean.java
| DateHelper.java
| Dispatcher.java
| TransferBean.java
| WebMessages_en.properties
| WebMessages_es.properties
| WebMesages.properties
| com.sun.ebank.web.template
| Debug.java
| Definition.java
| DefinitionTag.java
| InsertTag.java
| Parameter.java
| ParameterTag.java
| ScreenTag.java
|
Now you have to import the jars. From the folder /server/default/lib all jars and from
/client/, jboss-client.jar, jbossall-client.jar and jbossws-common.jar. I am not sure if
needed but my app works ok.
Following, I have created some other folders on the structure tree. The dd (deployment
descriptors) folder,
| dd
| client
| application-client.xml
| jboss-client.xml
| client-app
| application.xml
| ejb
| ejb-jar.xml
| web-app
| application.xml
|
dd/client/application-client.xml.-
| <?xml version="1.0" encoding="UTF-8"?>
|
| <!DOCTYPE application-client PUBLIC
| '-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN'
| 'http://java.sun.com/dtd/application-client_1_3.dtd'>
| <application-client>
| <display-name>BankAdmin</display-name>
| <ejb-ref>
| <ejb-ref-name>ejb/CustomerControllerEJB</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <home>com.sun.ebank.ejb.customer.CustomerControllerHome</home>
| <remote>com.sun.ebank.ejb.customer.CustomerController</remote>
| </ejb-ref>
|
| <ejb-ref>
| <ejb-ref-name>ejb/AccountControllerEJB</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <home>com.sun.ebank.ejb.account.AccountControllerHome</home>
| <remote>com.sun.ebank.ejb.account.AccountController</remote>
| </ejb-ref>
|
| <ejb-ref>
| <ejb-ref-name>ejb/TxControllerEJB</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <home>com.sun.ebank.ejb.tx.TxControllerHome</home>
| <remote>com.sun.ebank.ejb.tx.TxController</remote>
| </ejb-ref>
| </application-client>
|
dd/client/jboss-client.xml.-
| <jboss-client>
| <jndi-name>bank-client</jndi-name>
|
| <ejb-ref>
| <ejb-ref-name>ejb/AccountControllerEJB</ejb-ref-name>
| <jndi-name>accountController</jndi-name>
| </ejb-ref>
|
| <ejb-ref>
| <ejb-ref-name>ejb/CustomerControllerEJB</ejb-ref-name>
| <jndi-name>customerController</jndi-name>
| </ejb-ref>
|
| <ejb-ref>
| <ejb-ref-name>ejb/TxControllerEJB</ejb-ref-name>
| <jndi-name>txController</jndi-name>
| </ejb-ref>
|
| </jboss-client>
|
dd/client-app/application.xml.-
| <?xml version="1.0" encoding="UTF-8"?>
| <application
xmlns="http://java.sun.com/xml/ns/j2ee"
version="1.4"
|
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/application_1_4.xsd">
| <display-name>JBossDukesBank-Client</display-name>
| <description>Application description</description>
| <module>
| <ejb>bank-ejb.jar</ejb>
| </module>
| <module>
| <java>bank-client.jar</java>
| </module>
| <security-role>
| <role-name>bankCustomer</role-name>
| </security-role>
| </application>
|
dd/ejb/ejb-jar.xml.-
| <?xml version="1.0" encoding="UTF-8"?>
| <ejb-jar
xmlns="http://java.sun.com/xml/ns/j2ee" version="2.1"
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/ejb-jar_2_1.xsd">
| <display-name>DukesBankEJBJAR</display-name>
| <enterprise-beans>
| <entity>
| <ejb-name>AccountEJB</ejb-name>
| <local-home>com.sun.ebank.ejb.account.AccountHome</local-home>
| <local>com.sun.ebank.ejb.account.Account</local>
| <ejb-class>com.sun.ebank.ejb.account.AccountBean</ejb-class>
| <persistence-type>Bean</persistence-type>
| <prim-key-class>java.lang.String</prim-key-class>
| <reentrant>false</reentrant>
| <resource-ref>
| <description>Conexion BD</description>
| <res-ref-name>jdbc/DefaultDS</res-ref-name>
| <res-type>javax.sql.DataSource</res-type>
| <jndi-name>java:/DefaultDS</jndi-name>
| <res-auth>Container</res-auth>
| </resource-ref>
| </entity>
| <entity>
| <ejb-name>CustomerEJB</ejb-name>
| <local-home>com.sun.ebank.ejb.customer.CustomerHome</local-home>
| <local>com.sun.ebank.ejb.customer.Customer</local>
| <ejb-class>com.sun.ebank.ejb.customer.CustomerBean</ejb-class>
| <persistence-type>Bean</persistence-type>
| <prim-key-class>java.lang.String</prim-key-class>
| <reentrant>false</reentrant>
| <resource-ref>
| <description>Conexion BD</description>
| <res-ref-name>jdbc/DefaultDS</res-ref-name>
| <res-type>javax.sql.DataSource</res-type>
| <jndi-name>java:/DefaultDS</jndi-name>
| <res-auth>Container</res-auth>
| </resource-ref>
| </entity>
| <entity>
| <ejb-name>TxEJB</ejb-name>
| <local-home>com.sun.ebank.ejb.tx.TxHome</local-home>
| <local>com.sun.ebank.ejb.tx.Tx</local>
| <ejb-class>com.sun.ebank.ejb.tx.TxBean</ejb-class>
| <persistence-type>Bean</persistence-type>
| <prim-key-class>java.lang.String</prim-key-class>
| <reentrant>false</reentrant>
| <resource-ref>
| <description>Conexion BD</description>
| <res-ref-name>jdbc/DefaultDS</res-ref-name>
| <res-type>javax.sql.DataSource</res-type>
| <jndi-name>java:/DefaultDS</jndi-name>
| <res-auth>Container</res-auth>
| </resource-ref>
| </entity>
| <session>
| <ejb-name>AccountControllerEJB</ejb-name>
| <home>com.sun.ebank.ejb.account.AccountControllerHome</home>
| <remote>com.sun.ebank.ejb.account.AccountController</remote>
|
<ejb-class>com.sun.ebank.ejb.account.AccountControllerBean</ejb-class>
| <session-type>Stateful</session-type>
| <transaction-type>Bean</transaction-type>
| <ejb-local-ref>
| <ejb-ref-name>ejb/AccountEJB</ejb-ref-name>
| <ejb-ref-type>Entity</ejb-ref-type>
| <local-home>AccountHome</local-home>
| <local>Account</local>
| <ejb-link>AccountEJB</ejb-link>
| </ejb-local-ref>
| <ejb-local-ref>
| <ejb-ref-name>ejb/CustomerEJB</ejb-ref-name>
| <ejb-ref-type>Entity</ejb-ref-type>
| <local-home>CustomerHome</local-home>
| <local>Customer</local>
| <ejb-link>CustomerEJB</ejb-link>
| </ejb-local-ref>
| </session>
| <session>
| <ejb-name>CustomerControllerEJB</ejb-name>
| <home>com.sun.ebank.ejb.customer.CustomerControllerHome</home>
| <remote>com.sun.ebank.ejb.customer.CustomerController</remote>
|
<ejb-class>com.sun.ebank.ejb.customer.CustomerControllerBean</ejb-class>
| <session-type>Stateful</session-type>
| <transaction-type>Bean</transaction-type>
| <ejb-local-ref>
| <ejb-ref-name>ejb/CustomerEJB</ejb-ref-name>
| <ejb-ref-type>Entity</ejb-ref-type>
| <local-home>CustomerHome</local-home>
| <local>Customer</local>
| <ejb-link>CustomerEJB</ejb-link>
| </ejb-local-ref>
| </session>
| <session>
| <ejb-name>TxControllerEJB</ejb-name>
| <home>com.sun.ebank.ejb.tx.TxControllerHome</home>
| <remote>com.sun.ebank.ejb.tx.TxController</remote>
| <ejb-class>com.sun.ebank.ejb.tx.TxControllerBean</ejb-class>
| <session-type>Stateful</session-type>
| <transaction-type>Bean</transaction-type>
| <ejb-local-ref>
| <ejb-ref-name>ejb/TxEJB</ejb-ref-name>
| <ejb-ref-type>Entity</ejb-ref-type>
| <local-home>TxHome</local-home>
| <local>Tx</local>
| <ejb-link>TxEJB</ejb-link>
| </ejb-local-ref>
| <ejb-local-ref>
| <ejb-ref-name>ejb/AccountEJB</ejb-ref-name>
| <ejb-ref-type>Entity</ejb-ref-type>
| <local-home>AccountHome</local-home>
| <local>Account</local>
| <ejb-link>AccountEJB</ejb-link>
| </ejb-local-ref>
| </session>
| </enterprise-beans>
| </ejb-jar>
|
dd/web-app/application.xml.-
| <?xml version="1.0" encoding="UTF-8"?>
| <application
xmlns="http://java.sun.com/xml/ns/j2ee"
version="1.4"
|
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/application_1_4.xsd">
| <display-name>JBossDukesBank-WEB</display-name>
| <description>Application description</description>
| <module>
| <ejb>bank-ejb.jar</ejb>
| </module>
| <module>
| <web>
| <web-uri>bank-web.war</web-uri>
| <context-root>bank</context-root>
| </web>
| </module>
| <security-role>
| <role-name>bankCustomer</role-name>
| </security-role>
| </application>
|
I use this folder to build the ear (JBossDukesBank.ear) that I will explain later.
And at last, the WebContent folder. This folder is the ROOT of the JSP pages and its
structure is the same that you have downloaded. It looks like this,
WebContent
*.jsp
WebMessages*.properties
template
*.jsp
*.jspf
WEB-INF
classes
- the compiled classes of the web app
lib
jstl.jar
standard.jar
tags
tutorial-template.tld
jboss-web.xml
web.xml
|
| jboss-web.xml.-
|
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC
"-//JBoss//DTD Web Application 2.3V2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
<jboss-web>
<!-- Uncomment this element to add security for the application -->
<security-domain>java:/jaas/dukesbank</security-domain>
<resource-ref>
Conexion BD
<res-ref-name>jdbc/DefaultDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<jndi-name>java:/DefaultDS</jndi-name>
</resource-ref>
</jboss-web>
|
| web.xml.-
|
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<display-name>JBoss DukesBankWAR</display-name>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>WebMessages</param-value>
</context-param>
<display-name>Dispatcher</display-name>
<servlet-name>Dispatcher</servlet-name>
<servlet-class>com.sun.ebank.web.Dispatcher</servlet-class>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/accountHist</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/accountList</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/atm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/atmAck</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/main</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/transferAck</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/transferFunds</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/logon</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/logonError</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/logoff</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/error</url-pattern>
</servlet-mapping>
<jsp-config>
<jsp-property-group>
<display-name>bank</display-name>
<url-pattern>*.jsp</url-pattern>
<el-enabled>true</el-enabled>
<scripting-enabled>true</scripting-enabled>
<include-prelude>/template/prelude.jspf</include-prelude>
</jsp-property-group>
</jsp-config>
<!--#Security constraints -->
<security-constraint>
<web-resource-collection>
<web-resource-name>User Authentication Policy</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Bank Customers Authentication Policy</web-resource-name>
<url-pattern>/template/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>bankCustomer</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>bankCustomer</role-name>
</security-role>
<welcome-file-list>
<welcome-file>/main.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Duke's Bank</realm-name>
<form-login-config>
<form-login-page>/logon.jsp</form-login-page>
<form-error-page>/logonError.jsp</form-error-page>
</form-login-config>
</login-config>
<error-page>
<error-code>404</error-code>
/template/errorpage.jsp
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
/template/errorpage.jsp
</error-page>
<
taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/lib/fmt.tld</taglib-location>
<
taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/lib/c.tld</taglib-location>
<ejb-ref>
<ejb-ref-name>ejb/AccountControllerEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
com.sun.ebank.ejb.account.AccountControllerHome
com.sun.ebank.ejb.account.AccountController
<ejb-link>AccountControllerEJB</ejb-link>
</ejb-ref>
<ejb-ref>
<ejb-ref-name>ejb/CustomerControllerEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
com.sun.ebank.ejb.customer.CustomerControllerHome
com.sun.ebank.ejb.customer.CustomerController
<ejb-link>CustomerControllerEJB</ejb-link>
</ejb-ref>
<ejb-ref>
<ejb-ref-name>ejb/TxControllerEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
com.sun.ebank.ejb.tx.TxControllerHome
com.sun.ebank.ejb.tx.TxController
<ejb-link>TxControllerEJB</ejb-link>
</ejb-ref>
<resource-ref>
Conexion BD
<res-ref-name>jdbc/DefaultDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
|
| In the web.xml you have to put attention on the stanzas,
|
|
<jsp-config>
<jsp-property-group>
<display-name>bank</display-name>
<url-pattern>*.jsp</url-pattern>
<el-enabled>true</el-enabled>
<scripting-enabled>true</scripting-enabled>
<include-prelude>/template/prelude.jspf</include-prelude>
</jsp-property-group>
</jsp-config>
|
| Here I let in my JSPs both JSP scripting and JSTL EL.
|
|
<!--#Security constraints -->
<security-constraint>
<web-resource-collection>
<web-resource-name>User Authentication Policy</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Bank Customers Authentication Policy</web-resource-name>
<url-pattern>/template/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>bankCustomer</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>bankCustomer</role-name>
</security-role>
|
| My idea was to authenticate just one time but the web client need authentication in
two steps: when login and when you start to operate with the accounts. Once you start to
operate you can feel free. By the other hand I have just declared one role as
bankCustomer.
|
|
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Duke's Bank</realm-name>
<form-login-config>
<form-login-page>/logon.jsp</form-login-page>
<form-error-page>/logonError.jsp</form-error-page>
</form-login-config>
</login-config>
|
| <auth-method>FORM</auth-method> means the way you have to authenticate.
Here you reach an interesting point that is the logon.jsp. I am going to explain,
|
|
<%@ include file="/template/prelude.jspf/" %>
<fmt:message key="TitleLogon"/>
<h3><fmt:message key="Logon"/> <fmt:message
key="Submit"/>.</h3>
<form action="j_security_check" method=post>
<fmt:message key="CustomerId"/>
<fmt:message key="Password"/>
<input type="submit" value="<fmt:message
key="Submit"/>">
|
| When you put in your browser the URL
http://localhost:8080/main you are redirect to
the form logon.jsp just only to authenticate and nothing else. Later you go to the
dispatcher to follow the flow of the application. I mean, the form is just one automatic
step to go inside the application. All I have explained at the begining is prepare for
just this step.
|
| And this is the application.
|
| Changes in the code.-
|
| CodedNames.java
|
|
package com.sun.ebank.util;
/**
* This interface defines names in code used as args for lookup().
*/
public interface CodedNames {
public static final String BANK_DATABASE = "java:/DefaultDS";
public static final String ACCOUNT_EJB = "java:comp/env/ejb/AccountEJB";
public static final String ACCOUNT_CONTROLLER_EJB = "AccountControllerEJB";
public static final String CUSTOMER_EJB = "java:comp/env/ejb/CustomerEJB";
public static final String CUSTOMER_CONTROLLER_EJB =
"CustomerControllerEJB";
public static final String TX_EJB = "java:comp/env/ejb/TxEJB";
public static final String TX_CONTROLLER_EJB = "TxControllerEJB";
}
|
| As you can see to call the Session Bean I use the name declared in the ejb-jar.xml but
when I call the Entity Beans I use java:comp/â¦
|
| EJBGetter.java
|
|
package com.sun.ebank.util;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.sun.ebank.ejb.account.AccountHome;
import com.sun.ebank.ejb.account.AccountControllerHome;
import com.sun.ebank.ejb.customer.CustomerHome;
import com.sun.ebank.ejb.customer.CustomerControllerHome;
import com.sun.ebank.ejb.tx.TxHome;
import com.sun.ebank.ejb.tx.TxControllerHome;
import com.sun.ebank.util.Debug;
/**
* This helper class fetches EJB home references.
*/
public final class EJBGetter {
public static AccountHome getAccountHome() throws NamingException {
InitialContext initial = new InitialContext();
Object objref = initial.lookup(CodedNames.ACCOUNT_EJB);
return (AccountHome)objref;
}
public static AccountControllerHome getAccountControllerHome()
throws NamingException {
Context initial = getInitialContext();
Object objref = initial.lookup(CodedNames.ACCOUNT_CONTROLLER_EJB);
return (AccountControllerHome) PortableRemoteObject.narrow(objref,
AccountControllerHome.class);
}
public static CustomerHome getCustomerHome() throws NamingException {
InitialContext initial = new InitialContext();
Object objref = initial.lookup(CodedNames.CUSTOMER_EJB);
return (CustomerHome)objref;
}
public static CustomerControllerHome getCustomerControllerHome()
throws NamingException {
Context initial = getInitialContext();
Object objref = initial.lookup(CodedNames.CUSTOMER_CONTROLLER_EJB);
return (CustomerControllerHome) PortableRemoteObject.narrow(objref,
CustomerControllerHome.class);
}
public static TxHome getTxHome() throws NamingException {
InitialContext initial = new InitialContext();
return (TxHome)objref;
}
public static TxControllerHome getTxControllerHome()
throws NamingException {
Context initial = getInitialContext();
Object objref = initial.lookup(CodedNames.TX_CONTROLLER_EJB);
return (TxControllerHome) PortableRemoteObject.narrow(objref,
TxControllerHome.class);
}
private static Context getInitialContext(){
Context ctx = null;
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
env.put("j2ee.clientName", "bank-client");
try {
// Get an initial context
ctx = new InitialContext(env);
System.out.println("Got context");
Debug.print("Obtenido Contexto: ", ctx);
} catch (NamingException ne) {
// TODO Auto-generated catch block
System.out.println("Did not get context");
ne.printStackTrace();
}
return ctx;
}
}
// EJBGetter
|
| As you can see, to call the Session Bean I first setup the InitialContext and return
the Home Interface using PortableRemoteObject.narrow. But when I call the Entity Beans I
do not.
|
| Changes on the web client.
|
| Dispatcher.java
|
|
package com.sun.ebank.web;
import javax.servlet.http.*;
import com.sun.ebank.util.Debug;
import java.util.*;
import java.math.BigDecimal;
public class Dispatcher extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession(true);
BeanManager beanManager =
(BeanManager) session.getAttribute("beanManager");
if (beanManager == null) {
Debug.print("Creating bean manager.");
beanManager = new BeanManager();
session.setAttribute("beanManager", beanManager);
}
String selectedScreen = request.getServletPath();
Debug.print(selectedScreen);
CustomerBean customerBean = new CustomerBean();
customerBean.setBeanManager(beanManager);
request.setAttribute("customerBean", customerBean);
if (selectedScreen.equals("/accountHist")) {
AccountHistoryBean accountHistoryBean = new AccountHistoryBean();
try {
accountHistoryBean.setBeanManager(beanManager);
accountHistoryBean.setCustomerBean(customerBean);
accountHistoryBean.setAccountId(request.getParameter(
"accountId"));
accountHistoryBean.setSortOption(Integer.parseInt(
request.getParameter("sortOption")));
accountHistoryBean.setActivityView(Integer.parseInt(
request.getParameter("activityView")));
accountHistoryBean.setDate(Integer.parseInt(
request.getParameter("date")));
accountHistoryBean.setYear(Integer.parseInt(
request.getParameter("year")));
accountHistoryBean.setSinceDay(Integer.parseInt(
request.getParameter("sinceDay")));
accountHistoryBean.setSinceMonth(Integer.parseInt(
request.getParameter("sinceMonth")));
accountHistoryBean.setBeginDay(Integer.parseInt(
request.getParameter("beginDay")));
accountHistoryBean.setBeginMonth(Integer.parseInt(
request.getParameter("beginMonth")));
accountHistoryBean.setEndDay(Integer.parseInt(
request.getParameter("endDay")));
accountHistoryBean.setEndMonth(Integer.parseInt(
request.getParameter("endMonth")));
} catch (NumberFormatException e) {
}
accountHistoryBean.doTx();
request.setAttribute("accountHistoryBean", accountHistoryBean);
} else if(selectedScreen.equals("/logoff")) {
try {
Debug.print("Forwarding to template from doGet().");
request.getRequestDispatcher("/logoff.jsp")
.forward(request, response);
} catch (Exception ex) {
}
}
try {
Debug.print("Forwarding to template from doGet().");
request.getRequestDispatcher("/template/template.jsp")
.forward(request, response);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession(true);
ResourceBundle messages =
(ResourceBundle) session.getAttribute("messages");
if (messages == null) {
Locale locale = request.getLocale();
Debug.print(locale.getDisplayName());
messages = ResourceBundle.getBundle("com.sun.ebank.web.WebMessages",
locale);
if (messages == null) {
Debug.print("Didn't locate resource bundle.");
}
session.setAttribute("messages", messages);
}
String selectedScreen = request.getServletPath();
Debug.print(selectedScreen);
BeanManager beanManager =
(BeanManager) session.getAttribute("beanManager");
if (beanManager == null) {
beanManager = new BeanManager();
session.setAttribute("beanManager", beanManager);
}
CustomerBean customerBean = new CustomerBean();
customerBean.setBeanManager(beanManager);
request.setAttribute("customerBean", customerBean);
if (selectedScreen.equals("/accountHist")) {
AccountHistoryBean accountHistoryBean = new AccountHistoryBean();
try {
accountHistoryBean.setBeanManager(beanManager);
accountHistoryBean.setCustomerBean(customerBean);
accountHistoryBean.setAccountId(request.getParameter(
"accountId"));
accountHistoryBean.setSortOption(Integer.parseInt(
request.getParameter("sortOption")));
accountHistoryBean.setActivityView(Integer.parseInt(
request.getParameter("activityView")));
accountHistoryBean.setYear(Integer.parseInt(
request.getParameter("year")));
accountHistoryBean.setDate(Integer.parseInt(
request.getParameter("date")));
accountHistoryBean.setSinceDay(Integer.parseInt(
request.getParameter("sinceDay")));
accountHistoryBean.setSinceMonth(Integer.parseInt(
request.getParameter("sinceMonth")));
accountHistoryBean.setBeginDay(Integer.parseInt(
request.getParameter("beginDay")));
accountHistoryBean.setBeginMonth(Integer.parseInt(
request.getParameter("beginMonth")));
accountHistoryBean.setEndDay(Integer.parseInt(
request.getParameter("endDay")));
accountHistoryBean.setEndMonth(Integer.parseInt(
request.getParameter("endMonth")));
} catch (NumberFormatException e) {
// Not possible
}
accountHistoryBean.doTx();
request.setAttribute("accountHistoryBean", accountHistoryBean);
} else if (selectedScreen.equals("/transferAck")) {
String fromAccountId =
(String)request.getParameter("fromAccountId");
String toAccountId = (String)request.getParameter("toAccountId");
if ((fromAccountId == null) || (toAccountId == null)) {
request.setAttribute("errorMessage",
messages.getString("AccountError"));
try {
request.getRequestDispatcher("/error.jsp")
.forward(request, response);
} catch (Exception ex) {
}
} else {
TransferBean transferBean = new TransferBean();
try {
transferBean.setMessages(messages);
transferBean.setBeanManager(beanManager);
transferBean.setFromAccountId(fromAccountId);
transferBean.setToAccountId(toAccountId);
transferBean.setTransferAmount((new BigDecimal(
request.getParameter("transferAmount"))).setScale(2));
String errorMessage = transferBean.doTx();
if (errorMessage != null) {
request.setAttribute("errorMessage", errorMessage);
try {
request.getRequestDispatcher("/error.jsp")
.forward(request, response);
} catch (Exception ex) {
}
}
request.setAttribute("transferBean", transferBean);
} catch (NumberFormatException e) {
request.setAttribute("errorMessage",
messages.getString("AmountError"));
try {
request.getRequestDispatcher("/error.jsp")
.forward(request, response);
} catch (Exception ex) {
}
}
}
} else if (selectedScreen.equals("/atmAck")) {
ATMBean atmBean = new ATMBean();
try {
customerBean.setBeanManager(beanManager);
atmBean.setMessages(messages);
atmBean.setBeanManager(beanManager);
atmBean.setCustomerBean(customerBean);
atmBean.setAccountId(request.getParameter("accountId"));
atmBean.setAmount((new
BigDecimal(request.getParameter("amount"))).setScale(
2));
atmBean.setOperation(Integer.parseInt(request.getParameter(
"operation")));
String errorMessage = atmBean.doTx();
if (errorMessage != null) {
request.setAttribute("errorMessage", errorMessage);
try {
request.getRequestDispatcher("/error.jsp")
.forward(request, response);
} catch (Exception ex) {
}
}
request.setAttribute("atmBean", atmBean);
} catch (NumberFormatException e) {
request.setAttribute("errorMessage",
messages.getString("AmountError"));
try {
request.getRequestDispatcher("/error.jsp")
.forward(request, response);
} catch (Exception ex) {
}
}
}
try {
Debug.print("Forwarding to template from doPost().");
request.getRequestDispatcher("/template/template.jsp")
.forward(request, response);
} catch (Exception ex) {
}
}
}
|
| In the doGet() method I wrote the logoff option. It did not come in the downloaded
code.
|
| I did changes in the package com.sun.ebank.web.template where the Tag Libs
| are declared but I am not sure if it is needed. The changes are as follow (you can
compare with the downloaded code).
|
| DefinitionTag.java
|
public class DefinitionTag extends SimpleTagSupport {
private String definitionName = null;
private String screenId = null;
private HashMap screens = null;
public DefinitionTag() {
super();
}
public HashMap getScreens() {
return screens;
}
public void setName(String name) {
this.definitionName = name;
}
public void setScreen(String screenId) {
this.screenId = screenId;
}
public String getName() {
return this.definitionName;
}
public String getScreen(PageContext context) {
return (String)context.getRequest().getAttribute(this.screenId);
}
public void doTag() {
try {
screens = new HashMap();
getJspBody().
invoke(null);
Definition myDefinition = new Definition();
PageContext context = (PageContext) getJspContext();
String screenId = getScreen(context);
ArrayList params = (ArrayList) screens.get(screenId);
Iterator ir = null;
if (params != null) {
ir = params.iterator();
while (ir.hasNext())
myDefinition.setParam((Parameter) ir.next());
// put the definition in the page context
context.setAttribute(definitionName, myDefinition,
context.APPLICATION_SCOPE);
} else {
Debug.println("DefinitionTag: params are not defined.");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
|
| InsertTag.java
|
public class InsertTag extends SimpleTagSupport {
private String parameterName = null;
private String definitionName = null;
public InsertTag() {
super();
}
public void setParameter(String parameter) {
this.parameterName = parameter;
}
public void setDefinition(String name) {
this.definitionName = name;
}
public String getParameter() {
return this.parameterName;
}
public String getDefinition() {
return this.definitionName;
}
public void doTag() throws JspTagException {
Definition myDefinition = null;
Parameter myParameter = null;
boolean directInclude = false;
PageContext context = (PageContext) getJspContext();
// get the definition from the page context
myDefinition =
(Definition) context.getAttribute(definitionName,
context.APPLICATION_SCOPE);
// get the parameter
if ((parameterName != null) && (myDefinition != null)) {
myParameter = (Parameter) myDefinition.getParam(parameterName);
}
if (myParameter != null) {
directInclude = myParameter.isDirect();
}
try {
// if parameter is direct, print to out
if (directInclude && (myParameter != null)) {
context.getOut()
.print(myParameter.getValue());
}
// if parameter is indirect, include results of dispatching to page
else {
if ((myParameter != null) && (myParameter.getValue() != null)) {
context.include(myParameter.getValue());
}
}
} catch (Exception ex) {
Throwable rootCause = null;
if (ex instanceof ServletException) {
rootCause = ((ServletException) ex).getRootCause();
}
throw new JspTagException(ex.getMessage(), rootCause);
}
}
}
|
| Parameter.java
|
public class Parameter {
private String name;
private boolean isDirect;
private String value;
public Parameter(String name, String value, boolean isDirect) {
this.name = name;
this.isDirect = isDirect;
this.value = value;
}
public String getName() {
return name;
}
public boolean isDirect() {
return isDirect;
}
public String getValue() {
return value;
}
}
|
| ParameterTag.java
|
public class ParameterTag extends SimpleTagSupport {
private String paramName = null;
private String paramValue = null;
private String isDirectString = null;
public ParameterTag() {
super();
}
public void setName(String paramName) {
this.paramName = paramName;
}
public void setValue(String paramValue) {
this.paramValue = paramValue;
}
public void setDirect(String isDirectString) {
this.isDirectString = isDirectString;
}
public void doTag() {
boolean isDirect = false;
if ((isDirectString != null) &&
isDirectString.toLowerCase()
.equals("true")) {
isDirect = true;
}
try {
// retrieve the parameters list
if (paramName != null) {
ArrayList parameters =
((ScreenTag) getParent()).getParameters();
if (parameters != null) {
Parameter param =
new Parameter(paramName, paramValue, isDirect);
parameters.add(param);
} else {
Debug.println("ParameterTag: parameters do not exist.");
}
}
} catch (Exception e) {
Debug.println("ParameterTag: error in doTag: " + e);
}
}
}
|
| ScreenTag.java
|
| |
| | public class ScreenTag extends SimpleTagSupport {
| | private String screenId;
| | private ArrayList parameters = null;
| |
| | public ScreenTag() {
| | super();
| | }
| |
| | public ArrayList getParameters() {
| | return parameters;
| | }
| |
| | public void setScreenId(String screenId) {
| | this.screenId = screenId;
| | }
| |
| | public void doTag() {
| | parameters = new ArrayList();
| |
| | HashMap screens = (HashMap) ((DefinitionTag) getParent()).getScreens();
| |
| | if (screens != null) {
| | try {
| | if (!screens.containsKey(screenId)) {
| | screens.put(screenId, parameters);
| | }
| |
| | getJspBody()
| | .invoke(null);
| | } catch (Exception ex) {
| | ex.printStackTrace();
| | }
| | } else {
| | Debug.println("ScreenTag: Unable to get screens object.");
| | }
| | }
| | }
| |
|
| The tutorial-template.tld left as follow,
|
| | <taglib
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
web-jsptaglibrary_2_0.xsd"
| | version="2.0">
| | <description>A tag library exercising SimpleTag
handlers.</description>
| | <tlib-version>1.0</tlib-version>
| | <short-name>SimpleTagLibrary</short-name>
| | <uri>http://localhost:8080/bank/tags</uri>
| | <tag>
| | <name>mydefinition</name>
| | <tag-class>com.sun.ebank.web.template.DefinitionTag</tag-class>
| | <body-content>scriptless</body-content>
| | <attribute>
| | <name>name</name>
| | <required>true</required>
| | <rtexprvalue>true</rtexprvalue>
| | </attribute>
| | <attribute>
| | <name>screen</name>
| | <required>true</required>
| | <rtexprvalue>true</rtexprvalue>
| | </attribute>
| | </tag>
| | <tag>
| | <name>myscreen</name>
| | <tag-class>com.sun.ebank.web.template.ScreenTag</tag-class>
| | <body-content>scriptless</body-content>
| | <attribute>
| | <name>screenId</name>
| | <required>true</required>
| | <rtexprvalue>true</rtexprvalue>
| | </attribute>
| | </tag>
| | <tag>
| | <name>myparameter</name>
| | <tag-class>com.sun.ebank.web.template.ParameterTag</tag-class>
| | <body-content>scriptless</body-content>
| | <attribute>
| | <name>name</name>
| | <required>true</required>
| | <rtexprvalue>true</rtexprvalue>
| | </attribute>
| | <attribute>
| | <name>value</name>
| | <required>true</required>
| | <rtexprvalue>true</rtexprvalue>
| | </attribute>
| | <attribute>
| | <name>direct</name>
| | <required>true</required>
| | <rtexprvalue>true</rtexprvalue>
| | </attribute>
| | </tag>
| | <tag>
| | <name>myinsert</name>
| | <tag-class>com.sun.ebank.web.template.InsertTag</tag-class>
| | <body-content>scriptless</body-content>
| | <attribute>
| | <name>definition</name>
| | <required>true</required>
| | <rtexprvalue>true</rtexprvalue>
| | </attribute>
| | <attribute>
| | <name>parameter</name>
| | <required>true</required>
| | <rtexprvalue>true</rtexprvalue>
| | </attribute>
| | </tag>
| | </taglib>
| |
|
| And the screendefinitions.jspf changes to screendefinitions.jsp with the following
code (no JSP script),
|
| | <%@page contentType="text/html" pageEncoding="UTF-8"
isELIgnored="false" %>
| |
| | <tt:mydefinition name="bank"
screen="${requestScope['javax.servlet.forward.servlet_path']}">
| | <tt:myscreen screenId="/main">
| | <tt:myparameter name="title" value="Duke's Bank"
direct="true"/>
| | <tt:myparameter name="banner"
value="/template/banner.jsp" direct="false"/>
| | <tt:myparameter name="links"
value="/template/links.jsp" direct="false"/>
| | <tt:myparameter name="body" value="/main.jsp"
direct="false"/>
| | </tt:myscreen>
| | <tt:myscreen screenId="/transferAck">
| | <tt:myparameter name="title" value="TransferSucceeded"
direct="true"/>
| | <tt:myparameter name="banner"
value="/template/banner.jsp" direct="false"/>
| | <tt:myparameter name="links"
value="/template/links.jsp" direct="false"/>
| | <tt:myparameter name="body" value="/transferAck.jsp"
direct="false"/>
| | </tt:myscreen>
| | <tt:myscreen screenId="/transferFunds">
| | <tt:myparameter name="title" value="TransferFunds"
direct="true"/>
| | <tt:myparameter name="banner"
value="/template/banner.jsp" direct="false"/>
| | <tt:myparameter name="links"
value="/template/links.jsp" direct="false"/>
| | <tt:myparameter name="body" value="/transferFunds.jsp"
direct="false"/>
| | </tt:myscreen>
| | <tt:myscreen screenId="/atmAck">
| | <tt:myparameter name="title" value="WDSucceeded"
direct="true"/>
| | <tt:myparameter name="banner"
value="/template/banner.jsp" direct="false"/>
| | <tt:myparameter name="links"
value="/template/links.jsp" direct="false"/>
| | <tt:myparameter name="body" value="/atmAck.jsp"
direct="false"/>
| | </tt:myscreen>
| | <tt:myscreen screenId="/atm">
| | <tt:myparameter name="title" value="WD"
direct="true"/>
| | <tt:myparameter name="banner"
value="/template/banner.jsp" direct="false"/>
| | <tt:myparameter name="links"
value="/template/links.jsp" direct="false"/>
| | <tt:myparameter name="body" value="/atm.jsp"
direct="false"/>
| | </tt:myscreen>
| | <tt:myscreen screenId="/accountHist">
| | <tt:myparameter name="title" value="AccountHistory"
direct="true"/>
| | <tt:myparameter name="banner"
value="/template/banner.jsp" direct="false"/>
| | <tt:myparameter name="links"
value="/template/links.jsp" direct="false"/>
| | <tt:myparameter name="body" value="/accountHist.jsp"
direct="false"/>
| | </tt:myscreen>
| | <tt:myscreen screenId="/accountList">
| | <tt:myparameter name="title" value="AccountList"
direct="true"/>
| | <tt:myparameter name="banner"
value="/template/banner.jsp" direct="false"/>
| | <tt:myparameter name="links"
value="/template/links.jsp" direct="false"/>
| | <tt:myparameter name="body" value="/accountList.jsp"
direct="false"/>
| | </tt:myscreen>
| | <tt:myscreen screenId="/logoff">
| | <tt:myparameter name="title" value="Logoff"
direct="true"/>
| | <tt:myparameter name="banner"
value="/template/banner.jsp" direct="false"/>
| | <tt:myparameter name="links"
value="/template/nolinks.jsp" direct="false"/>
| | <tt:myparameter name="body" value="/logoff.jsp"
direct="false"/>
| | </tt:myscreen>
| | </tt:mydefinition>
| |
|
| It is important to understand the needed to put at the top of the page the tag,
|
|
| | <%@page contentType="text/html" pageEncoding="UTF-8"
isELIgnored="false" %>
| |
|
| It helps to the page to execute EL code. Put it in all the JSPs that use EL. It is
important too that you include, <%@ include file=â/template/prelude.jspfâ %> in
all the JSPs that use prefix c or fmt
|
| As you can see I use in the <tt:â¦> satanza the name declared in the
tutorial-template.tld
|
| And I think that is all. To end how I build the application. I use an XML Ant file,
|
| jboss-build.xml
|
| | <project name="JBossDukesBank" default="all"
basedir=".">
| |
| | <property file="jboss-build.properties"/>
| |
| | <property name="lib.dir"
value="${basedir}/libs"/>
| | <property name="src.dir" value="${basedir}/src"/>
| | <property name="build.dir"
value="${basedir}/build"/>
| | <property name="conf.dir" value="${basedir}/dd"/>
| | <property name="web.dir" value="${basedir}/web"/>
| |
| | <property name="web.content.dir"
location="${basedir}/WebContent"/>
| | <property name="web.inf.dir"
location="${web.content.dir}/WEB-INF"/>
| | <property name="classes.dir"
location="${web.inf.dir}/classes"/>
| | <property name="app.lib.dir"
location="${web.inf.dir}/lib"/>
| | <property name="autentiaApp.lib.dir" location="libs"/>
| |
| | <!-- The classpath for running the client -->
| | <path id="client.classpath">
| | <pathelement location="${build.dir}"/>
| | <fileset dir="${jboss.home}/client">
| | <include name="**/*.jar"/>
| | </fileset>
| | </path>
| |
| | <!-- The build classpath -->
| | <path id="axis.classpath">
| | <pathelement location="${build.dir}"/>
| | <fileset dir="/Users/orb/Desktop/axis-1_1/lib">
| | <include name="*.jar"/>
| | </fileset>
| | <fileset dir="${jboss.server}/lib/">
| | <include name="javax.servlet*.jar"/>
| | </fileset>
| | </path>
| |
| |
| | <!-- The build classpath -->
| | <path id="build.classpath">
| | <path refid="client.classpath"/>
| | <fileset dir="${jboss.server}/lib/">
| | <include name="javax.servlet*.jar"/>
| | </fileset>
| | </path>
| |
| | <!-- MySQL classpath -->
| | <path id="mysql.classpath">
| | <pathelement
location="${jboss.server}/lib/mysql-connector-java-5.1.6-bin.jar"/>
| | </path>
| |
| | <!-- ===================================================================
-->
| | <!-- Initialises the build.
-->
| | <!-- ===================================================================
-->
| |
| | <target name="prepare">
| | <mkdir dir="${build.dir}"/>
| | </target>
| |
| | <!-- ===================================================================
-->
| | <!-- Package EJB.
-->
| | <!-- ===================================================================
-->
| | <target name="package-ejb">
| | <delete file="jar/bank-ejb.jar"/>
| |
| | <jar jarfile="jar/bank-ejb.jar">
| | <metainf dir="${conf.dir}/ejb"
includes="**/*.xml" />
| |
| | <fileset dir="${build.dir}">
| | <include name="com/sun/ebank/ejb/account/**"/>
| | <include name="com/sun/ebank/ejb/customer/**"/>
| | <include name="com/sun/ebank/ejb/tx/**"/>
| | <include name="com/sun/ebank/ejb/exception/**"/>
| | <include name="com/sun/ebank/util/**"/>
| | </fileset>
| | </jar>
| | </target>
| |
| | <!-- ===================================================================
-->
| | <!-- Cliente Desktop.
-->
| | <!-- ===================================================================
-->
| | <target name="package-client">
| |
| | <delete file="jar/bank-client.jar"/>
| |
| | <copy todir="${build.dir}">
| | <fileset dir="${src.dir}">
| | <include name="**/appclient/*.properties"/>
| | </fileset>
| | <mapper type="flatten"/>
| | </copy>
| |
| | <jar jarfile="jar/bank-client.jar">
| | <metainf dir="dd/client" includes="*.xml"/>
| | <fileset dir="${build.dir}">
| | <include name="com/sun/ebank/appclient/**"/>
| | </fileset>
| | </jar>
| | </target>
| |
| | <!-- ===================================================================
-->
| | <!-- Cliente Web.
-->
| | <!-- ===================================================================
-->
| |
| | <macrodef name="package-web">
| | <attribute name="war.file.name"
default="bank-web.war"/>
| | <element name="add.filesets" optional="true"/>
| | <sequential>
| |
| | <delete file="jar/bank-web.war"/>
| |
| | <copy file="${web.content.dir}/logon.jsp"
tofile="${web.content.dir}/logon2.jsp" />
| | <copy
file="${src.dir}/com/sun/ebank/web/WebMessages.properties"
| |
tofile="${src.dir}/com/sun/ebank/web/WebMessages_en.properties" />
| | <copy todir="${app.lib.dir}"
preservelastmodified="true">
| | <fileset dir="${autentiaApp.lib.dir}"
includes="*.jar" excludes="servlet-api.jar"/>
| | </copy>
| | <copy todir="${web.content.dir}"
preservelastmodified="true">
| | <fileset dir="${src.dir}/com/sun/ebank/web/"
includes="*.properties" />
| | </copy>
| |
| | <war basedir="${web.content.dir}"
destfile="jar/(a){war.file.name}" duplicate="fail"
| | webxml="${web.inf.dir}/web.xml"
excludes="WEB-INF/web.xml">
| | <add.filesets/>
| | </war>
| |
| | <!--
| | <delete verbose="true">
| | <fileset
dir="${web.content.dir}/WEB-INF/classes/com/sun/ebank/ejb"
includes="**/*.class"/>
| | </delete>
| |
| | <delete verbose="true">
| | <fileset
dir="${web.content.dir}/WEB-INF/classes/com/sun/ebank/util"
includes="**/*.class"/>
| | </delete>
| | -->
| | </sequential>
| | </macrodef>
| |
| | <!-- ===================================================================
-->
| | <!-- Creates an ear file containing the ejb jars and the clients.
-->
| | <!-- ===================================================================
-->
| | <target name="assemble-app">
| | <delete file="jar/JBossDukesBank.ear"/>
| | <ear destfile="jar/JBossDukesBank.ear"
appxml="dd/application.xml">
| | <fileset dir="jar"
includes="bank-ejb.jar,bank-client.jar,bank-web.war"/>
| | </ear>
| | </target>
| |
| | <!-- ===================================================================
-->
| | <!-- Deploys the EAR file by copying into the jar deploy directory.
-->
| | <!-- ===================================================================
-->
| | <target name="deploy">
| | <copy file="jar/JBossDukesBank.ear"
todir="${basedir}/jar"/>
| | </target>
| |
| | <target name="package-web">
| | <package-web/>
| | </target>
| |
| | <target name="all"
depends="package-ejb,package-web,package-client,assemble-app,deploy" />
| |
| | </project>
| |
|
| As you can see I use three packages: the -ejb.jar that include the EJBs, the package
EJBExceptions and the package util. And as stand alone the clients: the desktop client and
the web client. When I assemble all together in the JBossDukesBank.ear, both clients have
access to the common âejb.jar
|
| Thanks a lot
| Jose Alvarez de Lara
|
| For any question I will be here.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4203226#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...