Skip to content

Commit f651a0a

Browse files
committed
LDEV-6100 jakarta compatibility - use reflection for createPageContext
https://luceeserver.atlassian.net/browse/LDEV-6100
1 parent 9b7f04f commit f651a0a

4 files changed

Lines changed: 434 additions & 7 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>org.lucee</groupId>
66
<artifactId>websocket-client-extension</artifactId>
7-
<version>2.3.0.7</version>
7+
<version>2.3.0.8-SNAPSHOT</version>
88
<packaging>pom</packaging>
99
<name>WebSockets Client Extension</name>
1010

-224 KB
Binary file not shown.

source/java/src/org/lucee/extension/function/CreateWebSocketClient.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222

2323
import java.io.File;
24+
import java.io.OutputStream;
25+
import java.lang.reflect.Method;
2426
import java.net.MalformedURLException;
2527
import java.net.URL;
2628
import java.util.ArrayList;
2729
import java.util.List;
28-
29-
import javax.servlet.ServletException;
30+
import java.util.Map;
3031

3132
import lucee.commons.io.res.Resource;
3233
import lucee.loader.engine.CFMLEngine;
@@ -166,7 +167,7 @@ public void onTextMessage(WebSocket websocket, String text) throws Exception {
166167
}
167168
}
168169
super.onTextMessage(websocket, text);
169-
170+
170171
}
171172
catch(Exception e) {
172173
e.printStackTrace();
@@ -279,14 +280,33 @@ private PageContext createPageContext() throws PageException {
279280
File contextRoot;
280281
if(res instanceof File) contextRoot=(File) res;
281282
else contextRoot=new File(res.getAbsolutePath());
282-
283+
284+
// Use reflection to call createPageContext to avoid javax/jakarta Cookie[] signature issues
283285
try {
284-
return engine.createPageContext(contextRoot, url.getHost(), url.getPath(), "", null, null, null, null, null, -1, true);
285-
} catch (ServletException e) {
286+
Method method = findCreatePageContextMethod(engine.getClass());
287+
if (method == null) {
288+
throw new RuntimeException("Could not find createPageContext method on CFMLEngine");
289+
}
290+
return (PageContext) method.invoke(engine, contextRoot, url.getHost(), url.getPath(), "", null, null, null, null, null, -1L, true);
291+
} catch (Exception e) {
286292
throw caster.toPageException(e);
287293
}
288294
}
289295

296+
private static Method createPageContextMethod = null;
297+
298+
private Method findCreatePageContextMethod(Class<?> clazz) {
299+
if (createPageContextMethod != null) return createPageContextMethod;
300+
301+
for (Method m : clazz.getMethods()) {
302+
if ("createPageContext".equals(m.getName()) && m.getParameterCount() == 11) {
303+
createPageContextMethod = m;
304+
return m;
305+
}
306+
}
307+
return null;
308+
}
309+
290310
private void releasePageContext(PageContext pc) throws PageException {
291311
if(pc==null) return;
292312
engine.releasePageContext(pc, true);

0 commit comments

Comments
 (0)