Invoking the Blazix Entity Bean EJB wizard
Invoking the Blazix Entity Bean EJB wizard
[pic]
You will get this error if you have no database sources set up
[pic]
After configuring at least one data source in the EJB ejb.ini configuration
dataSource.name: propsDataSource
dataSource.propsDataSource.odbc: props
we get the following window
[pic]
Next we’re prompted to select a table from the database
[pic]
Next we set the EJB properties to database table attributes mappings (note it’s a PK)
[pic]
and we can generate finders for the property
[pic]
Do the same for the other property we have in the table
[pic]
Create all the finders for the property
[pic]
Now tell Blazix where to store the EJB sources and jar
[pic]
The wizard will create directories, if necessary
[pic]
The contents of the MyEJBSources contain the following
build.cmd
PropsTable.java
PropsTableBean.java
PropsTableHome.java
Running the command file build.cmd generates the following messages
C:\Blazix\MyEJBSources>jar -cvf PropsTable.jar -C "c:\blazix\MyEJBSources" META-
INF/ejb-jar.xml "propsTable/PropsTableHome.class" "propsTable/PropsTable.class"
"propsTable/PropsTableBean.class"
added manifest
adding: META-INF/ejb-jar.xml(in = 899) (out= 435)(deflated 51%)
adding: propsTable/PropsTableHome.class(in = 848) (out= 358)(deflated 57%)
adding: propsTable/PropsTable.class(in = 314) (out= 207)(deflated 34%)
adding: propsTable/PropsTableBean.class(in = 1489) (out= 613)(deflated 58%)
C:\Blazix\MyEJBSources>blxejbc PropsTable.jar PropsTableEjb.jar
Blazix EJB Compiler 1.2
Copyright (C) Desiderata Software, 2001-2002
All rights reserved
Configuration file: C:\Blazix\ejb.ini
JRMP Version
Processing Entity bean "PropsTable"
Validating bean classes
Generating bean support classes
PropsTable: Compiling classes with javac
PropsTable: Generating RMI classes
PropsTable: Adding to JAR file PropsTableEjb.jar
"PropsTable.jar" ==> "PropsTableEjb.jar": EJB compilation successful
The EJB wizard reports
Configuration file: C:\Blazix\ejb.ini
The following entity bean source files have been created:
Remote Interface: c:\blazix\MyEJBSources\PropsTable.java
Home Interface: c:\blazix\MyEJBSources\PropsTableHome.java
Bean Class: c:\blazix\MyEJBSources\PropsTableBean.java
The ejb-jar file has been created in:
c:\blazix\MyEJBSources\META-INF\ejb-jar.xml
The commands to build and compile the entity bean are in:
c:\blazix\MyEJBSources\build.cmd
And the MyEJBSources contain
PropsTable.java
PropsTableBean.java
PropsTableHome.java
META-INF
build.cmd
propsTable * directory of class files
PropsTable.jar
PropsTableEjb.jar
We now complete the ejb.ini file, adding the EJB information
dataSource.name: propsDataSource
dataSource.propsDataSource.odbc: props
ejbJar: c:\blazix\MyEJBSources\PropsTableEjb.jar
ejb.PropsTable.dataSource: propsDataSource
ejb.PropsTable.table: PropsTable
Now we can start the Blazix EJB Server:
C:\Blazix>blxejbs
Log file: C:\Blazix\Ejblog.log
Blazix EJB Server 1.2
Copyright (C) Desiderata Software, 2001-2002
All rights reserved
Configuration file: C:\Blazix\ejb.ini
JRMP version
Deploying EJB-Home class "propsTable.PropsTableHome" at JNDI name "PropsTable
Evaluation license
Listening at CHOPIN:2050
EJB Server operational at Sat Mar 08 21:06:42 EST 2003
command line:
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH% propsTable.EntityClientSample put 11 4568
Read prop = 11 value = 4568
Set value of "11" to "4568"
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH% p
ropsTable.EntityClientSample put 123453344 dichter
Read prop = 123453344 value = dichter
Set value of "123453344" to "dichter"
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH%
propsTable.EntityClientSample get 123453344
Read prop = 123453344 value = null
123453344: dichter
where my.policy is a file with contents
grant {
permission java.security.AllPermission;
};
Important Steps to Run the Application accessing EJBs
I modified the blxweb.cmd file as follows:
@C:
@cd C:\Blazix
@java -Djava.security.policy=my.policy -classpath " C:\Blazix\blazix.jar;C:\Blazix\classes;%CLASSPATH%" desisoft.server.ServerMain %1 %2 %3 %4 %5 %6 %7 %8
The modified part is underlined and bolded. It allows the web server to run RMI lookups into the EJB server.
Be sure the my.policy file is in the same place as the blxweb.cmd file.
The class files are in the jar file, which can be anywhere, but I add its location into the ejb.ini file as shown below:
ejbJar: c:\blazix\MyEJBSources\PropsTableEjb.jar
ejb.PropsTable.dataSource: propsDataSource
ejb.PropsTable.table: PropsTable
Only the bolded, underlined line is relevant here.
The entire source code is on the next page. Note the javax.rmi package. This in not the same as the java.rmi package.
Complete Client Source code to EJB application client
// EntityClientSample.java
// Sample program showing entity bean usage.
package propsTable;
import javax.naming.*; import javax.ejb.*; import javax.rmi.*;
import java.util.*; import propsTable.*;
public class EntityClientSample {
static boolean doGet = false;
static String prop = null;
static String value = null;
static public void main( String[] args ) {
checkArgs( args );
try {
// Obtain the EJB home
Properties env = new Properties();
env.put( "java.naming.factory.initial", "desisoft.ejb.client.JRMPFactory" );
env.put( "desisoft.ejb.nameServer1", "localhost:2050" );
Context ctx = new InitialContext( env );
Object object = PortableRemoteObject.narrow(ctx.lookup( "PropsTable" ), PropsTableHome.class );
PropsTableHome home = (PropsTableHome) object;
PropsTable bean;
if ( doGet ) {
try {
bean = home.findByPrimaryKey( prop );
System.out.println( prop + ": " + bean.getValue());
} catch (FinderException notFound) {
System.out.println( "Property \"" + prop + "\" was not found" );
}
} else {
try {
bean = home.create( prop, value );
} catch (DuplicateKeyException exists) {
bean = home.findByPrimaryKey( prop );
}
bean.setValue( value );
System.out.println( "Set value of \"" + prop + "\" to \"" + value + "\"" );
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
Complete Client Source code to EJB application client
static void usage()
{
System.out.println( "Usage: java EntityClientSample put " );
System.out.println( " java EntityClientSample get " );
System.exit( 0 );
}
static void checkArgs( String[] args )
{
if ( args.length < 2 )
usage();
prop = args[1];
if ( args[0].equalsIgnoreCase( "get" )) {
if ( args.length > 2 )
usage();
doGet = true;
} else if ( args[0].equalsIgnoreCase( "put" )) {
if ( args.length != 3 )
usage();
doGet = false;
value = args[2];
} else
usage(); } }
Sample Output of my Program run
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH% p
ropsTable.EntityClientSample get 1000002
1000002: Maryland
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH% p
ropsTable.EntityClientSample get 1000003
1000003: Rhode Island
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH% p
ropsTable.EntityClientSample get 1000001
1000001: Connecticut
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH% p
ropsTable.EntityClientSample get 1000007
Property "1000007" was not found
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH% p
ropsTable.EntityClientSample put 1000066 Illinois
Set value of "1000066" to "Illinois"
C:\Blazix\MyEJBSources>java -Djava.security.policy=my.policy -cp .;%CLASSPATH% p
ropsTable.EntityClientSample get 1000066
1000066: Illinois
Note that the program response in bolded
Important Steps to Run the JSP client accessing EJBs
It is important the EJB is deployed in one way in the Container (AS). For example you can use either of these two ways
1. put the EJB jar into the ejbdir of the Blazix server
The directory can be modified in the ejb.ini file as shown below
# EJB JAR files can be copied to this directory for automatic deployment
ejbDir: C:\Blazix\ejbdir
2. Put the EJB jar into the system CLASSPATH, and start the AS and WS after the CLASSPATH is set.
Note: Do not put any of the EJB class files into the WS or AS CLASSPATH
The Screenshots of the HTML/JSP/JSP Bean/EJB Model Run
[pic]
Above is the HTML page you get initially.
[pic]
Above is the response as produced by the JSP page.
The code to run the Web-Based Example
Action (get/put):
PUT
GET
Property:
Value:
Register
This is the initial HTML page
This is the JSP Page
A JSP page with JSP Bean
Action
Property
Value:
The JSP creates a JSP Bean beanie of class, JSPEntityProps. The three parameters are set on beanie. Bean beanie instantiates through a lookup an EJB Bean using its “PropsTable” JNDI registered name. Through the EJB, beanie sets its properties, and the JSP page above can fill its fields.
The code for the JSPEntityProps class is on the next page.
The JSPEntityProps class Code
package propsTable;
import javax.naming.*; import javax.ejb.*; import java.util.*; import propsTable.*;
import java.rmi.*; import javax.rmi.PortableRemoteObject;
public class JSPEntityProps {
private String action;
private String prop;
private String value;
private PropsTableHome home;
private PropsTable bean;
private Object object;
public JSPEntityProps ( ) {
try {
// Obtain the EJB home
Properties env = new Properties();
env.put( "java.naming.factory.initial", "desisoft.ejb.client.JRMPFactory" );
env.put( "desisoft.ejb.nameServer1", "localhost:2050" );
Context ctx = new InitialContext( env );
object = (propsTable.PropsTableHomeCtx_Stub) ctx.lookup ( "PropsTable" ); //
home = (PropsTableHome) object; } // try
catch (Exception e) { e.printStackTrace(); } }
public void setProp (String prop) throws Exception { this.prop = prop; }
public String getProp() throws Exception {
if ( prop == null) throw new Exception("Property is NULL");
return prop; }
public void setValue(String value) throws Exception {
this.value = value;
if ( action.equalsIgnoreCase("put"))
doSet() ; }
public String getValue() throws Exception {
if ( action.equalsIgnoreCase("get"))
value = doGet() ;
return value; }
public void setAction(String action) throws Exception {
if ( ! action.equalsIgnoreCase("get") && ! action.equalsIgnoreCase("put"))
throw new Exception("'get' or 'put' required in field");
this.action = action; }
public String getAction() { return action; }
The JSPEntityProps class Code
public String doGet( ) throws Exception {
String value = "";
try {
bean = home.findByPrimaryKey( prop );
return bean.getValue(); }
catch (FinderException notFound) {
throw new Exception( "==> Property \"" + prop + "\" was not found" ); }
catch (RemoteException re) {
throw new Exception("==> Remote Exception"); } }
public void doSet() throws Exception {
try {
try {
bean = home.create( prop, value ); }
catch (DuplicateKeyException exists) {
bean = home.findByPrimaryKey( prop ); } }
catch (FinderException fe) { throw new Exception( "===> Finder Exception"); }
catch (CreateException ce) { throw new Exception( "===> Create Exception"); }
catch (RemoteException re) { throw new Exception( "===> RemoteException"); }
try {
bean.setValue( value );
System.out.println( "Set value of \"" + prop + "\" to \"" + value + "\"" ); }
catch (Exception ex) {
System.err.println( "===> Cannot set Value");
ex.printStackTrace(); } } }
The EJB used in the web based example is the same as the one used in the application example. It is similar to the one we generated with the EJB wizard in class. Recall that in the wizard we specified the Database name and the table to which we mapped the EJB properties.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- html forms javascript and cascading style sheets
- how to put a javascript into an html page
- tags that need to go inside other tags ece cis
- html or hypertext markup language is an easy way to tell
- html forms richland community college
- invoking the blazix entity bean ejb wizard
- jsp examples illinois state university
- introduction
Related searches
- the coffee bean menu
- why was the savings bond wizard discontinued
- the coffee bean coursey
- the coffee bean baton rouge
- the coffee bean locations
- the coffee bean nutrition information
- the coffee bean near me
- the coffee bean tea leaf
- the coffee bean and tea
- the coffee bean tea lea
- the wizard stock trading
- the coffee bean store