Reputation: 31
We have a requirement to audit a Servlet route.
We have looked at using a Wire Tap which would Post a new HTTP request to a separate audit endpoint.
Our reason for using a Wire Tap is so we don't block the Servlet route.
Our problem is that we need to log the HTTP response from the audit endpoint. Our understanding is that the Wire Tap component is InOnly and therefore will not capture the response.
Our current thought is to push the audit requests to a Queue after the Wiretap. We would then take the requests off the queue and call the auditing endpoint logging the responses.
Is this the best approach or is there a better way?
Could we use "setExchangePattern" to make the Wire Tap InOut? If so would it block the main route?
We have seen there is an OnCompletion handler but are not sure whether that would be of use to us. Again would it block the main route?
Upvotes: 0
Views: 1480
Reputation: 31
We appear to have solved this by pointing the Wire Tap at a direct route which then does the call out to the audit endpoint and logs the response.
This allows us to still pass back the main outgoingEndpoint response while asynchronously logging the audit response.
<from uri="servlet:///incomingendpoint matchOnUriPrefix=true&servletName=IncomingServlet" />
<to ref="outgoingEndpoint" />
<log id="outgoingEndpointLog" message="\nPre Wire Tap Log:[id = ${id}]\n [body = ${body}]\n [headers = ${headers}]\n" ... />
<wireTap uri="direct:tapAuditEndpoint" processorRef="headerProcessor" />
<route id="tapAuditRoute">
<from uri="direct:tapAuditEndpoint"/>
<to uri="auditEndpoint"/>
<log id="auditEndpointLog" message="\nAudit Response Log:[id = ${id}]\n [body = ${body}]\n [headers = ${headers}]\n" ... />
</route>
Upvotes: 1
Reputation: 55545
The wire tap is tapping the current message. So you can use the wire tap at the end of the route which would assume the current message is what would be the response.
For that you can also use on completion which is triggered at the end, though you may use on completion if its more general and apply to more routes etc.
Mind that wire tap is asynchronous and routing the message in a separate thread, then you may have concurrent access to the message from the consumer writing the response, and when you do the audit. If you do not need async you can possible just skip the wire tap and route to the audit directly at the end of the route.
Upvotes: 0