Skip to Content

Introduction

The HTTP Protocol has a concept of conditional requests.

HTTP conditional requests are requests that are executed differently, depending on the value of specific headers like If-Match

If-Match can be used to prevent the modification of a resource without overriding another change that has been done since the original resource was fetched. If the request cannot be fulfilled, the 412(Precondition Failed) response is returned.

 

How to achieve conditional update via OData V2 adapter in CPI?

OData V2 adapter in CPI allows propagation of “If-Match” header to the receiver.
The value for the header “If-Match” has to be fetched by READ operation on the resource that is being updated.

 

Simple Update

In CPI, the Update operation can be configured via PUT, MERGE or PATCH.
Assume the below service accepts only conditional Update. i.e., PUT operation requires “If-Match” header in the request.

https://services.odata.org/V2/(S(ifmatch))/OData/OData.svc/

Here we will update the Product with ID=1

The Update payload is as below

<Products>
	<Product>
		<ID>1</ID>
		<Rating>5</Rating>
	</Product>
</Products>

 

Assume the GET of <serviceURL>/Products(ID=1) returns an Etag header that has to be passed in the If-Match header of PUT request.

  1. The Integration Flow is modeled with sequential multicast.
  2. Branch 1 does the GET request
  3. The Etag response header is stored using Write Variable.
  4. Branch 2 will set the “If-Match” header from the global variable from step 3. PUT operation is configured.

1. Content Modifier 1

The update payload is set in this content Modifier.

2. Sequential Multicast: Branch 1
2.1. Content Modifier 2

The value of the key property (ID) is stored from the update payload in exchange property “keyValue”

2.2. Request Reply 1

OData receiver is configured for GET call. ID is set from the exchange property “keyValue”

2.3. Write Variables 1

The response header “Etag” value is stored in global variable “etag”.

3. Sequential Multicast: Branch 2
3.1. Content Modifier 3

If-Match exchange header is created with the value from global variable “etag”.

3.2. Request Reply 2

OData receiver is configured for PUT call. The “If-Match” header set in Content Modifer 3 is passed to receiver endpoint and conditional PUT will be executed.

Update in Batch

  1. The Integration Flow is modeled with sequential multicast.
  2. Branch 1 does the GET request
  3. The Etag response header is stored using Write Variable.
  4. Branch 2 will set the “If-Match” header from the global variable from step 3.
  5. Message mapping maps the update payload to batch payload and sets the “If-Match” header in the batch Payload.

Message Mapping 1
  1. Map the batch payload for the entitySet and its properties.
  2. The headerName will be constant
  3. Click the header value. Create a script file.
  4. Define a function getHeader() to get the header value that is set in Content Modifier 3.
  5. Pass the constant “If-Match” as an argument to get the header value and assign it to headerValue.

 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply