quetwo / railoWebSocketServer

WebSocket engine for the Railo CFML engine. Tunnels connections over existing HTTP, so you don't need to open additional firewall or application ports.
14 stars 3 forks source link

websocket handshake not successful #3

Closed sfeldkamp closed 8 years ago

sfeldkamp commented 8 years ago

Environment details: Lucee 4.5.1.022 Tomcat 8.0.24.0 JVM 1.7.0_79-b14 OS: Linux

When trying to connect to my server I get the following error returned to the browser (as output by Chrome Devtools). Yes, 8001 is the port that my Lucee installation is configured to serve from and I am able to successfully browse the site on that port.

WebSocket connection to 'ws://local.lucee.sitevision.com:8001/wsEndpoint/sethtest/' failed: Error during WebSocket handshake: Unexpected response code: 404

This error is written into the exception.log from that request.

"ERROR","http-nio-8001-exec-8","11/05/2015","20:11:44","",";Page /wsEndpoint/sethtest/index.cfm [/sites/svsn-sandbox-lucee/web/wsEndpoint/sethtest/index.cfm] not found;Page /wsEndpoint/sethtest/index.cfm [/sites/svsn-sandbox-lucee/web/wsEndpoint/sethtest/index.cfm] not found
    at lucee.runtime.PageSourceImpl.loadPage(PageSourceImpl.java:915):915
    at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:946):946
    at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:56):56
    at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:36):36
    at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2257):2257
    at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2224):2224
    at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:456):456
    at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:47):47
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729):729
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291):291
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52):52
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239):239
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219):219
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106):106
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502):502
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142):142
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79):79
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88):88
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518):518
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091):1091
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668):668
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527):1527
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484):1484
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142):1142
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617):617
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61):61
    at java.lang.Thread.run(Thread.java:745):745
"

It appears that Tomcat is trying to serve the page index.cfm in my channel, which of course does not exist. Maybe the request is not being intercepted properly by the servlet engine? I have added the following to the web.xml file in WEB-INF.

<listener>
    <listener-class>com.quetwo.wsRailoEndpoint.wsEndpointLoader</listener-class>
</listener>

This is the same error that is reported if you don't remove the javax.websocket-api-1.0.jar from the wsRailoEndpoint.jar when deploying to Tomcat8, however I have removed that jar. I don't believe I'm getting a conflict on javax.websocket package now.

quetwo commented 8 years ago

It looks like the WebSocket engine (wsRailoEndpoint) isn't getting instantiated. It should grab onto anything that is within /wsEndpoint/, based on the Java annotations compiled into the class.

This leverages the javax.websocket package within Tomcat, so you shouldn't need to load that.

One thing to try is to flip the metadata-complete="true" in the WEB-INF/web.xml file to false. This will force Tomcat to scan the entire project and it should pick up on the annotations to load the library. If that works, then you will need to figure out why the wsEndpointLoader isn't actually executing. If it dosen't, then it is possible that something is causing either the JAR not to be loaded, or it not not being scanned.

sfeldkamp commented 8 years ago

Success! The problem was a mislocation of the code block. I had put it in /WEB-INF/Lucee/lucee-web.xml because my project did not have a /WEB-INF/web.xml (which is optional) and I mistook that file for the missing web.xml file.

We've decided instead to install the at the server level though in {lucee-home}/tomcat/conf/web.xml putting the wsRailoEndpoint.jar file in {lucee-home}/lib. This is working now and I understand that this will cause the interceptor to fire for all sites on this Lucee instance. Is that a bad idea?

quetwo commented 8 years ago

It will take over for all the domains at the /wsEndpoint/* locations, but if that doesn't bother you, then it's not a big deal. I know of one site that does it this way on purpose. The channel watchers on the websocket side will be global however.