// 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;
package com.github.bjuvensjo.rsimulator.http;



@WebFilter(urlPatterns = {"/*"})
public class ScriptFilter implements Filter {
    private static final String GROOVY_PATTERN = com.github.bjuvensjo.rsimulator.core.config.Constants.REQUEST + ".*";

    private final Logger log = LoggerFactory.getLogger(ScriptFilter.class);

    @Override
    public void init(FilterConfig filterConfig) {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.debug("doFilter");
        if (shouldApplyFilter(request)) {
            log.debug("ApplyingScripts");
            Map<String, Object> vars = new HashMap<>();
            vars.put(Constants.SERVLET_REQUEST, request);
            vars.put(Constants.SERVLET_RESPONSE, 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;

package com.github.bjuvensjo.rsimulator.http;



@WebFilter(urlPatterns = {"/*"})
public class ScriptFilter implements Filter {
    private static final String GROOVY_PATTERN = com.github.bjuvensjo.rsimulator.core.config.Constants.REQUEST + ".*";

    private final Logger log = LoggerFactory.getLogger(ScriptFilter.class);

    @Override
    public void init(FilterConfig filterConfig) {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.debug("doFilter");
        if (shouldApplyFilter(request)) {
            log.debug("ApplyingScripts");
            Map<String, Object> vars = new HashMap<>();
            vars.put(Constants.SERVLET_REQUEST, request);
            vars.put(Constants.SERVLET_RESPONSE, response);
            vars.put(Constants.ROOT_PATH, GlobalConfig.rootPath);