Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Use SOAP to Access EJB Components with PHP : Page 3

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.


advertisement
Deploy Your EJB Component
Next, you need to deploy the component bean. So, run your J2EE RI server:

j2ee –verbose

The –verbose option allows you to see all the debug messages from the server.



Now, in a separate window (the J2EE RI server needs to be running all the time), run the deploy tool from J2EE package:

deploytool

To prepare and deploy the EJB component, take the following steps (consult the screenshots for guidance):

  1. FILE → NEW → APPLICATION

    Click to enlarge
    Figure 2: New Application Wizard
  2. Click OK. Single click on AlohaApp.
  3. FILE → NEW → ENTERPRISE BEAN, click NEXT

    Click to enlarge
    Figure 3: New Enterprise Bean Wizard - EJB JAR
  4. Click NEXT

    Click to enlarge
    Figure 4: New Enterprise Bean Wizard - General
  5. Click NEXT, then FINISH.
  6. TOOLS → DEPLOY

    Click to enlarge
    Figure 5: Deploy AlohaApp - Introduction
  7. Click NEXT

    Click to enlarge
    Figure 6: Deploy AlohaApp - JNDI Names
  8. Click FINISH

    Click to enlarge
    Figure 7: Deployment Progress
If you arrived at the screen display above, you did everything correctly and your EJB component is deployed.

Test Your EJB Component
Now it's time to test whether it works. You need to compile your client tool: HelloWorldClient.java. The following is the source code:

import javax.ejb.*; import javax.naming.*; import java.rmi.*; import javax.rmi.*; import greentest.*; public class HelloWorldClient { public void go() { try { Context ic = new InitialContext(); // during deployment, in JNDI we called it 'Aloha', remember? Object o = ic.lookup("Aloha"); HelloWorldHome home = (HelloWorldHome) PortableRemoteObject.narrow(o,
HelloWorldHome.class); HelloWorld aloha = home.create(); System.out.println(aloha.say()); } catch (Exception ex) { ex.printStackTrace(); } } public static void main(String[] args) { new HelloWorldClient().go(); } }

To compile it, use AlohaAppClient.jar (consisting of classes and stubs), which the deployment tool generated during the steps above. The compilation process itself is pretty easy:

javac -classpath %CLASSPATH%;C:\green\php_with_ejb\AlohaAppClient.jar HelloWorldClient.java

Execute the normal client for your stateless session bean.

Click to enlarge
Figure 8: Executed Client for Stateless Session Bean

If you see the above output, you've done everything correctly.



Comment and Contribute

 

 

 

 

 


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

 

 

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