// Path: weave/server/src/main/java/org/emergent/plumber/MiscUtil.java
// public class MiscUtil {
// 
//   public static void dumpRequestParameters(GenericServlet servlet, HttpServletRequest req) {
//     for (Enumeration enu = req.getParameterNames(); enu.hasMoreElements();) {
//       String parmName = (String)enu.nextElement();
//       String parmValue = req.getParameter(parmName);
//       servlet.log(String.format("parm : %s = %s", parmName, parmValue));
//     }
//   }
// 
//   public static String toWeaveTimestamp(long millis) {
//     return String.format("%.2f", millis / 1000.0);
//   }
// 
//   public static double toWeaveTimestampDouble(long millis) {
//     return (millis / 10) / 100.0;
//   }
// 
//   public static String readBody(HttpServletRequest req) throws IOException {
//     BufferedReader reader = req.getReader();
//     StringWriter writer = new StringWriter();
//     String line = "";
//     while ((line = reader.readLine()) != null) {
//       writer.write(line);
// //      writer.write("\n");
//     }
//     return writer.toString();
//   }
// 
//   public static boolean isEmpty(String s) {
//     return (s == null || s.trim().length() == 0);
//   }
// 
//   public static void close(InputStream closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(OutputStream closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(Reader closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(Writer closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(Connection closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(Statement closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(ResultSet closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void copy(InputStream is, OutputStream os) throws IOException {
//     byte buf[] = new byte[1024];
//     int letti;
//     while ((letti = is.read(buf)) > 0) {
//       os.write(buf, 0, letti);
//     }
//   }
// }


import org.emergent.plumber.MiscUtil;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;

    if (!(servletRequest instanceof HttpServletRequest)) {
      filterChain.doFilter(servletRequest, servletResponse);
      return;
    }

    PrintStream ds = null;
    try {
      ds = getDumpStream();
      HttpServletRequest httpRequest = (HttpServletRequest)servletRequest;
      HttpServletResponse httpResponse = (HttpServletResponse)servletResponse;

      if (m_dumpRequest) {
        ServletUtil.doFilter2(httpRequest, ds);
        MyRequestWrapper bufferedRequest = new MyRequestWrapper(httpRequest);
        httpRequest = bufferedRequest;
        String body = bufferedRequest.getBody();
        ds.println("REQUEST -> " + body);
      }

      if (m_dumpResponse) {
        MyResponseWrapper wrappedResp = new MyResponseWrapper(httpResponse);
        filterChain.doFilter(httpRequest, wrappedResp);
        String body = wrappedResp.getBody();
        ds.println("RESPONSE -> " + body);
      } else {
        filterChain.doFilter(httpRequest, httpResponse);
      }
    } finally {
      if (m_dumpFile != null) {
// Path: weave/server/src/main/java/org/emergent/plumber/MiscUtil.java
// public class MiscUtil {
// 
//   public static void dumpRequestParameters(GenericServlet servlet, HttpServletRequest req) {
//     for (Enumeration enu = req.getParameterNames(); enu.hasMoreElements();) {
//       String parmName = (String)enu.nextElement();
//       String parmValue = req.getParameter(parmName);
//       servlet.log(String.format("parm : %s = %s", parmName, parmValue));
//     }
//   }
// 
//   public static String toWeaveTimestamp(long millis) {
//     return String.format("%.2f", millis / 1000.0);
//   }
// 
//   public static double toWeaveTimestampDouble(long millis) {
//     return (millis / 10) / 100.0;
//   }
// 
//   public static String readBody(HttpServletRequest req) throws IOException {
//     BufferedReader reader = req.getReader();
//     StringWriter writer = new StringWriter();
//     String line = "";
//     while ((line = reader.readLine()) != null) {
//       writer.write(line);
// //      writer.write("\n");
//     }
//     return writer.toString();
//   }
// 
//   public static boolean isEmpty(String s) {
//     return (s == null || s.trim().length() == 0);
//   }
// 
//   public static void close(InputStream closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(OutputStream closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(Reader closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(Writer closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(Connection closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(Statement closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void close(ResultSet closeable) {
//     if (closeable != null) try {
//       closeable.close();
//     } catch (Exception ignored) {
//     }
//   }
// 
//   public static void copy(InputStream is, OutputStream os) throws IOException {
//     byte buf[] = new byte[1024];
//     int letti;
//     while ((letti = is.read(buf)) > 0) {
//       os.write(buf, 0, letti);
//     }
//   }
// }


// Path: weave/server/src/main/java/org/emergent/plumber/util/DumpFilter.java
import org.emergent.plumber.MiscUtil;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;


    if (!(servletRequest instanceof HttpServletRequest)) {
      filterChain.doFilter(servletRequest, servletResponse);
      return;
    }

    PrintStream ds = null;
    try {
      ds = getDumpStream();
      HttpServletRequest httpRequest = (HttpServletRequest)servletRequest;
      HttpServletResponse httpResponse = (HttpServletResponse)servletResponse;

      if (m_dumpRequest) {
        ServletUtil.doFilter2(httpRequest, ds);
        MyRequestWrapper bufferedRequest = new MyRequestWrapper(httpRequest);
        httpRequest = bufferedRequest;
        String body = bufferedRequest.getBody();
        ds.println("REQUEST -> " + body);
      }

      if (m_dumpResponse) {
        MyResponseWrapper wrappedResp = new MyResponseWrapper(httpResponse);
        filterChain.doFilter(httpRequest, wrappedResp);
        String body = wrappedResp.getBody();
        ds.println("RESPONSE -> " + body);
      } else {
        filterChain.doFilter(httpRequest, httpResponse);
      }
    } finally {
      if (m_dumpFile != null) {
        MiscUtil.close(ds);