Show TOC

Exposing the Implementation EJB as a Web ServiceLocate this document in the navigation structure

Prerequisites

Configure your AS Java.

More information: Configuring the Application Server in the Developer Studio

Context

You expose the implementation EJB as a Web service by using the Web Services wizard, integrated in the SAP NetWeaver Developer Studio. When you expose the implementation bean, you can use service endpoint interface (SEI) to expose some or all methods of the implementation bean as Web service methods. More information: Service Endpoint Interface .

In this tutorial, you use the local interface of the Enterprise Java Bean as an SEI

Procedure


  1. In the Project Explorer , expand the ConverterEJB project, and then choose Start of the navigation path ejbModule Next navigation step com.sap.tutorial.javaee End of the navigation path.

  2. Right-click ConverterBean.java , and then choose Start of the navigation path Web Services Next navigation step Create Web Service End of the navigation path.

    The Web Services wizard appears.

  3. Move the slider to Developservice position, as shown in the figure below.

  4. Choose Next .

    The Service Endpoint Interface screen opens.

  5. Choose Specify existing interface option, as shown in the figure below.

  6. Choose Browse and then in the Select Service endpoint interface , enter com.sap.tutorial.javaee.ConverterLocal .

  7. From the Matching items area, choose ConverterLocal interface. When this entry is selected, the Web service annotations are generated in the local Java interface.

  8. Choose Next .

  9. On the Web Service customizations step, choose Next .

    The Method Selection screen opens.

  10. On the Method Selection screen, the system displays and exposes all explicitly specified methods. Make sure that the dollarToEuro(BigDecimal dollars) and euroTo Dollar(BigDecimal euros ) methods are selected.

  11. Choose Finish .

Results

The Enterprise Java Bean is exposed as a Web service.

The framework generates the relevant standard Web service annotations in the implementation bean and in the SEI.

The code sample below shows the update of the SEI:

package com.sap.tutorial.javaee;
import javax.ejb.Local;
import java.math.BigDecimal;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(name="ConverterLocal", targetNamespace="http://sap.com/tutorial/javaee/")
@Local
public interface ConverterLocal {
        @WebMethod(operationName="dollarToEuro")
        public BigDecimal dollarToEuro (@WebParam(name="dollars")
        BigDecimal dollars);
        @WebMethod(operationName="euroToDollar")
        public BigDecimal euroToDollar (@WebParam(name="euros")
        BigDecimal euros);
}

         

The code sample below shows the update of the implementation bean:

package com.sap.tutorial.javaee;
import java.math.BigDecimal;
import javax.ejb.Stateless;
import javax.jws.WebService;

@WebService(endpointInterface="com.sap.tutorial.javaee.ConverterLocal", portName="ConverterBeanPort", serviceName="ConverterService", targetNamespace="http://sap.com/tutorial/javaee/")
@Stateless(name="ConverterBean")
public class ConverterBean implements ConverterLocal {
        private BigDecimal dollarRate = new BigDecimal("1.2");
        private BigDecimal euroRate = new BigDecimal("0.83");

        public BigDecimal dollarToEuro(BigDecimal dollars) {
          BigDecimal result = dollars.multiply(euroRate);
          return result.setScale(2, BigDecimal.ROUND_UP);
          }
        public BigDecimal euroToDollar(BigDecimal euros) {
          BigDecimal result = euros.multiply(dollarRate);
          return result.setScale(2, BigDecimal.ROUND_UP);
          }
}