Class JavaxPacScriptParser

java.lang.Object
com.github.markusbernhardt.proxy.selector.pac.JavaxPacScriptParser
All Implemented Interfaces:
PacScriptParser

public class JavaxPacScriptParser extends Object implements PacScriptParser
PAC parser using the Rhino JavaScript engine bundled with Java 1.6
More information about PAC can be found there:
Proxy_auto-config
web-browser-auto-proxy-configuration
  • Field Details

    • SCRIPT_METHODS_OBJECT

      static final String SCRIPT_METHODS_OBJECT
      See Also:
    • SOURCE_NAME

      static final String SOURCE_NAME
    • source

      private final PacScriptSource source
    • engine

      private final delight.rhinosandox.RhinoSandbox engine
  • Constructor Details

  • Method Details

    • setupEngine

      private delight.rhinosandox.RhinoSandbox setupEngine() throws ProxyEvaluationException
      Initializes the JavaScript engine and adds aliases for the functions defined in ScriptMethods.
      Throws:
      ProxyEvaluationException - on error.
    • buildFunctionCallCode

      private String buildFunctionCallCode(String functionName, int args)
      Builds a JavaScript code snippet to call a function that we bind.
      Parameters:
      functionName - of the bound function
      args - of the bound function
      Returns:
      the JS code to invoke the method.
    • getScriptSource

      public PacScriptSource getScriptSource()
      Gets the source of the PAC script used by this parser.
      Specified by:
      getScriptSource in interface PacScriptParser
      Returns:
      a PacScriptSource.
    • evaluate

      public String evaluate(String url, String host) throws ProxyEvaluationException
      Evaluates the given URL and host against the PAC script.
      Specified by:
      evaluate in interface PacScriptParser
      Parameters:
      url - the URL to evaluate.
      host - the host name part of the URL.
      Returns:
      the script result.
      Throws:
      ProxyEvaluationException - on execution error.