public class NbPacScriptEvaluator extends Object implements PacScriptEvaluator
NbPacScriptEvaluatorFactory
.
Features comparison
There are differences between how browsers have implemented the PAC
evaluation functionality. In the following the Apache NetBeans implementation
(this class) is pitched against some of the major browsers.
Behavior | Apache NetBeans |
Chrome61.0.3163.100 |
Firefox56.0.1 |
IE 1111.608.15063.0 |
Edge40.15063.0.0 |
---|---|---|---|---|---|
Entry point functions supported:FindProxyForURL() and FindProxyForURLEx() |
Both are supported. If both exist in the same PAC script then FindProxyForURLEx() is used. |
Only FindProxyForURL() |
Only FindProxyForURL() |
Both. Only one of them may be present. |
Both. Only one of them may be present. |
Security: Sandboxed execution of PAC script | Yes | ??? | ??? | Yes | Yes |
Security: Stripped URL (Value passed in url parameter) |
Yes1 | Yes1 (but strangely not for HTTP, only for HTTPS) |
Yes2 | Yes | Yes |
Extended return value support Netscape spec only allowed:
|
In addition:3
|
??? | In addition:
|
??? | ??? |
Uses result cache | Yes (based on url value) |
Yes | ??? | Yes (based on host value) |
??? |
Support for getClientVersion() | Yes (returns "1.0") |
No | No | Yes (returns "1.0") |
Yes (returns "1.0") |
Use of result cache
when script uses time sensitive functions:weekdayRange() , dateRange() and timeRange()
|
Result cache not used | ??? | ??? | ??? | ??? |
Name lookup timeout4 | Explicit. (see DNS_TIMEOUT_MS ) |
??? | Yes | ??? | ??? |
Support for Date/Time functions with range crossing a boundary5 | Yes | ??? | Yes since v49 |
??? | ??? |
myIpAddress()6 | Pretty good. Uses JNI. (At least far better than text book Java approach which consistently yields incorrect result) | Uses UDP to try to find IP address. Seems to be reliable. | ??? | ??? | ??? |
user-info
and everything after the
host name, however the value passed to the script always ends with a '/'
character.user-info
is not removed.Proxy
object, all return
types must be mapped to Java Proxy types DIRECT
,
HTTP
and SOCKS
, which means some finer grained information
is lost. (but is irrelevant)weekdayRange()
, dateRange()
and
timeRange()
) allow values that crosses a value boundary.
For example timeRange(22,3
) for the range from 10 pm to 3 am, or
dateRange("DEC","MAR"
) for the range from Dec 1st to March 31st.myIpAddress()
(or myIpAddressEx()
) function
at finding the host's correct IP address, in particular on a multi-homed
computer.
Customization
The implementation for
PacHelperMethods
is
found via the global lookup. If you are unhappy with the implementation
of the Helper Functions you can replace with your own.
Constructor and Description |
---|
NbPacScriptEvaluator(String pacSourceCocde) |
Modifier and Type | Method and Description |
---|---|
List<Proxy> |
findProxyForURL(URI uri)
Returns the proxy/proxies appropriate to use for the given URI.
|
String |
getEngineInfo()
Gets relevant information about the engine, typically the name
of the JavaScript engine, version number, etc.
|
String |
getJsEntryFunction()
Gets the entry function to the PAC script which the engine uses.
|
String |
getPacScriptSource()
Gets the JavaScript source code of the PAC script.
|
static ScriptEngine |
newAllowedPacEngine(String allowedEngines,
StringBuilder err) |
boolean |
usesCaching()
Returns if the Evaluator uses result caching or not.
|
public NbPacScriptEvaluator(String pacSourceCocde) throws PacParsingException
PacParsingException
public List<Proxy> findProxyForURL(URI uri) throws PacValidationException
PacScriptEvaluator
The method calls the JavaScript FindProxyForURL(url, host)
function in the PAC script (or alternatively the
FindProxyForURLEx(url, host)
function), parses the result and
returns it as a prioritized list of proxies.
findProxyForURL
in interface PacScriptEvaluator
uri
- URI to get proxies for.PacValidationException
- when the result from the JavaScript function
cannot be interpreted.public boolean usesCaching()
PacScriptEvaluator
PacScriptEvaluator.findProxyForURL(java.net.URI)
will
not result in a call to JavaScript function FindProxyForURL
if the URL has been resolved previously. But the Evaluator cannot use
caching if the PAC Script uses methods which depends on time and the Evaluator
may therefore have decided to turn off result caching.
If an implementation of PacScriptEvaluator
never uses result caching
(because it simply isn't implemented) then this method will always return
false
.
usesCaching
in interface PacScriptEvaluator
public String getJsEntryFunction()
PacScriptEvaluator
getJsEntryFunction
in interface PacScriptEvaluator
public String getEngineInfo()
PacScriptEvaluator
getEngineInfo
in interface PacScriptEvaluator
public String getPacScriptSource()
PacScriptEvaluator
getPacScriptSource
in interface PacScriptEvaluator
public static ScriptEngine newAllowedPacEngine(String allowedEngines, StringBuilder err)