Petals-SE-POJO 2.7.0+

Version 1 by Christophe DENEUX
on Mar 10, 2023 13:17.

compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (6)

View Page History
* if a {{public setLogger(Logger logger)}} setter method is defined, the component set its {{Logger instance}} with this method at the initialization of the Service Unit.
* if a {{public void init()}} method is defined, the component invoke it at the initialization of the Service Unit.
* a {{public boolean onExchange(Exchange exchange, Optional<Boolean> currentFlowTracingActivation, AbstractJBIListener jbiLIstener)}} MUST be provided.
* a {{public boolean onAsyncExchange(Exchange subExchange, AsyncContext asyncContext, AbstractJBIListener jbiListener)}} CAN be provided, optionally.
* a {{public boolean onExpiredAsyncJBIMessage(Exchange subExchange, AsyncContext asyncContext, AbstractJBIListener jbiListener)}} CAN be provided, optionally.
}

public boolean onExchange(Exchange exchange, Optional<Boolean> currentFlowTracingActivation, AbstractJBIListener jbiListener)
throws MessagingException {
[...]
{code}

The method {{onExchange(Exchange exchange, Optional<Boolean> currentFlowTracingActivation, AbstractJBIListener jbiListener)}} is invoked when an exchange is received from the component that is addressed to the current POJO endpoint.
The POJO must process the service in that method.
The POJO can invoke any 'sub-service' during its processing by synchronous invocations using the {{jbiListener}} instance.
}

public boolean onExchange(Exchange exchange, Optional<Boolean> currentFlowTracingActivation, AbstractJBIListener jbiListener)
throws MessagingException {
[...]
The method create an asynchronous context, to set the data.
The method can create any 'sub-exchange' and send then asynchronously, with the asynchronous context as parameter.
Then the {{onExchange(Exchange exchange, Optional<Boolean> currentFlowTracingActivation, AbstractJBIListener jbiListener)}} returns {{false}}, as the response or the acknowledgment of the original exchange is not yet ready to be sent back.
Any asynchronous response from the 'sub-exchange' comes back in the {{onAsyncExchange(Exchange subExchange, AsyncContext asyncContext, AbstractJBIListener jbiListener)}} method. During the process of this method, the 'sub-exchange' must be handled according to the MEP, and the returns {{true}} of the method let the CDK send the 'sub-exchange' to the partner.
Once all 'sub-exchanges' are received, the 'original' exchange can be retrieve from the asynchronous context and the response or acknowledgement send back explicitly.
Note that once a {{sendAsync(...)}} has expired, the POJO does not have the ownership of the exchange anymore (because it was sent but never came back) and can't access anything else than the exchangeId and the exchange status! The {{AsyncContext}}, which can be subclassed when needed, is there to store needed information in these situations.

h3. Invoking a service provider from your POJO

A service provider can be invoked from your POJO when processing the incoming request in method {{onExchange(Exchange exchange, Optional<Boolean> currentFlowTracingActivation, AbstractJBIListener jbiListener)}}.

First you should retrieve the service consumer associated to the service provider to invoke as following:
{code:java}
final Consumes consume = jbiListener.getComponent().getServiceUnitManager().getConsumesFromDestination(CONSUMED_ENDPOINT, CONSUMED_SERVICE, CONSUMED_INTERFACE, CONSUMED_OPERATION);
{code}
Next, you can create the exchange as following:
{code:java}
final Exchange subExchange = jbiListener.createExchange(consume, MEPPatternConstants.IN_OUT, currentFlowTracingActivation);
{code}
where {{jbiListener}} and {{currentFlowTracingActivation}} are parameters of method {{onExchange(...)}}.

h3. Accessing placeholders