protected String findProxyForUrl(final URI uri) { Object o; try { o = js.invokeFunction("FindProxyForURL", uri.toString(), uri .getHost()); } catch (ScriptException e) { LOGGER.log(Level.WARNING, "Error executing FindProxyForUrl({0}): {1} ", new Object[] { uri, e.getLocalizedMessage() }); return null; } catch (NoSuchMethodException e) { LOGGER.log(Level.WARNING, "FindProxyForUrl not found"); return null; } if (o == null || o instanceof String) return (String) o; LOGGER.log(Level.WARNING, "FindProxyForURL({0}) returned a {1} ", new Object[] { uri, o.getClass() }); return o.toString(); }
protected void init(final Reader pacReader) throws Exception { ScriptEngineManager sem = new ScriptEngineManager(); final ScriptEngine se = sem.getEngineByName("JavaScript"); if (se instanceof Invocable) { js = (Invocable) se; } else { throw new RuntimeException( "Bad script engine is not an instance of Invocable"); } initPacFunctions(se); InputStreamReader isrUtils = new InputStreamReader(getClass() .getResourceAsStream("PacUtils.js")); try { se.eval(isrUtils); } finally { isrUtils.close(); } try { se.eval(pacReader); } catch (ScriptException e) { LOGGER.log(Level.WARNING, "Error sourcing the PAC file: {1} ", e .getLocalizedMessage()); } finally { pacReader.close(); } }
System.out.println("Return value: "+value); } catch (ScriptException e) { System.out.println(e.getLocalizedMessage());
System.out.println("Return value: "+value); } catch (ScriptException e) { System.out.println(e.getLocalizedMessage());
System.out.println("Return value: "+value); } catch (ScriptException e) { System.out.println(e.getLocalizedMessage());
System.out.println("Return value: "+value); } catch (ScriptException e) { System.out.println(e.getLocalizedMessage());
System.out.println("Return value: "+value); } catch (ScriptException e) { System.out.println(e.getLocalizedMessage());
errolog.info(String.format("执行js脚本过程中错误%S", e.getLocalizedMessage())); } catch (NoSuchMethodException e) {