Show TOC Start of Content Area

Procedure documentation Exposing the Implementation EJB as a Web Service  Locate the document in its SAP Library structure

Use

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

Prerequisites

Configure your AS Java.

More information: Configuring the Application Server in the Developer Studio

Procedure

       1.      In the Project Explorer, expand the ConverterEJB project, and then choose ejbModule com.sap.tutorial.javaee.

       2.      Right-click ConverterBean.java, and then choose Web Services Create Web Service.

The Web Services wizard appears.

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

This graphic is explained in the accompanying text

       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.

This graphic is explained in the accompanying text

       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.

This graphic is explained in the accompanying text

   11.      Choose Finish.

Result

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:

Syntax

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:

Syntax

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);

     }

}

Next Step

Setting an Authentication Level to the Web Service

 

 

 

End of Content Area