Reputation: 311
For WSO2 api manager, what is the difference or relation between handlers and sequence.
I want to put some conditions for each api to follow. Based on condition it will check if api request has passed the condition or not. I am not sure for this if I need to use sequence or handlers.
Upvotes: 2
Views: 1257
Reputation: 751
This answer assumes that by "sequence" the user means "mediation sequence," which are run via the APIManagerExtensionHandler handler (mediation can be global or per-API, but to the best of my knowledge it is executed in the same place).
Both mediation sequences and handlers are code extensions that run after the gateway receives a response or request. Handlers extend the org.apache.synapse.rest.AbstractHandler
class, requiring implementation of AbstractHandler.handleRequest
and AbstractHandler.handleResponse
; mediators extend org.apache.synapse.mediators.AbstractMediator
class and require implementing AbstractMediator.mediate
.
The primary difference between a custom handler and a mediation sequence is that using a custom handler requires you to write your own Java class, then package and deploy your handler. If your requirements can be satisfied with a combination of predefined mediators (provided by WSO2's ESB) then you can write an XML sequence to define the mediation tasks, with no new code needed.
In my experience, here are the primary differences between handlers and mediation sequences. Using one over the other should be determined by your specific requirements.
Handlers
Mediation Sequences
In short: if some combination of existing mediators will achieve your goal, using mediation sequences makes the most sense (even if it's a case of "close, but not quite," writing a custom mediator can be easier than creating an entirely new handler). If you require an increased level of customization or require mediation to occur before or after all other mediation is executed, you should consider writing a handler.
Edit: to actually answer the specific question: you can do logical checks of values in request headers using a mediation sequence fairly easily. These checks become a bit more difficult to do if you need to read body content... in which case a custom handler is essentially your only option.
Upvotes: 5