Tutorial: Using the Outbound Service

Set up and configure the Outbound Services extensions and a test endpoint to send an outbound Integration Object back to an inbound channel.

Prerequisites

Install the most recent version of SAP Commerce Cloud.

Context

There are options for sending data outbound using the Integration API. To replicate data externally based on a preconfigured schedule, use Outbound Sync, or, if you prefer an event-based approach, use webhooks. However, to send data to an outbound destination based on an SAP Commerce Cloud process or custom logic, use the Outbound Service. The Outbound Service use case requires you to write custom code to integrate with an existing SAP Commerce Cloud process.

The following process provides an example for setting up the communication between the Outbound Service and the OData2 endpoint and verifying that the operation was successful in Backoffice. Step 6 is an example of one way to send Integration Object Items outbound using the Outbound Service.

Procedure

  1. Configure the localextensions.xml file to make the Outbound Service available to SAP Commerce Cloud.
    1. To set up the environment, run the setantenv command from {commerce_installed_dir}/bin/platform.
    2. To prepare SAP Commerce Cloud, run the ant clean command.
    3. Configure the integrationbackoffice extension to manage the Integration Object definition in Backoffice.

      A localextensions.xml file is created in {commerce_installed_dir}/hybris/config.

      <?xml version="1.0" encoding="UTF-8"?>
      <hybrisconfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="resources/schemas/extensions.xsd">
          <extensions>
              <!--
                      All extensions located in ${HYBRIS_BIN_DIR}/platform/ext are automatically loaded.
                      More information about how to configure available extensions can be found here : https://wiki.hybris.com/x/nZVzC
              -->
       
              <path dir="${HYBRIS_BIN_DIR}" />
              <extension name='integrationbackoffice' />
          </extensions>
      </hybrisconfig>
    4. To initialize the platform, run ant initialize from {commerce_installed_dir}/bin/platform.
    5. To start SAP Commerce Cloud, run hybrisserver from {commerce_installed_dir}/bin/platform.
  2. Create an Integration Object with the Category Integration Object Item as the root by sending POST request https://localhost:<sourceSystemPort>/odata2webservices/IntegrationService/InboundChannelConfigurations with the following body:
    {
      "integrationObject": {
        "code": "InboundCategory",
        "items": [
          {
            "code": "Category",
            "root": true,
            "type": {
              "code": "Category"
            },
            "attributes": [
              {
                "attributeName": "code",
                "attributeDescriptor": {
                  "enclosingType": {
                    "code": "Category"
                  },
                  "qualifier": "code"
                },
                "unique": true
              }
            ]
          }
        ]
      },
      "authenticationType": {
        "code": "BASIC"
      }
    } 
  3. Create an instance of a category in the source system to send out later. POST to the Integration Object that was just created for the Category Integration Object Item with an authorized users by ending POST request https://localhost:<sourceSystemPort>/odata2webservices/InboundCategory/Categories with the following payload:
    {    "code": "cat1"} 
  4. Define an Integration Object that has the same root as the Integration Object defined on the source system in the destination system. For example, by sending POST request https://localhost:<destinationSystemUrlPort>/odata2webservices/IntegrationService/InboundChannelConfigurations with the following body:
    {
      "integrationObject": {
        "code": "OutboundCategory",
        "items": [
          {
            "code": "Category",
            "root": true,
            "type": {
              "code": "Category"
            },
            "attributes": [
              {
                "attributeName": "code",
                "attributeDescriptor": {
                  "enclosingType": {
                    "code": "Category"
                  },
                  "qualifier": "code"
                },
                "unique": true
              }
            ]
          }
        ]
      },
      "authenticationType": {
        "code": "BASIC"
      }
    } 
  5. Define the Consumed Destination details on the source system by importing the following ImpEx:
  6. To create an OutboundProduct named "Original Name", use a REST client to POST the following payload to https://localhost:9002/odata2webservices/OutboundProduct/Products:
    Include the following header values in the POST request:
    • Basic Authentication
    • Content-Type: application/json
    • Accept: application/json
    {
        "@odata.context": "$metadata#Product/$entity",
        "code": "test_article",
        "name": "Original Name",
        "catalogVersion": {
            "catalog": {
                "id": "Default"
            },
            "version": "Staged"
        }
    }
  7. Define an InboundChannelConfiguration to expose the OutboundProduct Integration Object with Basic Authentication. For example:
    INSERT_UPDATE InboundChannelConfiguration; integrationObject(code)[unique = true]
                                             ; OutboundProduct
  8. One way to send Integration Object Items outbound is to trigger the Outbound Services OutboundServiceFacade. To do so, you can execute the following script from Start of the navigation pathConsole Next navigation step Scripting LanguagesEnd of the navigation path in the Administration Console.
    import de.hybris.platform.outboundservices.facade.impl.DefaultOutboundServiceFacade
    import de.hybris.platform.core.model.user.CustomerModel
    import de.hybris.platform.core.Registry
    import org.slf4j.Logger
    import org.springframework.http.ResponseEntity
    import de.hybris.platform.integrationservices.util.Log
    import rx.Observable
    
    import java.lang.reflect.Field
    import java.time.LocalDateTime
    
    def LOG = Log.getLogger(DefaultOutboundServiceFacade.class)
    def ctx = Registry.getApplicationContext()
    def outboundServiceFacade = ctx.getBean("outboundServiceFacade")
    def category = modelService.get(new de.hybris.platform.core.PK(8796093055118))
    
    
    //send 1 outbound request
    outboundServiceFacade.send(category, "InboundCategory", "consumedDestination_1").subscribe(
            // onNext
            { responseEntityMap ->
                LOG.info("Successful response with status code: {}", responseEntityMap.getStatusCode())
            }
            ,
            // onError
            { error ->
                LOG.info("Encountered an ERROR with the following message: {}", error.getMessage())
            }
    )
  9. After running the script, log into Backoffice and verify that the product name changed to the name specified in the test.