Log all network interactions of Java application

前端 未结 5 705
陌清茗
陌清茗 2020-12-29 22:53

I have a monstrous Java app (a client of little-known application server GNUEnterprise) and its source, which I can compile back after making some changes to it. The app use

5条回答
  •  自闭症患者
    2020-12-29 23:24

    If you want to log network traffic & you have URLConnection objects then the problem is already solved!
    If you want to log at stream level, you need to write a little wrapper on top of your I/O streams & log all data before transfer them to lower network layers, otherwise you can use connection objects directly to get required info & log them.
    For managing cookies, you should use java.net.HttpCookie which is introduced in java 6. Only thing you have to do is to create an instance of CookieManager & set it as default cookie manager:

    CookieManager cookieManager = new CookieManager();
    CookieHandler.setDefault(cookieManager);
    

    & you can use it for managing connection cookies!

提交回复
热议问题