Skip to content

Commit eeb8a83

Browse files
committed
LDEV-6273 drop static engine/caster/creation cache; remove onTextMessage swallow; handle wss://
1 parent 93349df commit eeb8a83

1 file changed

Lines changed: 23 additions & 26 deletions

File tree

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

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ public static Object call(PageContext pc , String endpoint, Component comp) thro
7474
Cast caster = engine.getCastUtil();
7575
HTTPUtil httpUtil = CFMLEngineFactory.getInstance().getHTTPUtil();
7676

77-
//
78-
String str=engine.getStringUtil().replace(endpoint, "ws://", "http://", true, true);
77+
// LDEV-6273: normalise both ws:// and wss:// so URL parsing accepts the scheme
78+
// for PageContext host/path lookup. The actual WebSocket connect uses the
79+
// original `endpoint` string, not this normalised copy.
80+
String str=engine.getStringUtil().replace(endpoint, "wss://", "https://", true, true);
81+
str=engine.getStringUtil().replace(str, "ws://", "http://", true, true);
7982
URL url;
8083
try {
8184
url = httpUtil.toURL(str);
@@ -107,15 +110,12 @@ class WebSocketAdapterImpl extends WebSocketAdapter {
107110
private static final Collection.Key ON_PONG;
108111

109112

110-
private static CFMLEngine engine;
111-
private static Cast caster;
112-
private static Creation creation;
113-
114113
static {
115-
engine = CFMLEngineFactory.getInstance();
116-
caster = engine.getCastUtil();
117-
creation = engine.getCreationUtil();
118-
114+
// LDEV-6273: resolve per-class-init for the key constants only — do NOT
115+
// cache engine/caster/creation as statics. They'd pin a retired CFMLEngine
116+
// across cfadmin restart and the reading thread would IOB in PageContextUtil.
117+
Cast caster = CFMLEngineFactory.getInstance().getCastUtil();
118+
119119
ON_ERROR = caster.toKey("onError");
120120
ON_MSG = caster.toKey("onMessage");
121121
ON_BINARY_MSG = caster.toKey("onBinaryMessage");
@@ -156,22 +156,16 @@ public void onBinaryMessage(WebSocket websocket, byte[] binary) throws Exception
156156

157157
@Override
158158
public void onTextMessage(WebSocket websocket, String text) throws Exception {
159-
try {
160-
if(has(comp,ON_MSG)) {
161-
PageContext pc=null;
162-
try{
163-
comp.call(pc=createPageContext(), ON_MSG, new Object[]{text});
164-
}
165-
finally {
166-
releasePageContext(pc);
167-
}
159+
if(has(comp,ON_MSG)) {
160+
PageContext pc=null;
161+
try{
162+
comp.call(pc=createPageContext(), ON_MSG, new Object[]{text});
163+
}
164+
finally {
165+
releasePageContext(pc);
168166
}
169-
super.onTextMessage(websocket, text);
170-
171-
}
172-
catch(Exception e) {
173-
e.printStackTrace();
174167
}
168+
super.onTextMessage(websocket, text);
175169
}
176170

177171
@Override
@@ -276,6 +270,9 @@ private void _onError(String type, Throwable cause, Object data) throws Exceptio
276270
}
277271

278272
private PageContext createPageContext() throws PageException {
273+
// LDEV-6273: resolve the live engine per-call. A static cache pinned the
274+
// retired engine past cfadmin restart and blew up at PageContextUtil:196.
275+
CFMLEngine engine = CFMLEngineFactory.getInstance();
279276
Resource res=config.getRootDirectory();
280277
File contextRoot;
281278
if(res instanceof File) contextRoot=(File) res;
@@ -289,7 +286,7 @@ private PageContext createPageContext() throws PageException {
289286
}
290287
return (PageContext) method.invoke(engine, contextRoot, url.getHost(), url.getPath(), "", null, null, null, null, null, -1L, true);
291288
} catch (Exception e) {
292-
throw caster.toPageException(e);
289+
throw engine.getCastUtil().toPageException(e);
293290
}
294291
}
295292

@@ -309,7 +306,7 @@ private Method findCreatePageContextMethod(Class<?> clazz) {
309306

310307
private void releasePageContext(PageContext pc) throws PageException {
311308
if(pc==null) return;
312-
engine.releasePageContext(pc, true);
309+
CFMLEngineFactory.getInstance().releasePageContext(pc, true);
313310
}
314311

315312
private boolean has(Component comp, Key key) {

0 commit comments

Comments
 (0)