Developing for WebLogic Server 8.1 with Oracle JDeveloper 10g

by Deepak Vohra
02/07/2006

The business method getAppServer() is exposed through the SessionEJBLocal interface. Next, create a JSP client for the session EJB. Right-click on the View project node in the Applications-Navigator, and select New. In the New Gallery frame, select Web Tier>JavaServer Pages in the Categories, and select JSP Page in the Items listed. In the Create JSP frame, specify a file name and a directory name for the JSP. The JSP will be added to the View project. We want this new JSP to invoke the getAppServer() business method of the session EJB in the Model project. Although this is not sound MVC practice, the purpose of this tutorial is to explore features of the IDE, not to write excellent code! The J2EE library is required in the classpath of the View project.

Figure 11
Figure 11. weblogic.jsp in the Applications Navigator

Select Tools>Project Properties to add the J2EE library to the View project. In the Project Properties frame, select Profiles>Development>Libraries in the Categories listed. Transfer the J2EE library from the Available Libraries frame to the Selected Libraries frame. The J2EE library has the javax.ejb package Enterprise JavaBeans classes and interfaces.

Figure 12
Figure 12. J2EE Library

In the client JSP obtain a SessionEJBLocalHome object from the session EJB JNDI. From the SessionEJBLocalHome object create a SessionEJBLocal object and invoke the getAppServer() method:


InitialContext ctx=new InitialContext(); 
Object objref =  ic.lookup("SessionEJB");
 model.SessionEJBLocalHome
sessionEJBHome=(model.SessionEJBLocalHome)objref;
model.SessionEJBLocal sessionEJB=sessionEJBHome.create();
out.println(sessionEJB.getAppServer());

The weblogic.jsp client JSP for the session EJB is illustrated below.

Figure 13
Figure 13. weblogic.jsp

We have created a session EJB and a JSP for the session EJB. Next, create an EJB JAR file for the session EJB. Right-click on the Model project node in the Applications-Navigator, and select General>Deployment Profiles in the Categories listed. Select EJB JAR File in the Items listed. Click on the OK button.

Figure 14
Figure 14. New EJB JAR file

In the Create Deployment Profile frame, select the default deployment profile name and directory, and click on the OK button. In the EJB Jar Deployment Profile Properties frame, select the default specified values for the EJB JAR File, enterprise application name, ejb1, and click on the OK button.

Figure 15
Figure 15. EJB JAR Deployment Profile Properties

A deployment profile for the session EJB will be added to the Model project.

Figure 16
Figure 16. EJB Deployment Profile

Next, create a WAR file for the JSP. Right-click on the View project node, and select New. In the New Gallery frame, select General>Deployment Profiles in the Categories listed and WAR File in the Items listed. Click on the OK button. In the Create Deployment Profile frame, specify a deployment profile name and a directory name (or select the default values), and click on the OK button. A deployment profile for the JSP will be added to the View project.

Figure 17
Figure 17. Web Application Deployment Profile

Set the J2EE Web Context root for the Web application in the Project Properties. Select Tools>Project Properties. In the Project Properties frame, select the Common>J2EE node. Specify the context root in the J2EE Web Context Root field. For the example Web application, specify the context root as weblogic-context-root. Next, specify a dependency between the Model project and the View project. Right-click on the View project node, and select New. In the New Gallery frame, select the Common>Dependencies node. Select the EJB JAR deployment profile in the Model project, and click on the OK button.

Figure 18
Figure 18. Project dependencies

Next, create the application deployment profile for the Model-View application. Right-click on the View project node, and select New. In the New Gallery frame, select General>Deployment Profiles in the Categories listed, and select EAR File in the Items listed. Click on the OK button. In the Create Deployment Profile frame, specify a deployment profile name and directory (or select the default values), and click on the OK button. In the EAR Deployment Profile Properties frame, select the Application Assembly node. Select the Web application J2EE module and the EJB application module. Click on the OK button.

Figure 19
Figure 19. EAR Deployment Profile Properties

The application deployment profile node will be added to the Applications-Navigator. Next, deploy the J2EE application to WebLogic Server which has already started. Right-click on the application deployment profile node, and select Deploy to>AppServerConnection1. AppServerConnection1 is the connection to the WebLogic Server.

Figure 20
Figure 20. Deploying to WebLogic Server

The J2EE application will be deployed on WebLogic Server. Access the WebLogic Server administration console with the URL: //localhost:7001/console. The J2EE application is listed in the Deployments>Applications node.

Figure 21
Figure 21. Application deployed in WebLogic Server

Next, run the client JSP for the session EJB in WebLogic Server with the URL //localhost::7001/weblogic-context-root/weblogic.jsp. The getAppServer() method of the session EJB will be invoked in the JSP, and the String value returned by the method will be output to the browser.

Figure 22
Figure 22. Run JSP in WebLogic Server