package examples.simple;

import com.vtence.molecule.WebServer;
import com.vtence.molecule.middlewares.Failsafe;

import java.io.IOException;
import java.nio.charset.Charset;

public class SimpleExample {

    public void run(WebServer server) throws IOException {
               // Capture internal server errors and display a 500 page
        server.add(new Failsafe())
               // The warmup block is executed once at startup
              .warmup(app -> System.out.println("Application ready"))
              .start((request, response) -> {
                  // An unsupported charset will cause an exception, which will cause the FailSafe middleware
                  // to render a 500 page
                  Charset encoding = Charset.forName(request.parameter("encoding"));
                  // The specified charset will be used automatically to encode the response
                  response.contentType("text/html; charset=" + encoding.displayName().toLowerCase());

                  response.done("<html>" +
                          "<body>" +
                          "<p>" +
                          "Les naïfs ægithales hâtifs pondant à Noël où il gèle sont sûrs " +
                          "d'être déçus en voyant leurs drôles d'œufs abîmés." +
                          "</p>" +
                          "</body>" +
                          "</html>");
              });
    }


    public static void main(String[] args) throws IOException {
        SimpleExample example = new SimpleExample();
        // Run the default web server
        WebServer webServer = WebServer.create();
        example.run(webServer);
        System.out.println("Access at " + webServer.uri() + "?encoding=utf-8");
    }
}
@@ -169,16 +169,492 @@
 arset;%0A%0A
+/**%0A * %3Cp%3E%0A *     In this example we run a single application that responds to all incoming requests with an HTML page,%0A *     varying the encoding.%0A * %3C/p%3E%0A * %3Cp%3E%0A *     We let the user change the output encoding by specifying the desired charset as a request parameter.%0A * %3C/p%3E%0A * %3Cp%3E%0A *     There's always the chance that we are thrown an encoding we don't support, so we use the failsafe middleware%0A *     to turn internal server errors into a 500 error page.%0A * %3C/p%3E%0A */%0A
 public c
@@ -746,25 +746,43 @@
     
-       // C
+// The failsafe middleware c
 apture
+s
  int
@@ -809,26 +809,101 @@
 and 
-display a 500 page
+renders a default 500 page,%0A        // showing a stack trace of the exception and its causes.
 %0A   
@@ -956,16 +956,25 @@
  // The 
+optional 
 warmup b
@@ -1005,16 +1005,35 @@
  startup
+ as a boot sequence
 %0A       
@@ -1217,24 +1217,32 @@
  which will 
+in turn 
 cause the Fa
@@ -1243,13 +1243,13 @@
 the 
-FailS
+fails
 afe 
@@ -1415,17 +1415,20 @@
 The 
-specified
+content-type
  cha
@@ -1585,16 +1585,104 @@
 se());%0A%0A
+                  // Our HTML page contains characters outside the ISO-8859-1 alphabet.%0A
         
@@ -2423,8 +2423,9 @@
 %0A    %7D%0A%7D
+%0A

Update inline doc for the simple example