miércoles, 8 de octubre de 2014

... message composers in SwitchYard

Message composition

It is the process of converting the Message from the binding format (HTTP request, SOAP envelope, JMS message, File, …​) to a SwitchYard message, and mapping the context information from the binding format (HTTP headers, SOAP headers, JMS headers, …​) to the SwitchYard Context, and from the Switchyard internal format (message and context) back again into the binding format.

Message Composition Explained with an example

Here we will find a description of what is happening at the message composition time in a call to a SwitchYard application through an HTTP binding and having one call to an external reference through an HTTP binding.

(1) Request message from binding to service

The request message is converted from the binding message type to the internal service type. For this to happen, a call toHttpMessageComposer.compose().
In this method two things will happen:
  • It will create a Message for the Exchange.
  • A call to HttpContextMapper.mapFrom(HttpRequestBindingData, context) will be done. This method will:
    • It will copy requestInfo from the HTTPRequestBindingData into the message Context with keyHttpComposition.HTTP_REQUEST_INFO and assigning the following labels, ComponentLabel.HTTP andEndpointLabel.HTTP
HttpRequestInfo has all the required information from the request, and is the source of information that can be used in the SwitchYard’s component implementations to access information relative to the request, such as requestURI, requestPath, method, contextPath,…​ See the implementation of this class to find all the available information.
  • It will copy all headers from the HTTP request that match the defined includes and exludes regex pattern for the composer at design time.
Headers are not automatically copied, you have to add to messageComposer which headers you want to include (.*: all)

When checking for headers, or defining headers in Binding’s RegEx Inclusion and Exclusion, all headers arelowercased. If you send a header Authorization, you should check for authorization instead.
  • It will copy the content from the HttpBindingData to the Message that will flow through SwitchYard converting it to the appropiate type.
  • It will return the Message.

(2) Service component implementations execution

The request pipelines of a component will be executed, until a there is a call to an external HTTP service.

(3) Request message from reference to binding

A call to the external service is about to happen, and message needs to be converted from SwitchYard message to the reference binding data.
  • A call to HttpMessageComposer.decompose(Exchange, HttpRequestBindingData) will be done. This method will:
    • Copies the content from the Exchange to the content HttpRequestBindingData
    • Calls HttpContextMapper.mapTo(Request) to copy headers from the Message`s Context to the HttpRequestBindingData’s http headers. These properties will be copied only if they match the registered regexp expressions in the MessageComposer’s design time configuration or if the properties are marked with the EndpointLabel.HTTP label in the Context.

(4) Response message from binding to reference

Once the external service has being executed, we have to deal with the response from this external service, and map it back into SwitchYard. To to this, a call to *HttpMessageComposer.compose(HttpResponseBindingData, Exchange) will be done. This method will:
  • Create a Message
  • Call HttpContextMapper.mapFrom(HttpResponseBindingData, Message) that will:
    • Copies the statusCode of the invocation into a Context property calledHttpContextMapper.HTTP_RESPONSE_STATUS with labels http (ComponentLabel.HTTP and EnpointLabel.HTTP)
    • It will copy all headers from the HTTP response that match the defined includes and exludes regex pattern for the composer at design time.
Headers are not automatically copied, you have to add to messageComposer which headers you want to include (.*: all)
  • It will copy the content from the HttpBindingData to the Message that will flow through SwitchYard converting it to the appropiate type.
  • It will return the Message.

(5) Service execution

The rest of the components` pipeline will be executed.

(6) Response message from service to binding

When our application has ended it’s execution and it is returning the result to the caller, it will call againHttpMessageComposer.decompose(Exchange, HttpResponseBindingData) to convert the SwitchYard message to the binding message or content. It will: * Get statusCode from Context propertyHttpContextMapper.HTTP_RESPONSE_STATUS that has been established as part of the SwitchYard service execution.
This property could be the one that was set from the invocation to the external Composite’s Reference. (In step 4)
  • If there is no statusCode set as a property, or this statusCode property does not have the EndpointLabel.HTTP label, it will calculate one depending on the content and on the Exchange.getState. If the state of the Exchange isExchangeState.FAULT it will return an HTTP Error code of 500. (See the code for the logic determining the statusCode)
    • Copy the content from the SwitchYard’s Message to the HttpResponseBindingData
    • Call HttpContextMapper.mapTo(HttpResponseBindingData) that will:
      • Copy headers from the Message`s Context to the HttpRequestBindingData’s http headers. These properties will be copied only if they match the registered regexp expressions in the MessageComposer’s design time configuration or if the properties are marked with the EndpointLabel.HTTP label in the Context.
      • If the property is HttpContextMapper.HTTP_RESPONSE_STATUS it will set the status on the HttpResponseBindingData

No hay comentarios: