Cortex Call Stack
This section describes how a single authorized request drills down through the Cortex’s architectural layers and then percolates up back through the layers and returns to the client application that made the request.
Version 7.1 of the Cortex API introduces the Helix programming model for designing resources. Helix resources interact with the different layers of the call stack in a less complex manner than legacy resources do. This document is divided into two sections: one for Helix resources, and one for legacy resources.
Helix Resource Call Stack
Overview of Helix Resource Call Stack:
The client application sends a HTTP request (
GET
,PUT
,POST
, orDELETE
) to Cortex.Cortex authenticates the request using the authentication token found in the request header. Once the request is authenticated, the request is passed to the HTTP bridge.
The HTTP Bridge converts the HTTP request into a
ResourceOperation
, which contains the resource being referenced, the HTTP request’s method, and the request’sSubject
.The
ResourceOperation
is then passed to the Kernel. The resource being referenced could becarts
,items
,lineitems
, etc. Supported HTTP request methods areGET
,POST
,PUT
,DELETE
.The
ResourceKernelImpl
receives theResourceOperation
and runs thesubmitOperation
(ResourceOperation
) method to verify that the request’sSubject
is authorized to access the resource.If the subject is verified,
ResourceKernelImpl
loads the resource referenced in theResourceOperation
through theResourceServer
.The
ResourceServer
reads theResourceOperation
's resource and the operation type (GET
,PUT
,POST
,DELETE
) to determine the correct Prototype to run and then executes the prototype.The prototype gets injected with the appropriate repository, the
RequestIdentifier
, and if necessary theResourceEntity
which have been injected as fields into the prototype.The prototype then calls the appropriate method on the repository, based on the type of operation being performed.
The repository performs the necessary requests against the Elastic Path Commerce Engine, and returns the response in an rxJava stream, either as a
Single
,Observable
,Maybe
orCompletable
rxJava stream type.The resource receives the rxJava stream result from the repository, and returns it to the kernel.
The kernel converts the data from the rxJava stream into a JSON object, and sets the Status Code to
200
,401
, etc., depending on the success or failure of the operation.A JSON object is returned back the client with the HTTP status.
Legacy Resource Call Stack
The main difference between Helix programming model resources and legacy resources is in the resource and integration layers.
The client application sends a HTTP request (
GET
,PUT
,POST
, orDELETE
) to Cortex.Cortex authenticates the request using the authentication token found in the request header. Once the request is authenticated, the request is passed to the HTTP bridge.
The HTTP Bridge converts the HTTP request into a
ResourceOperation
, which contains the resource being referenced, the HTTP request’s method, and the request’sSubject
.The
ResourceOperation
is then passed to the Kernel. The resource being referenced could becarts
,items
,lineitems
, etc. Supported HTTP request methods areGET
,POST
,PUT
,DELETE
.The
ResourceKernelImpl
receives theResourceOperation
and runs thesubmitOperation
(ResourceOperation
) method to verify that the request’s Subject is authorized to access the resource.If the subject is verified,
ResourceKernelImpl
loads the resource referenced in theResourceOperation
through theResourceServer
.The
ResourceServer
reads theResourceOperation
's resource and the operation type (GET
,PUT
,POST
,DELETE
) toResourceOperation
to run and then executes theResourceOperation
.The
ResourceOperation
, which encapsulates the Resource URI, the resource, and the operation being applied to the resource, delegates the operation to the resource’s lookup or writer depending on the operation type.If the operation is a
GET
, the resource’s lookup is used. If the operation is aDELETE
or aPOST
, the resource’s writer is used.The resource’s writer or lookup calls a strategy class in the integration layer. The strategy performs a
CRUD
operation that calls into the Elastic Path Core services. (More on this is step 7 below)For a
READ
operation, the strategy returns a Java object and then calls a transformer to convert the Elastic Path Commerce object into a DTO (Data Transfer Object).The DTO is wrapped in an ExecutionResult, a flag is set on the
ExecutionResult
to indicate the call’s success or failure, and then theExecutionResult
is passed to the resource.For a
CREATE
orUPDATE
operation, the GUID of the newly created object or the updated object is put into anExecutionResult
and then passed to the resource.The resource receives the
ExecutionResult
from the Integration layer, takesExecutionResult
's DTO, and uses the resource’s transformer to create a representation of the DTO.The resource then sends the
ExecutionResult
with the representation to the Resource server layer.The Resource server layer wraps the
ExecutionResult
in anOperationResult
and passes theOperationResult
to the kernel.The kernel converts the
Representation
nested in theOperationResult
into a JSON object and sets theOperationResult
's ResourceStatus to200
,401
, etc, depending on the success or failure of the operation.
Process Request by API Platform
The following diagram shows the workflow of the process request by API Platform: