@@ -0,0 +1,3707 @@
+package pl.java.scalatech;%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.io.StringWriter;%0Aimport java.nio.charset.Charset;%0A%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport lombok.extern.slf4j.Slf4j;%0A%0A/**%0A * Simulate an event stream URL by retrieving pre-canned data instead of going to live servers.%0A */%0A@Slf4j%0Apublic class MockStreamServlet extends HttpServlet %7B%0A    private static final String HYSTRIX_STREAM = %22/hystrix.stream%22;%0A    private static final long serialVersionUID = 1L;%0A    private static final Logger logger = LoggerFactory.getLogger(MockStreamServlet.class);%0A%0A    public MockStreamServlet() %7B%0A        super();%0A    %7D%0A%0A    /**%0A     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)%0A     */%0A    @Override%0A    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException %7B%0A                       %0A        int delay = 500;%0A        String delayArg = request.getParameter(%22delay%22);%0A        if (delayArg != null) %7B%0A            delay = Integer.parseInt(delayArg);%0A        %7D%0A%0A        int batch = 1;%0A        String batchArg = request.getParameter(%22batch%22);%0A        if (batchArg != null) %7B%0A            batch = Integer.parseInt(batchArg);%0A        %7D%0A%0A        String data = getFileFromPackage(HYSTRIX_STREAM);%0A        String lines%5B%5D = data.split(%22%5Cn%22);%0A%0A        response.setContentType(%22text/event-stream%22);%0A        response.setCharacterEncoding(%22UTF-8%22);%0A%0A        int batchCount = 0;%0A        // loop forever unless the user closes the connection%0A        for (;;) %7B%0A            for (String s : lines) %7B%0A                s = s.trim();%0A                if (s.length() %3E 0) %7B%0A                    try %7B%0A                        response.getWriter().println(s);%0A                        response.getWriter().println(%22%22); // a newline is needed after each line for the events to trigger%0A                        response.getWriter().flush();%0A                        batchCount++;%0A                    %7D catch (Exception e) %7B%0A                        logger.warn(%22Exception writing mock data to output.%22, e);%0A                        // most likely the user closed the connection%0A                        return;%0A                    %7D%0A                    if (batchCount == batch) %7B%0A                 %0A                        try %7B%0A                 %0A                            Thread.sleep(delay);%0A                        %7D catch (InterruptedException e) %7B%0A                            // ignore%0A                        %7D%0A                        // reset%0A                        batchCount = 0;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A    private String getFileFromPackage(String filename) %7B%0A        try %7B                   %0A            InputStream is = this.getClass().getResourceAsStream(filename);%0A            try %7B             %0A                BufferedReader in = new BufferedReader(new InputStreamReader(is, Charset.forName(%22UTF-8%22)));%0A                StringWriter s = new StringWriter();%0A                int c = -1;%0A                while ((c = in.read()) %3E -1) %7B%0A                    s.write(c);%0A                %7D%0A                return s.toString();%0A            %7D finally %7B%0A                is.close();%0A            %7D%0A        %7D catch (Exception e) %7B%0A            throw new RuntimeException(%22Could not find file: %22 + filename, e);%0A        %7D finally %7B%0A        %7D%0A    %7D%0A%7D%0A

Create MockStreamServlet.java