When you create a Web service, you can configure it at design time (in the SAP NetWeaver Developer Studio) to customize the Web service’s behavior at runtime. You configure a Web service at design time by using a set of annotations which SAP provides. You add the annotations manually in the Web service implementation bean. More information: Configuring Web Services at Design Time.
The implementation EJB session bean is exposed as a Web service.
1. In the Project Explorer, choose ejbModule → com.sap.tutorial.javaee, and then open the ConverterBean.java session bean.
2. Update the source code as shown in the sample below.
The code sample below shows the implementation of a class level annotation, which configures basic authentication level of the session bean during the design time.
package com.sap.tutorial.javaee; import java.math.BigDecimal; import javax.ejb.Stateless; import javax.jws.WebService; import com.sap.engine.services.webservices.espbase.configuration.ann.dt.AuthenticationDT; import com.sap.engine.services.webservices.espbase.configuration.ann.dt.AuthenticationEnumsAuthenticationLevel;
@WebService(portName="ConverterBeanPort", targetNamespace="http://sap.com/tutorial/javaee/", serviceName="ConverterService", endpointInterface="com.sap.tutorial.javaee.ConverterLocal") @AuthenticationDT(authenticationLevel = AuthenticationEnumsAuthenticationLevel.BASIC) @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); } } |
3. Save your changes.
The authentication level is set to the Converter Web service.
Deploying the Converter Web Service