Browse DevX
Sign up for e-mail newsletters from DevX


Extend Your J2EE Applications into Web Services : Page 2

Web services are here. It's time to extend your J2EE applications. Apache Axis allows you to Web-service enable existing J2EE applications without touching your back-end business logic.




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

Invoking EJBs
The JSP Web interface acquires user-entered text via a text field, instantiates and invokes the session bean's reverseString() method, and displays the results. Invoking the EJB involves the following:
  1. Initializing Context:

    Context context = new InitialContext();

  2. Looking up the bean:

    Object boundObject = context.lookup(java:comp/env/MyEJB);

  3. Narrowing the object to conform to the given interface:

    myEJBHome = (MyEJBHome) PortableRemoteObject.narrow(boundObject,MyEJBHome.class); myEJB = (MyEJB) PortableRemoteObject.narrow(myEJBHome.create(),MyEJB.class);

  4. Invoking the methods on the remote object:


Deploying the J2EE Application
The latest crop of J2EE and Web services technologies are configuration-file driven. This concept is a double-edged sword. If you know how each field in the configuration file affects your application, configuring the application is a piece of cake. However, if it lacks proper documentation and its log files do not provide detailed error messages, getting your application up and running will be a nightmare.

The sample J2EE application has three configuration files, web.xml, ejb-jar.xml, and application.xml:

  • The web deployment descriptor (web.xml) file contains tags to define the welcome page of the application, EJB references used within the JSP pages, Servlets, and the application's servlet mappings.
  • The EJB deployment descriptor (ejb-jar.xml) file contains tags to define the enterprise beans, remote interface classes, home interface classes, and EJB types.
  • The application.xml file contains tags to define deployment of the Web module and the EJB module, as well as tags to define data sources. (For additional information about the available tags for OC4J application server, refer to OC4J documentation at orionserver.com.)

J2EE defines an organized way for deploying enterprise applications. Web interface files (JSPs, Servlets, and HTML pages), along with the Web configuration file (web.xml), are put into Web Archive (war) file. EJB classes, along with the deployment descriptor (ejb-jar.xml), are put into Java Archive (jar) file. The war file, jar file, and application configuration file (application.xml) are put into an Enterprise Archive (ear) file. (See Figure 1).

Figure 1: A J2EE Application with Deployment Descriptors

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