Now that you have finished developing your bean, you can test it by deploying it to an application server. JBoss, the EJB server that ships with AppComposer, allows you to test your EJBs in a deployment environment.
To deploy the EJB that you built to a different application server (usually the one that runs your web applications) you have to save the EJB capsule as a jar file. When you save an EJB capsule as a jar file, AppComposer compiles and generates the bean implementation, remote interface, and home interface. It places these resources in a package called acejb. AppComposer also generates ejb-jar.xml, the deployment descriptor for the bean, and puts it in the jar file's META-INF directory. Before you generate the jar file, you need to define a data source that goes into the deployment descriptor file. Instead of having to edit the ejb-jar.xml file by hand, AppComposer allows you to add an EJB resource while building the capsule. It is automatically included when AppComposer generates the bean's deployment descriptor.
When building this capsule, the database interactions you configured in the SQL select and update actors were made directly through JDBC. This is fine for building behaviors, but when running a session bean from an EJB server, you usually must set up a data source that corresponds to the correct database connection. This allows the application server to manage access to the particular database across whatever applications it is running. The EJB using the data source needs to designate it using its deployment descriptor.
Session EJB capsules have a section of the details pane called EJB Resources. Use this pane to set up a data source with the following attributes. AppComposer adds this to the deployment descriptor when you save the EJB capsule as a jar.
Now you are ready to generate the bean from the capsule.
Before you try to use the session bean, change the URL of the data source that the bean uses from the JDBC URL used for development to the URL of the datasource defined in JBoss.
AppComposer uses a different URL for the EJB during construction and editing of the session bean capsule. The ejbdata.url allows the container to find information it needs to connect the EJB capsule and its database. If you use a text editor to open the AppComposer/sql.properties file, you see an entry that looks like:
ejbdata.url=jdbc:pointbase://127.0.0.1:10020/ejbdata #ejbdata.url=java:/DefaultDS ejbdata.maxconn=2 ejbdata.user=public ejbdata.password=public
Application server environments generally use configured Data Sources rather than getting database connections directly through JDBC. To use the session bean, change the URL of the ejbdata connection to that of the name of the data source you defined for JBoss. Only EJB capsules need this change between edit time and runtime, so they can fully utilize the enterprise resources of the EJB server. Data sources are only available when accessed from within an application server, so when building the query, you used the JDBC URL directly.
#ejbdata.url=jdbc:pointbase://127.0.0.1:10020/ejbdata ejbdata.url=java:/DefaultDS ejbdata.maxconn=2 ejbdata.user=public ejbdata.password=public
You now have a runnable EJB that you can use in AppComposer capsules or other development environments. It is deployed and ready to test. AppComposer includes a servlet capsule named SimpleBankServlet.zac that you can use to test your session bean. This capsule acts as the client to the session bean.
Basically, each time the servlet runs, it creates an instance of a SimpleBankEJB with the account number "111111". The servlet displays the account holder's name and current balance, and withdraws $500.00 from the account. If you run the servlet a second time, you see that the balance is lower because of the original withdrawal. The withdraw method commits to the database because the its transaction level is set to "Required". If running in an application server other than JBoss, you need to include the sql.properties file in the base directory of the application server installation.
Congratulations! You have successfully built a complex session bean capsule, deployed it, and tried using it as an actor in another capsule.
For more information on building, designing and using session EJBs, and for details on types of session beans not discussed here, see: