Class RhinoBasedPacEvaluator

  • All Implemented Interfaces:
    PacEvaluator

    public class RhinoBasedPacEvaluator
    extends java.lang.Object
    implements PacEvaluator
    Represents a Proxy Auto Config file. This object can be used to evaluate the proxy file to find the proxy for a given url.
    See Also:
    The PAC File
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  RhinoBasedPacEvaluator.EvaluatePacAction
      Helper classs to run remote javascript code (specified by the user as PAC URL) inside a sandbox.
    • Constructor Summary

      Constructors 
      Constructor Description
      RhinoBasedPacEvaluator​(java.net.URL pacUrl)
      Initialize a new object by using the PAC file located at the given URL.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addToCache​(java.net.URL url, java.lang.String proxyResult)
      Adds an entry to the cache
      private java.lang.String getFromCache​(java.net.URL url)
      Gets an entry from the cache
      private java.lang.String getHelperFunctionContents()
      Returns the pac helper functions as a String.
      private java.lang.String getPacContents​(java.net.URL pacUrl)
      Returns the contents of file at pacUrl as a String.
      java.lang.String getProxies​(java.net.URL url)
      Get the proxies for accessing a given URL.
      private java.lang.String getProxiesWithoutCaching​(java.net.URL url)
      Get the proxies for accessing a given URL.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PROPERTY_READ_ACTION

        private static final java.lang.String PROPERTY_READ_ACTION
        See Also:
        Constant Field Values
      • LOG

        private static final Logger LOG
      • pacHelperFunctionContents

        private final java.lang.String pacHelperFunctionContents
      • pacContents

        private final java.lang.String pacContents
      • pacUrl

        private final java.net.URL pacUrl
      • cache

        private final TimedHashMap<java.lang.String,​java.lang.String> cache
    • Constructor Detail

      • RhinoBasedPacEvaluator

        public RhinoBasedPacEvaluator​(java.net.URL pacUrl)
        Initialize a new object by using the PAC file located at the given URL.
        Parameters:
        pacUrl - the url of the PAC file to use
    • Method Detail

      • getProxies

        public java.lang.String getProxies​(java.net.URL url)
        Get the proxies for accessing a given URL. The result is obtained by evaluating the PAC file with the given url (and the host) as input. This method performs caching of the result.
        Specified by:
        getProxies in interface PacEvaluator
        Parameters:
        url - the url for which a proxy is desired
        Returns:
        a list of proxies in a string like
        "PROXY foo.example.com:8080; PROXY bar.example.com:8080; DIRECT"
        See Also:
        getProxiesWithoutCaching(URL)
      • getProxiesWithoutCaching

        private java.lang.String getProxiesWithoutCaching​(java.net.URL url)
        Get the proxies for accessing a given URL. The result is obtained by evaluating the PAC file with the given url (and the host) as input.
        Parameters:
        url - the url for which a proxy is desired
        Returns:
        a list of proxies in a string like
        "PROXY example.com:3128; DIRECT"
        See Also:
        getProxies(URL)
      • getPacContents

        private java.lang.String getPacContents​(java.net.URL pacUrl)
        Returns the contents of file at pacUrl as a String.
      • getHelperFunctionContents

        private java.lang.String getHelperFunctionContents()
        Returns the pac helper functions as a String. The functions are read from net/sourceforge/jnlp/resources/pac-funcs.js
      • getFromCache

        private java.lang.String getFromCache​(java.net.URL url)
        Gets an entry from the cache
      • addToCache

        private void addToCache​(java.net.URL url,
                                java.lang.String proxyResult)
        Adds an entry to the cache