// Path: rsimulator-core/src/main/java/com/github/bjuvensjo/rsimulator/core/SimulatorResponse.java
// public interface SimulatorResponse {
// 
//     /**
//      * Returns the properties of a specific test data request and response pair. If the name of the test data request
//      * file for instance is Test1Request.xml, the properties file must be named Test1.properties. For supported
//      * properties, see *PropertiesInterceptor classes.
//      *
//      * @return the properties of a specific test data request and response pair
//      */
//     Optional<Properties> getProperties();
// 
//     /**
//      * Sets the specified properties.
//      *
//      * @param properties the properties to set
//      */
//     void setProperties(Optional<Properties> properties);
// 
//     /**
//      * Returns the test data response.
//      *
//      * @return the test data response
//      */
//     String getResponse();
// 
//     /**
//      * Sets the specified response.
//      *
//      * @param response the response to set
//      */
//     void setResponse(String response);
// 
//     /**
//      * Returns the matching request path.
//      *
//      * @return the matching request path
//      */
//     Path getMatchingRequest();
// 
//     /**
//      * Sets the specified path.
//      *
//      * @param path the path to set
//      */
//     void setMatchingRequest(Path path);
// }
// 
// Path: rsimulator-http/src/main/java/com/github/bjuvensjo/rsimulator/http/config/Constants.java
// public final class Constants {
//     /**
//      * The parameter name that is used to set/unset the use of relative root path.
//      */
//     public static final String USE_ROOT_RELATIVE_PATH = "useRootRelativePath";
//     /**
//      * The parameter name that is used to set the root path.
//      */
//     public static final String ROOT_PATH = "rootPath";
// 
//     public static final String SERVLET_REQUEST = "servletRequest";
//     public static final String SERVLET_RESPONSE = "servletResponse";
//     public static final String VARS = "vars";
// 
//     public static final String DEFAULT_ROOT_PATH = "src/main/resources";
//     public static final String SIMULATOR_RESPONSE = "simulatorResponse";
// 
//     private Constants() {
//     }
// }
// 
// Path: rsimulator-http/src/main/java/com/github/bjuvensjo/rsimulator/http/config/GlobalConfig.java
// public class GlobalConfig {
//     public static String rootPath;
//     public static boolean useRootRelativePath;
// 
//     static {
//         rootPath = System.getProperty(Constants.ROOT_PATH) != null ? System.getProperty(Constants.ROOT_PATH)
//                 : Constants.DEFAULT_ROOT_PATH;
//         useRootRelativePath = System.getProperty(Constants.USE_ROOT_RELATIVE_PATH) != null && "true".equals(System
//                 .getProperty(Constants.USE_ROOT_RELATIVE_PATH));
//     }
// 
//     private GlobalConfig() {
//         // noop
//     }
// }


import com.github.bjuvensjo.rsimulator.core.SimulatorResponse;
import com.github.bjuvensjo.rsimulator.http.config.Constants;
import com.github.bjuvensjo.rsimulator.http.config.GlobalConfig;
import groovy.lang.Binding;
import groovy.util.GroovyScriptEngine;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
            request.setAttribute(Constants.USE_ROOT_RELATIVE_PATH, vars.get(Constants.USE_ROOT_RELATIVE_PATH));
            chain.doFilter(request, response);
            vars.put(Constants.SIMULATOR_RESPONSE, request.getAttribute(Constants.SIMULATOR_RESPONSE));
            applyScript(Scope.LOCAL_RESPONSE, vars);
            applyScript(Scope.GLOBAL_RESPONSE, vars);
        } else {
            chain.doFilter(request, response);
        }
    }

    private boolean shouldApplyFilter(ServletRequest request) {
        String theRootPath = request.getParameter(Constants.ROOT_PATH);
        String theUseRootRelativePath = request.getParameter(Constants.USE_ROOT_RELATIVE_PATH);
        return (theRootPath == null && theUseRootRelativePath == null);
    }

    private void applyScript(Scope type, Map<String, Object> vars) {
        try {
            String root = null;
            String script = null;
            switch (type) {
                case GLOBAL_REQUEST:
                    root = GlobalConfig.rootPath;
                    script = "GlobalServletRequest.groovy";
                    break;
                case GLOBAL_RESPONSE:
                    root = GlobalConfig.rootPath;
                    script = "GlobalServletResponse.groovy";
                    break;
                case LOCAL_RESPONSE:
// Path: rsimulator-core/src/main/java/com/github/bjuvensjo/rsimulator/core/SimulatorResponse.java
// public interface SimulatorResponse {
// 
//     /**
//      * Returns the properties of a specific test data request and response pair. If the name of the test data request
//      * file for instance is Test1Request.xml, the properties file must be named Test1.properties. For supported
//      * properties, see *PropertiesInterceptor classes.
//      *
//      * @return the properties of a specific test data request and response pair
//      */
//     Optional<Properties> getProperties();
// 
//     /**
//      * Sets the specified properties.
//      *
//      * @param properties the properties to set
//      */
//     void setProperties(Optional<Properties> properties);
// 
//     /**
//      * Returns the test data response.
//      *
//      * @return the test data response
//      */
//     String getResponse();
// 
//     /**
//      * Sets the specified response.
//      *
//      * @param response the response to set
//      */
//     void setResponse(String response);
// 
//     /**
//      * Returns the matching request path.
//      *
//      * @return the matching request path
//      */
//     Path getMatchingRequest();
// 
//     /**
//      * Sets the specified path.
//      *
//      * @param path the path to set
//      */
//     void setMatchingRequest(Path path);
// }
// 
// Path: rsimulator-http/src/main/java/com/github/bjuvensjo/rsimulator/http/config/Constants.java
// public final class Constants {
//     /**
//      * The parameter name that is used to set/unset the use of relative root path.
//      */
//     public static final String USE_ROOT_RELATIVE_PATH = "useRootRelativePath";
//     /**
//      * The parameter name that is used to set the root path.
//      */
//     public static final String ROOT_PATH = "rootPath";
// 
//     public static final String SERVLET_REQUEST = "servletRequest";
//     public static final String SERVLET_RESPONSE = "servletResponse";
//     public static final String VARS = "vars";
// 
//     public static final String DEFAULT_ROOT_PATH = "src/main/resources";
//     public static final String SIMULATOR_RESPONSE = "simulatorResponse";
// 
//     private Constants() {
//     }
// }
// 
// Path: rsimulator-http/src/main/java/com/github/bjuvensjo/rsimulator/http/config/GlobalConfig.java
// public class GlobalConfig {
//     public static String rootPath;
//     public static boolean useRootRelativePath;
// 
//     static {
//         rootPath = System.getProperty(Constants.ROOT_PATH) != null ? System.getProperty(Constants.ROOT_PATH)
//                 : Constants.DEFAULT_ROOT_PATH;
//         useRootRelativePath = System.getProperty(Constants.USE_ROOT_RELATIVE_PATH) != null && "true".equals(System
//                 .getProperty(Constants.USE_ROOT_RELATIVE_PATH));
//     }
// 
//     private GlobalConfig() {
//         // noop
//     }
// }


// Path: rsimulator-http/src/main/java/com/github/bjuvensjo/rsimulator/http/ScriptFilter.java
import com.github.bjuvensjo.rsimulator.core.SimulatorResponse;
import com.github.bjuvensjo.rsimulator.http.config.Constants;
import com.github.bjuvensjo.rsimulator.http.config.GlobalConfig;
import groovy.lang.Binding;
import groovy.util.GroovyScriptEngine;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

            request.setAttribute(Constants.USE_ROOT_RELATIVE_PATH, vars.get(Constants.USE_ROOT_RELATIVE_PATH));
            chain.doFilter(request, response);
            vars.put(Constants.SIMULATOR_RESPONSE, request.getAttribute(Constants.SIMULATOR_RESPONSE));
            applyScript(Scope.LOCAL_RESPONSE, vars);
            applyScript(Scope.GLOBAL_RESPONSE, vars);
        } else {
            chain.doFilter(request, response);
        }
    }

    private boolean shouldApplyFilter(ServletRequest request) {
        String theRootPath = request.getParameter(Constants.ROOT_PATH);
        String theUseRootRelativePath = request.getParameter(Constants.USE_ROOT_RELATIVE_PATH);
        return (theRootPath == null && theUseRootRelativePath == null);
    }

    private void applyScript(Scope type, Map<String, Object> vars) {
        try {
            String root = null;
            String script = null;
            switch (type) {
                case GLOBAL_REQUEST:
                    root = GlobalConfig.rootPath;
                    script = "GlobalServletRequest.groovy";
                    break;
                case GLOBAL_RESPONSE:
                    root = GlobalConfig.rootPath;
                    script = "GlobalServletResponse.groovy";
                    break;
                case LOCAL_RESPONSE:
                    SimulatorResponse simulatorResponse = (SimulatorResponse) vars.get(Constants.SIMULATOR_RESPONSE);