I took the code from the ZAP documentation and stripped it down so that it only does the following:
1. Start the ZAP proxy in daemon mode on port 8090
3. Stop the ZAP proxy
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class DaemonWaveIntegrationTest {
    private List<String> openUrlViaProxy (Proxy proxy, String apiurl) throws Exception {
        List<String> response = new ArrayList<>();
        URL url = new URL(apiurl);
        HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy);
        uc.connect();
        BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            response.add(inputLine);
        }
        in.close();
        return response;
    }
    private void startZAP () throws Exception {
        // ZAP.main(new String[]{"-daemon"});
        // Thread.sleep(5000);
    }
    private void stopZAP (Proxy proxy) throws Exception {
        // TODO not found a reliable way of doing this inline yet :(
    }
    public void testDaemonWave () throws Exception {
        startZAP();
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8090));
        // Access one page via the proxy
        Thread.sleep(2000);
        stopZAP(proxy);
    }
    public static void main(String[] args) throws Exception {
        DaemonWaveIntegrationTest test = new DaemonWaveIntegrationTest();
        test.testDaemonWave ();
    }
The above works if i manually start the ZAP proxy and have it running on port 8090.Â
What i am missing is the API calls inside the startZAP and stopZAP methods. Can anyone point to any clues here please. Tried to look for some documentation that better explainsÂ
the API calls but could not find it. Will appreciate it.