...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="UTF-8"?> <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>bank-jetty</dep:artifactId> <dep:version>2.1.2-SNAPSHOT<2</dep:version> <dep:type>car</dep:type> </dep:moduleId> <dep:dependencies> <dep:dependency> <dep:groupId>org.apache.geronimo.configs<samples</dep:groupId> <dep:artifactId>jasper<artifactId>sample-datasource</dep:artifactId> <dep:version>2.1.2-SNAPSHOT<2</dep:version> <dep:type>car</dep:type> </dep:dependency> <dep:dependency> <dep:groupId>org.apache.geronimo.configs</dep:groupId> <dep:artifactId>jetty6</dep:artifactId> <dep:version>2.2-SNAPSHOT<1.2</dep:version> <dep:type>car</dep:type> </dep:dependency> <dep:dependency> <dep:groupId>org.apache.geronimo.configs</dep:groupId> <dep:artifactId>openjpa<artifactId>jasper</dep:artifactId> <dep:version>2.1.2-SNAPSHOT<2</dep:version> <dep:type>car</dep:type> </dep:dependency> <dep:dependency> <dep:groupId>org.apache.geronimo.configs</dep:groupId> <dep:artifactId>openejb</dep:artifactId> <dep:version>2.2-SNAPSHOT<1.2</dep:version> <dep:type>car</dep:type> </dep:dependency> <dep:dependency> <dep:groupId>org.apache.geronimo.samples<configs</dep:groupId> <dep:artifactId>sample-datasource<artifactId>openjpa</dep:artifactId> <dep:version>2.1.2-SNAPSHOT<2</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 customer</attribute>--> <attribute name="path">BankDB.sql</attribute> <reference name="DataSource"> <name>SampleTxDatasource</name> </reference> </gbean> </application> |
...
Banking command line client
The bank command line client does a JNDI lookup to the remote interface. Later, the list of ExchangeRate is obtained and printed out on the screen.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
package org.apache.geronimo.samples.bank.client;
import java.util.List;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeRemote;
import org.apache.geronimo.samples.bank.ejb.ExchangeRate;
public class BankClient {
public static void main(String[] args) {
Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
p.setProperty(Context.PROVIDER_URL, "ejbd://localhost:4201");
try {
Context ic = new InitialContext(p);
BankManagerFacadeRemote bmr = (BankManagerFacadeRemote) ic.lookup("BankManagerFacadeBeanRemote");
List<ExchangeRate> rates = bmr.getExchangeRates();
System.out.println("Exchange Rates");
for (int i = 0; i < (int) rates.size(); i++) {
ExchangeRate rate = rates.get(i);
System.out.println("Currency: " + rate.getCurrency());
System.out.println("Rate: " + rate.getRate());
System.out.println();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
Note |
---|
Please note that "BankManagerFacadeBeanRemote" is used here as the look up name instead of "BankManagerFacadeRemote". Otherwise, you'll get an error like this - javax.naming.NameNotFoundException: /BankManagerFacadeRemote does not exist in the system. Check that the app was successfully deployed. |
To test the command line client first determine a useable (although excessive classpath) by running
...
Code Block |
---|
java -cp <output from above>:target/bank-client-<version>.jar org.apache.geronimo.samples.bank.client.BankClient |