I am trying to start the cometd websocket server as part of my own war, which launches the berth 8.1.12 in the built-in mode. I can run all other web applications this way, but for the case with websocket, I get this error:
java.lang.NullPointerException at org.eclipse.jetty.websocket.WebSocketFactory.upgrade(WebSocketFactory.java:238) at org.eclipse.jetty.websocket.WebSocketFactory.acceptWebSocket(WebSocketFactory.java:396) at org.cometd.websocket.server.WebSocketTransport.handle(WebSocketTransport.java:157) at org.cometd.server.CometdServlet.service(CometdServlet.java:166) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
I read all the other posts, and I think this is different.
I have 2 maven projects, one of which creates a uber jar containing the 8.1.12 berth server using the maven-shades plugin, and the other that includes this first jar as a military overlay. The overlay puts all the berth-server classes at the root of the war, so it can be started using "java -jar my.war". Since Cometd also needs a jetty for web maps, I made it double sure that all the dependencies and banks in the WEB-INF / lib directory are 8.1.12 anyway. Thus, there is only one server and its berth 8.1.12. All other messages / questions are related to a non-transport or non-websocket container or non-http connection, but this is a 100% berth 8.1.12, and webapp works great when deployed with a stand-alone external application 8.1.12 .
Dependencies for uberjar from maven-shades (for built-in home-made war with the pier)
[INFO] com.pgi.pulsar:pulsar-container:jar:1.0-SNAPSHOT [INFO] +- org.eclipse.jetty:jetty-server:jar:8.1.12.v20130726:compile [INFO] | +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile [INFO] | +- org.eclipse.jetty:jetty-continuation:jar:8.1.12.v20130726:compile [INFO] | \- org.eclipse.jetty:jetty-http:jar:8.1.12.v20130726:compile [INFO] | \- org.eclipse.jetty:jetty-io:jar:8.1.12.v20130726:compile [INFO] +- org.eclipse.jetty:jetty-servlet:jar:8.1.12.v20130726:compile [INFO] | \- org.eclipse.jetty:jetty-security:jar:8.1.12.v20130726:compile [INFO] +- org.eclipse.jetty:jetty-webapp:jar:8.1.12.v20130726:compile [INFO] | \- org.eclipse.jetty:jetty-xml:jar:8.1.12.v20130726:compile [INFO] +- org.eclipse.jetty:jetty-servlets:jar:8.1.12.v20130726:compile [INFO] | +- org.eclipse.jetty:jetty-client:jar:8.1.12.v20130726:compile [INFO] | \- org.eclipse.jetty:jetty-util:jar:8.1.12.v20130726:compile [INFO] \- junit:junit:jar:4.8.2:test
Here is the code to launch the built-in pier:
public class Main { public static void main(String[] args) throws Exception { Server server = new Server(); SocketConnector connector = new SocketConnector(); connector.setMaxIdleTime(1000 * 60 * 60); connector.setSoLingerTime(-1); String portValue = System.getProperty("pulsar.port"); int port = (portValue != null ? Integer.parseInt(portValue) : 8080); connector.setPort(port); server.setConnectors(new Connector[]{connector}); WebAppContext context = new WebAppContext(); context.setServer(server); context.setContextPath("/"); ProtectionDomain protectionDomain = Main.class.getProtectionDomain(); URL location = protectionDomain.getCodeSource().getLocation(); context.setWar(location.toExternalForm()); server.setHandler(context); server.start(); System.in.read(); server.stop(); server.join();
Libraries in webapp WEB-INF / libs:
jar tvf target/pulsar-websockets-1.0-SNAPSHOT.war | grep WEB-INF/lib/jetty | cut -b 36-100 WEB-INF/lib/jetty-client-8.1.12.v20130726.jar WEB-INF/lib/jetty-continuation-8.1.12.v20130726.jar WEB-INF/lib/jetty-http-8.1.12.v20130726.jar WEB-INF/lib/jetty-io-8.1.12.v20130726.jar WEB-INF/lib/jetty-jmx-8.1.12.v20130726.jar WEB-INF/lib/jetty-server-8.1.12.v20130726.jar WEB-INF/lib/jetty-util-8.1.12.v20130726.jar WEB-INF/lib/jetty-websocket-8.1.12.v20130726.jar WEB-INF/lib/jetty-xml-8.1.12.v20130726.jar
The problem is that it could be related to the problem of loading classes between berth classes such as HttpConnection (I read the post about HttpConnection-ThreadLocal and osgi) that are shared between webapp and the adjacent berth. These classes are actually located in both places, but I cannot find a way to separate them, since they are needed in both places.
Maybe there is a way for the dock to share the classes loaded by the class using the webapp class loader? At the moment I have run out of ideas and I donβt know what I can try next. What can I do to make this work?