diff --git a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java index 700d1836f2..4109252785 100644 --- a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java +++ b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java @@ -691,7 +691,7 @@ synchronized static void load(ConfigServerImpl cs, ConfigImpl config, ConfigWebI _loadStartupHook(cs, config, root, log); if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(cs == null ? config : cs), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded startup hook"); - if (config instanceof ConfigServer) LSPEndpointFactory.init(config, false); + if (config instanceof ConfigServer) LSPEndpointFactory.getInstance(config, false); } config.setLoadTime(System.currentTimeMillis()); diff --git a/core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java b/core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java index 0faec00179..802866cca3 100644 --- a/core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java +++ b/core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java @@ -1,7 +1,7 @@ package lucee.runtime.lsp; import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -10,9 +10,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import javax.servlet.http.Cookie; +import javax.servlet.ServletException; import lucee.print; +import lucee.commons.io.DevNullOutputStream; import lucee.commons.io.SystemUtil; import lucee.commons.io.log.Log; import lucee.loader.engine.CFMLEngine; @@ -21,10 +22,8 @@ import lucee.runtime.Component; import lucee.runtime.PageContext; import lucee.runtime.config.Config; -import lucee.runtime.config.ConfigServer; -import lucee.runtime.config.ConfigWeb; import lucee.runtime.op.Caster; -import lucee.runtime.thread.ThreadUtil; +import lucee.runtime.thread.SerializableCookie; public class LSPEndpointFactory { private static final int DEFAULT_LSP_PORT = 2089; // Common LSP port @@ -48,11 +47,11 @@ private LSPEndpointFactory(Config config) { cfcPath = engine.getCastUtil().toString(SystemUtil.getSystemPropOrEnvVar("lucee.lsp.component", null), DEFAULT_COMPONENT); if (Util.isEmpty(cfcPath, true)) cfcPath = DEFAULT_COMPONENT; - log.debug("lsp", "LSP server port: " + port); - log.debug("lsp", "LSP server component endpoint: " + cfcPath); + log.info("lsp", "LSP server port: " + port); + log.info("lsp", "LSP server component endpoint: " + cfcPath); } - public static LSPEndpointFactory init(Config config, boolean forceRestart) throws IOException { + public static LSPEndpointFactory getInstance(Config config, boolean forceRestart) throws IOException { if (Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.lsp.enabled", null), false)) { print.e("---- LSPEndpointFactory ----"); synchronized (SystemUtil.createToken("LSPEndpointFactory", "init")) { @@ -75,8 +74,12 @@ public static LSPEndpointFactory init(Config config, boolean forceRestart) throw return instance; } + public static LSPEndpointFactory getExistingInstance() { + return instance; + } + private LSPEndpointFactory start() throws IOException { - log.debug("lsp", "starting LSP server"); + log.info("lsp", "starting LSP server"); try { serverSocket = new ServerSocket(port); } @@ -104,7 +107,7 @@ private LSPEndpointFactory start() throws IOException { listenerThread.setDaemon(true); listenerThread.start(); - log.debug("lsp", "LSP server started"); + log.info("lsp", "LSP server started"); return this; } @@ -118,13 +121,9 @@ private void stop() throws IOException { } } - public static LSPEndpointFactory getInstance(Config config) { - return instance; - } - private void handleClient(Socket clientSocket) { - log.debug("lsp", "LSP server handle client"); + log.info("lsp", "LSP server handle client"); try { // Get input/output streams BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); @@ -188,10 +187,10 @@ private void handleClient(Socket clientSocket) { } } - private String processMessage(String jsonMessage) { + public String processMessage(String jsonMessage) { try { log.info("lsp", "Received message: " + jsonMessage); - PageContext pc = createPageContext((ConfigWeb) engine.getThreadConfig()); + PageContext pc = createPageContext(); Component cfc = engine.getCreationUtil().createComponentFromName(pc, cfcPath); String response = engine.getCastUtil().toString(cfc.call(pc, "execute", new Object[] { jsonMessage })); @@ -214,12 +213,7 @@ private void error(String type, Exception e) { public static Log getLog(Config config) { if (config == null) config = CFMLEngineFactory.getInstance().getThreadConfig(); - if (config instanceof ConfigServer) { - // we only log to config Server if there is no web context - Config cw = CFMLEngineFactory.getInstance().getThreadConfig(); - if (cw != null) config = cw; - } - if (config == null) return null; + try { Log log = config.getLog("lsp"); if (log == null) log = config.getLog(DEFAULT_LOG); @@ -233,8 +227,9 @@ public static Log getLog(Config config) { return null; } - public static PageContext createPageContext(final ConfigWeb cw) { - return ThreadUtil.createPageContext(cw, new ByteArrayOutputStream(), "", "/", "", new Cookie[0], null, null, null, null, true, TIMEOUT); + public static PageContext createPageContext() throws ServletException { + return CFMLEngineFactory.getInstance().createPageContext(new File("."), "localhost", "/", "", SerializableCookie.COOKIES0, null, null, null, + DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, -1, false); } public static void releasePageContext(PageContext pc) { diff --git a/loader/build.xml b/loader/build.xml index e8fd88d97e..76eb2269ae 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 956dd6165e..43cd91c1c5 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.1.2.13-SNAPSHOT + 6.1.2.14-SNAPSHOT jar Lucee Loader Build