Show TOC

Creating the Enterprise Java BeanLocate this document in the navigation structure

Context

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

Procedure


  1. In the ProjectExplorer , choose the HelloWorldEJB project, and then choose Start of the navigation path File Next navigation step New  Next navigation step Other End of the navigation path.

  2. In the list of wizards, choose Start of the navigation path EJB Next navigation step EJB 3.0 Next navigation step EJB Session Bean 3.0 End of the navigation path, and then choose Next .

  3. In the EJB ClassName field, enter HelloBean .

  4. Make sure that the EJBProject field contains the HelloWorldEJB project.

  5. In the DefaultEJBPackage field, enter com.sap.tutorial.helloworld .

  6. In the Create BusinessInterface 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.

    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 ProjectExplorer , expand the HelloWorldEJB project, and then choose Start of the navigation path ejbModule Next navigation step com.sap.tutorial.helloworld Next navigation step HelloBean.java Next navigation step HelloBean Next navigation step sayHello(String) End of the navigation path.

  9. Right-click sayHello(String) , and then choose EJB Start of the navigation path Methods Next navigation step Add to Local and Remote Interfaces End of the navigation path.

  10. Save your changes.

Results

The HelloBean appears in the HelloWorldEJB project. The sayHello method 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.