Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package spark.debug;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.lang3.exception.ExceptionUtils;
import freemarker.template.Configuration;
import freemarker.template.Version;
import spark.ExceptionHandler;
import spark.Request;
import spark.Response;
import spark.Spark;
import spark.template.freemarker.FreeMarkerEngine;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import static spark.Spark.exception;
public class DebugScreen implements ExceptionHandler {
protected final FreeMarkerEngine templateEngine;
protected final Configuration templateConfig;
protected final SourceLocator[] sourceLocators;
public DebugScreen() {
this(
new FileSearchSourceLocator("./src/main/java"),
new FileSearchSourceLocator("./src/test/java")
);
}
public DebugScreen(SourceLocator... sourceLocators) {
templateEngine = new FreeMarkerEngine();
templateConfig = new Configuration(new Version(2, 3, 23));
templateConfig.setClassForTemplateLoading(getClass(), "/");
templateEngine.setConfiguration(templateConfig);
this.sourceLocators = sourceLocators;
}
/**
* Enables the debug screen to catch any exception (Exception.class)
* using the default source locators (src/main/java and src/test/java)
*/
public static void enableDebugScreen() {
exception(Exception.class, new DebugScreen());
}
/**
* Enables the debug screen to catch any exception (Exception.class)
* using user defined source locators
*
* @param sourceLocators locators to use to find source files
*/
public static void enableDebugScreen(SourceLocator... sourceLocators) {
exception(Exception.class, new DebugScreen(sourceLocators));
}
@Override
public final void handle(Exception exception, Request request, Response response) {
handleThrowable(exception, request, response);
}
public final void handleThrowable(Throwable throwable, Request request, Response response) {
response.status(500); // Internal Server Error
// Find the original causing throwable; this will contain the most relevant information to
// display to the user.
while (throwable.getCause() != null) {
throwable = throwable.getCause();
}
try {
List