Package com.hsbc.cranker.mucranker
Interface ProxyListener
-
public interface ProxyListenerHooks to intercept, change and observe the proxying of requests from a client to a target and back.Register listeners when constructor the router with the
CrankerRouterBuilder.withProxyListeners(List)method.Note: the default implementation of each method is a no-op operation, so you can just override the events you are interested in.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidonAfterProxyToTargetHeadersSent(ProxyInfo info, io.muserver.Headers headers)This is called if async method which used to send request headers has already called.default voidonAfterTargetToProxyHeadersReceived(ProxyInfo info, int status, io.muserver.Headers headers)This is called if response headers has already received from targetdefault voidonBeforeProxyToTarget(ProxyInfo info, io.muserver.Headers requestHeadersToTarget)This is called before sending a request to the target servicedefault voidonBeforeRespondingToClient(ProxyInfo info)This is called before sending the response to the client.default voidonComplete(ProxyInfo proxyInfo)This is called after a response has been completed.default voidonFailureToAcquireProxySocket(ProxyInfo proxyInfo)This is called if a free socket could not be found for the target in which case:ProxyInfo.bytesReceived()will be 0.ProxyInfo.bytesSent()will be 0.ProxyInfo.connectorInstanceID()will be null.ProxyInfo.serviceAddress()will be null.ProxyInfo.errorIfAny()will be null.default voidonRequestBodyChunkSentToTarget(ProxyInfo info, ByteBuffer chunk)Called when a chunk of request body data is sent to the target This will be called many times if the body has been fragmenteddefault voidonRequestBodySentToTarget(ProxyInfo info)Called when the full request body has been received to the targetdefault voidonResponseBodyChunkReceived(ProxyInfo info)Called when the full response body has been received from the targetdefault voidonResponseBodyChunkReceivedFromTarget(ProxyInfo info, ByteBuffer chunk)Called when a chunk of response body data is received from the target This will be called many times if the body has been fragmented
-
-
-
Method Detail
-
onBeforeProxyToTarget
default void onBeforeProxyToTarget(ProxyInfo info, io.muserver.Headers requestHeadersToTarget) throws javax.ws.rs.WebApplicationException
This is called before sending a request to the target service- Parameters:
info- Info about the request and response. Note that duration, bytes sent and bytes received will contain values as the the current point in time.requestHeadersToTarget- The headers that will be sent to the client. Modify this object in order to change the headers sent to the target server.- Throws:
javax.ws.rs.WebApplicationException- Throw a web application exception to send an error to the client rather than proxying the request.
-
onBeforeRespondingToClient
default void onBeforeRespondingToClient(ProxyInfo info) throws javax.ws.rs.WebApplicationException
This is called before sending the response to the client.
The response info contains the response objects with the HTTP status and headers that will be sent to the client. You are able to change these values at this point in the lifecycle.
- Parameters:
info- Info about the request and response. Note that duration, bytes sent and bytes received will contain values as the the current point in time.- Throws:
javax.ws.rs.WebApplicationException- Throw a web application exception to send an error to the client rather than proxying the response. This allows you reject responses from services that you deem to be invalid.
-
onComplete
default void onComplete(ProxyInfo proxyInfo)
This is called after a response has been completed.Note that this is called even if the response was not completed successfully (for example if a browser was closed before a response was complete). If the proxying was not successful, then
ProxyInfo.errorIfAny()will not be null.- Parameters:
proxyInfo- Information about the response.
-
onFailureToAcquireProxySocket
default void onFailureToAcquireProxySocket(ProxyInfo proxyInfo)
This is called if a free socket could not be found for the target in which case:ProxyInfo.bytesReceived()will be 0.ProxyInfo.bytesSent()will be 0.ProxyInfo.connectorInstanceID()will be null.ProxyInfo.serviceAddress()will be null.ProxyInfo.errorIfAny()will be null.
- Parameters:
proxyInfo- Information about the request.
-
onAfterProxyToTargetHeadersSent
default void onAfterProxyToTargetHeadersSent(ProxyInfo info, io.muserver.Headers headers) throws javax.ws.rs.WebApplicationException
This is called if async method which used to send request headers has already called. Because the operation of send header is async so this callback does not mean headers has sent complete- Parameters:
info- Info about the request and response.headers- The headers that has sent to the target- Throws:
javax.ws.rs.WebApplicationException- Throw a web application exception to send an error to the client rather than proxying the response. At this stage, the header maybe already sent to target but because this exception has been thrown so will stop send or receive data from target
-
onAfterTargetToProxyHeadersReceived
default void onAfterTargetToProxyHeadersReceived(ProxyInfo info, int status, io.muserver.Headers headers) throws javax.ws.rs.WebApplicationException
This is called if response headers has already received from target- Parameters:
info- Info about the request and response.status- Response statusheaders- The headers that has sent to the target- Throws:
javax.ws.rs.WebApplicationException- Throw a web application exception to send an error to the client rather than keep getting data from target.
-
onRequestBodyChunkSentToTarget
default void onRequestBodyChunkSentToTarget(ProxyInfo info, ByteBuffer chunk)
Called when a chunk of request body data is sent to the target This will be called many times if the body has been fragmented- Parameters:
info- Info about the request and response.chunk- Request body data which already been sent to target successfully.
-
onRequestBodySentToTarget
default void onRequestBodySentToTarget(ProxyInfo info)
Called when the full request body has been received to the target- Parameters:
info- Info about the request and response.
-
onResponseBodyChunkReceivedFromTarget
default void onResponseBodyChunkReceivedFromTarget(ProxyInfo info, ByteBuffer chunk)
Called when a chunk of response body data is received from the target This will be called many times if the body has been fragmented- Parameters:
info- Info about the request and response.chunk- Response body data received from the target.
-
onResponseBodyChunkReceived
default void onResponseBodyChunkReceived(ProxyInfo info)
Called when the full response body has been received from the target- Parameters:
info- Info about the request and response. proxying the request.
-
-