WorkShop n°3 : Logging packets asynchronously
In this workshop, we are going to demonstrate how to build your own plugin to perform an asynchronous operation on each packets going through TcpCatcher. 'Asynchronous' means that the hook is called concurrently to packet delivery and thus may not delay the delivery.
For demonstration purpose, we chose the most typical asynchronous operation : logging all packets detailed into a file.
- Import the TcpCatcher jar (which contains the interface class) into your java project and write a class implementing the CustomHook interface and that may look like this one
Note the your class must not belong to any package in order to be plugged at runtime.
- Start TcpCatcher, check "Apply an automatic transformation to packets" and select your .class file after clicking on the "Choose Class" button.
A message should tell you that the hook has been successfully set up.
Because logging is a read only operation, we can do it asynchronously (ie concurrently to packet delivery) and thus without delaying the communication at all.
Note also that, because the hook is Asynchronous, any modification done here on the packet will be vain.
Let's Check "Asynchronous callback".
Click "Apply settings and start", use TcpCatcher and once you have finished, just close it to trigger the hook shutdown.
You will then get a file like this one (in current TcpCatcher.jar location):
Note that TcpCatcher provides, at hook level, the request HTTP header (field httpHeader), the raw content (field httpContent) and the deflated content (field unzippedContent) in the class TcpCatcherPacket.