Browse DevX
Sign up for e-mail newsletters from DevX


Use SOAP to Access EJB Components with PHP : Page 2

PHP code on the front end and EJBs on the back end—how do you make them talk to each other? Apply a little SOAP. Exposing the EJBs as Web services enables PHP to work with them, and SOAP is the key.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Prepare Your EJB Component
First things first: make sure you've downloaded and properly installed J2SE and J2EE. You need them to follow the example EJB component.

The following are the source code listings for the stateless session bean:

  • Remote home interface: greentest/HelloWorldHome.java:

    package greentest; import javax.ejb.*; import java.rmi.RemoteException; public interface HelloWorldHome extends EJBHome { public HelloWorld create() throws CreateException, RemoteException; }

  • Remote interface: greentest/HelloWorld.java:

    package greentest; import javax.ejb.*; import java.rmi.RemoteException; public interface HelloWorld extends EJBObject { public String say() throws RemoteException; }

  • And the bean itself: greentest/HelloWorldBean.java:

    package greentest; import javax.ejb.*; public class HelloWorldBean implements SessionBean { public void setSessionContext(SessionContext ctx) { System.out.println("In setSessionContext(...)"); } public void ejbCreate() { System.out.println("In ejbCreate()"); } public void ejbActivate() { System.out.println("In ejbActivate()"); } public void ejbPassivate() { System.out.println("In ejbPassivate()"); } public void ejbRemove() { System.out.println("In ejbRemove()"); } public String say() { System.out.println("In business method say()"); return "Hello World! I am just tiny Stateless Session Bean!"; } }

As you can see, the only active business method in the bean is say(), which returns the "Hello World" string. So, as long as you've installed J2SE and J2EE and modified the CLASSPATH environment variable, you can compile everything now. All source files should be in directory src/, and all classes will need to be in directory classes/. Also, don't forget that as long as the enterprise bean is in the package greentest, you need a subdirectory named greentest in classes/ and src/ as well. Other than that, the compilation process is easy:

cd src\ javac -d ..\classes greentest\*.java

You should not have any problems if you correctly followed all the steps and set CLASSPATH correctly.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date