package pl.labno.bernard.htmlunified; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.util.WebConnectionWrapper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.IOException; public class RequestResponseLogger extends WebConnectionWrapper { private static final Log LOG = LogFactory.getLog(RequestResponseLogger.class); private boolean active = true; public RequestResponseLogger(WebClient webClient) throws IllegalArgumentException { super(webClient); } @Override public WebResponse getResponse(WebRequest request) throws IOException { final WebResponse response = super.getResponse(request); if (active) { LOG.info("request=" + request.getRequestBody() + "\nresponse=" + response.getContentAsString()); } return response; } public void off() { active = false; } public void on() { active = true; } }