Why do you want to achieve this using custom agent when you can just install Siteminder Apache agent?
Anyway, to implement custom agent on Apache you will first need to know how to implement custom filter/module on Apache which intercepts all HTTP traffic. For this you will need to refer to Apache documentation.
Once you know how to implement custom Apache filters/module you will then need to refer to the customagnet code (JavaTestClient.java) and invoke Policy server for Authentication/Authorization and IsProtected calls.
To be frank, its not worth going through all this trouble and trying to reinvent the wheel when you have a tried and tested Apache Siteminder web agent which you can install and configure in less then 10 minutes