Show TOC Start of Content Area

Procedure documentation Creating the Enterprise Java Bean  Locate the document in its SAP Library structure

Use

In the HelloWorldEJB project, you create a session Enterprise Java Bean which provides the business logic of the Web service.

Procedure

       1.      In the Project Explorer, choose the HelloWorldEJB project, and then choose File New Other.

       2.      In the list of wizards, choose EJB EJB 3.0 EJB Session Bean 3.0, and then choose Next.

       3.      In the EJB Class Name field, enter HelloBean.

       4.      Make sure that the EJB Project field contains the HelloWorldEJB project.

       5.      In the Default EJBPackage field, enter com.sap.tutorial.helloworld.

       6.      In the Create Business Interface area, select Remote and Local, and then choose Finish.

The system opens the created EJB session bean for editing.

       7.      Update the source code as shown in the sample below.

The code sample below shows the implementation of a Java class which returns the following string: Hello, <name>. The value of the variable <name> is provided by user input.

Syntax

package com.sap.tutorial.helloworld;

import javax.ejb.Stateless;

 

@Stateless(name="HelloBean")

public class HelloBean implements HelloRemote, HelloLocal {

   private String message = "Hello, ";

   public String sayHello(String name) {

   return message + name + ".";

   }

}

       8.      In the Project Explorer, expand the HelloWorldEJB project, and then choose ejbModule com.sap.tutorial.helloworld HelloBean.java HelloBean sayHello(String).

       9.      Right-click sayHello(String), and then choose EJB Methods Add to Local and Remote Interfaces.

   10.      Save your changes.

Result

The HelloBean appears in the HelloWorldEJB project. The sayHello class is added to the local and remote Java interfaces. At this point, the implementation session bean is ready to be exposed as a Web service.

Next Step

Exposing the Enterprise Java Bean as a Web Service

 

End of Content Area