Bit of background - I’m fooling around with tomcat 8’s built-in websocket
support using POJO ServerEndpoints. Really cool btw… Anyways, I thought
it would be a neat experiment to throw the Lucee jars into the app and try
to access Lucee info from the websocket endpoint.
In general, I’m following this
example: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java?view=markup
I realized I could use the configurator to throw in stuff to the config’s
userproperties, so that seemed a natural place to put this stuff. I just
can’t seem to get it to…work. To the code example:
package websocket;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
import lucee.runtime.PageContext;
import lucee.runtime.exp.PageException;
public class WebSocketBinderConfig extends
ServerEndpointConfig.Configurator {
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request, HandshakeResponse response) {
CFMLEngine engine = CFMLEngineFactory.getInstance();
PageContext pc = engine.getThreadPageContext(); //so far so good
try {
String appname = pc.applicationScope().get(“ApplicationName”); // Throws
NPE - any ideas as to why? I do not get any stack trace info past this
line.
String appname = pc.getConfig().getId(); // for kicks and grins, i tried
to just use the config id instead of the above line, but even just the call
to getConfig() throws a NPE
config.getUserProperties().put(“lcappname”, appname);
} catch (PageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package websocket;
import java.io.IOException;
import javax.websocket.EndpointConfig;
import javax.websocket.OnClose;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint(value="/websocket/{channel-id}",
configurator=WebSocketBinderConfig.class)
public class WebSocketBinder {
public WebSocketBinder() {
}
@OnOpen
public void onSessionStart(Session session, EndpointConfig config) throws
PageException {
session.addMessageHandler(new PongHandler(session,config));
try {
session.getBasicRemote().sendText("welcome aboard!
"+config.getUserProperties().get(“lcappname”));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@OnClose
public void onSessionClose() {
}
}
I’d appreciate any input, thanks!