Show TOC

Consuming Idempotent Web ServicesLocate this document in the navigation structure

Use

When you invoke an idempotent operation of a Web service, the client runtime performs a SOAP request. Before sending the idempotent operation request to the Web service, the Web service client applies a unique ID to the request. At a later stage, if the provider system does not delegate a successful response, the consumer system re-sends the request automatically. The retransmission continues until the Web service client receives a successful response, a Web services related error (for example SOAPFault ), or until the number of retries expires. Each SOAP request is sent only if the previous request failed. A failure of the communication may occur due to network connection issues, for example, a socket read timeout exception, or if the service is not available at all. Otherwise, the relevant result is delegated to the consumer application. If the last request fails, a fault message is delegated to the consumer application.

To improve performance, the provider system saves the result of a Web service operation that is requested by the consumer with a specific ID. At a later stage, if the same request is received, the provider returns the result that is already executed and saved on the system.

After you deploy the consumer, you configure idempotency settings in SAP NetWeaver Administrator on the Idempotency area of the Web service client settings. The Idempotency area in SAP NetWeaver Administrator appears only for Web service clients that are created for idempotency-enabled Web services.

More information: Configuring Individual Web Service Clients

This procedure enables you to configure runtime idempotency settings during the design time of the Web service client.

Note
  • You can enable and configure idempotency only for Web service clients that consume idempotent operations of Web services.

  • Only ABAP provider systems support idempotent requests.

  • You cannot configure idempotency and Web service reliable messaging (WS-RM) for the same Web service client.

Procedure
  1. Generate a Web service proxy. More information: Creating Web Service Proxies .

  2. Create a client application. More information: Creating Web Service Client Applications .

  3. Configure specific idempotent settings for the consumer using the application program interfaces below:

    • IdempotencyManagementFactory

      • Factory class name

        com.sap.engine.services.webservices.espbase.client.api.IdempotencyManagementFactory

      • Factory methods

        IdempotencyManagementInterface getInterface(Object port)

        This method creates an instance of the idempotency management interface c om.sap.engine.services.webservices.espbase.client.api.IdempotencyManagementInterface for the required port.

    • IdempotencyManagementInterface

      • Interface class name

        com.sap.engine.services.webservices.espbase.client.api.IdempotencyManagementInterface

      • Interface methods

        • void activateGlobalIdeopotency(boolean activate)

          This method activates or deactivates idempotency support for the corresponding port. The idempotency support is activated by default. If the value of activate is true and only if this operation is marked as idempotent in the WSDL document, the runtime treats the operation as idempotent. If the value of activate is false , then no operation is treated as idempotent.

        • boolean isGlobalIdeopotencyActive()

          This method determines whether idempotency support is activated for the corresponding port.

        • void setRetrySleep(long sleep)

          This method specifies an interval (in milliseconds) after each request to the Web service. The default value is 30 seconds.

        • long getRetrySleep()

          This method gets the interval (in milliseconds) after each request to the Web service.

        • void setRetriesCount(int count)

          This method specifies the maximum number of requests to the Web service. The default value is 5.

        • int getRetriesCount()

          This method gets the maximum number of requests to the Web service.

Example

package com.sap.test;

import java.io.IOException;

import java.io.OutputStream;

import java.io.PrintWriter;

import java.io.StringWriter;

import java.io.Writer;

import java.math.BigInteger;

import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.xml.ws.WebServiceRef;

import types_ns.IdempotencyOperationTypeType;

import types_ns.RegularOperationTypeType;

import com.sap.engine.services.webservices.espbase.client.api.HTTPControlFactory;

import com.sap.engine.services.webservices.espbase.client.api.HTTPControlInterface;

import com.sap.engine.services.webservices.espbase.client.api.IdempotencyManagementFactory;

import com.sap.engine.services.webservices.espbase.client.api.IdempotencyManagementInterface;

import def_ns.IdempotencyTest;

import def_ns.IdempotencyTestService;

/**

* Servlet implementation class for Servlet: ConsumerServlet *

*

*/

public class ConsumerServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

static final long serialVersionUID = 1L;

@WebServiceRef(name="IdempotencyTestService") IdempotencyTestService service;

public ConsumerServlet() {

super();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String host = request.getParameter("host");

String httpPort = request.getParameter("port");

response.setContentType("text/html"); IdempotencyTest port = service.getIdempotencyTestBindingPort();

HTTPControlInterface httpControl = HTTPControlFactory.getInterface(port);

httpControl.setEndpointURL("http://" + host + ":" + httpPort + "/IdempotencyTestService/IdempotencyTestImplBean");

OutputStream responseOutputStream = response.getOutputStream();

httpControl.startLogging(responseOutputStream, responseOutputStream);

IdempotencyManagementInterface idempotencyManagement = IdempotencyManagementFactory.getInterface(port);

log(responseOutputStream, "Default Idempotency activation status: " + idempotencyManagement.isGlobalIdeopotencyActive());

idempotencyManagement.activateGlobalIdeopotency(false);

log(responseOutputStream, "After disabling it, Idempotency activation status is: " + idempotencyManagement.isGlobalIdeopotencyActive());

idempotencyManagement.activateGlobalIdeopotency(true);

log(responseOutputStream, "After enabling it, Idempotency activation status is: " + idempotencyManagement.isGlobalIdeopotencyActive());

log(responseOutputStream, "Default Idempotency retries count: " + idempotencyManagement.getRetriesCount());

idempotencyManagement.setRetriesCount(3);

log(responseOutputStream, "After changing it, Idempotency retries count is: " + idempotencyManagement.getRetriesCount());

RegularOperationTypeType regularOperationIn = new RegularOperationTypeType();

regularOperationIn.setParam("value");

log(responseOutputStream, "Initiating Regular call");

port.regularOperation(regularOperationIn);

log(responseOutputStream, "Idempotency test passed successfully");

}

}