Skip to content

Commit

Permalink
register pagecontext with thread
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Dec 20, 2024
1 parent 3e7b495 commit fa3c96f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
27 changes: 21 additions & 6 deletions core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lucee.runtime.Component;
import lucee.runtime.PageContext;
import lucee.runtime.config.Config;
import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.exp.PageException;
import lucee.runtime.op.Caster;
import lucee.runtime.thread.SerializableCookie;
Expand Down Expand Up @@ -85,7 +86,7 @@ public static LSPEndpointFactory getExistingInstance() {
public Component getComponent() throws PageException, ServletException {
// if component was not yet created, create it
if (cfc == null && !stateless) {
cfc = engine.getCreationUtil().createComponentFromName(createPageContext(), cfcPath);
cfc = engine.getCreationUtil().createComponentFromName(createPageContext(false), cfcPath);
}
return cfc;
}
Expand Down Expand Up @@ -200,9 +201,12 @@ private void handleClient(Socket clientSocket) {
}

public String processMessage(String jsonMessage) {
PageContext previousPC = null, pc = null;
try {
log.info("lsp", "Received message: " + jsonMessage);
PageContext pc = createPageContext();
// just in case there is a previous Pagcontext, safe it
previousPC = ThreadLocalPageContext.get();
pc = createPageContext(true);
if (cfc == null || stateless) {
cfc = engine.getCreationUtil().createComponentFromName(pc, cfcPath);
}
Expand All @@ -215,6 +219,9 @@ public String processMessage(String jsonMessage) {
error("lsp", e);
return null;
}
finally {
releasePageContext(pc, previousPC);
}
}

private void error(String type, Exception e) {
Expand All @@ -240,13 +247,21 @@ public static Log getLog(Config config) {
return null;
}

public static PageContext createPageContext() throws ServletException {
public static PageContext createPageContext(boolean register) throws ServletException {
return CFMLEngineFactory.getInstance().createPageContext(new File("."), "localhost", "/", "", SerializableCookie.COOKIES0, null, null, null,
DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, -1, false);
DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, -1, register);
}

public static void releasePageContext(PageContext pc) {
CFMLEngineFactory.getInstance().releasePageContext(pc, true);
/**
* unregister temporary PageContext and register again any PageContext that was already there (just
* in case)
*
* @param pc
* @param previousPC
*/
public static void releasePageContext(PageContext pc, PageContext previousPC) {
if (pc != null) CFMLEngineFactory.getInstance().releasePageContext(pc, true);
if (previousPC != null) CFMLEngineFactory.getInstance().registerThreadPageContext(previousPC);
}

}
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.2.16-SNAPSHOT"/>
<property name="version" value="6.1.2.17-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.2.16-SNAPSHOT</version>
<version>6.1.2.17-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit fa3c96f

Please sign in to comment.