refactor: HttpUtils改为单例INSTANCE
This commit is contained in:
@@ -71,7 +71,7 @@ public class GroovyScriptEngine {
|
|||||||
binding.setVariable("jsoup", new JsoupHelper());
|
binding.setVariable("jsoup", new JsoupHelper());
|
||||||
binding.setVariable("json", objectMapper);
|
binding.setVariable("json", objectMapper);
|
||||||
binding.setVariable("utils", new ScriptUtils());
|
binding.setVariable("utils", new ScriptUtils());
|
||||||
binding.setVariable("http", new HttpUtils());
|
binding.setVariable("http", HttpUtils.INSTANCE);
|
||||||
|
|
||||||
GroovyShell shell = new GroovyShell(classLoader, binding);
|
GroovyShell shell = new GroovyShell(classLoader, binding);
|
||||||
String fullScript = SCRIPT_PREFIX + groovyScript + "\n// PAR 调用入口\nreturn parse(content, url)";
|
String fullScript = SCRIPT_PREFIX + groovyScript + "\n// PAR 调用入口\nreturn parse(content, url)";
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import java.time.Duration;
|
|||||||
*/
|
*/
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
|
public static final HttpUtils INSTANCE = new HttpUtils();
|
||||||
|
|
||||||
private static final HttpClient client = HttpClient.newBuilder()
|
private static final HttpClient client = HttpClient.newBuilder()
|
||||||
.connectTimeout(Duration.ofSeconds(10))
|
.connectTimeout(Duration.ofSeconds(10))
|
||||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||||
|
|||||||
Reference in New Issue
Block a user