0

I'm running a Java server (Jetty, to be specific) on an AWS EC2 instance using WebSocket to connect to a client's browser. When I do this locally (hosting the server on my computer, not AWS), it runs fine. However, when I move the code to an EC2 instance, I get the following error message on the client-side:

WebSocket connection to 'ws://Elastic_IP:8080/?username=name_of_user' failed: Error during WebSocket handshake: Unexpected response code: 500

I made sure that the EC2 instance will accept traffic on port 8080.

On the server-side, I'm getting many java.lang.NoClassDefFoundError when the connection is attempted. I do not get these error when I run it locally. Perhaps there's an issue when I'm compiling on the EC2 instance, however it does compile without error. I'm compiling and running the code using Eclipse locally, but I'm compiling and running the code on EC2 by hand (javac with lots of classpaths). It's likely that I made an error when compiling by hand, but I'm not sure what the error could be.

Any help would be greatly appreciated.

EDIT
After a little trouble-shooting on my own, I realized that JSON.ParseException was the source of issue. After I removed all calls to this class from the server code, the handshake completed and I was able to establish a connection between the server and the client. However, I am now running into the following error when I receive a message from the client:

WARN:MyWebSocketHandler:qtp990368553-16: Unhandled Error (closing connection) 
java.lang.RuntimeException: Cannot call method public void 
MyWebSocketHandler#onMessage(org.eclipse.jetty.websocket.api.Session, java.lang.String) with args:
[org.eclipse.jetty.websocket.common.WebSocketSession, java.lang.String]

It seems that I defined the argument to be org.eclipse.jetty.websocket.api.Session, but during runtime the argument is actually org.eclipse.jetty.websocket.common.WebSocketSession. Any ideas on how this is happening or which one (Session vs WebSocketSession) I should use? The only capability I need is to send strings between the server and the client.

skamazin
  • 757
  • 5
  • 12
  • Could you provide the full stacktrace, so that we can see which class, specifically, the JVM is complaining about? Also, rather than using Eclipse to run your server code locally, could you try running it locally just as you would on the EC2 instance, so that your local environment is closer/more like the one that's on the EC2 instance? – Castaglia Mar 19 '16 at 20:38
  • @Castaglia I fixed the main issue for the handshake (I had to remove an import on the server code, but it does work on the local side with the import), but I'm hitting another road block. I updated the questions to reflect my misfortune. – skamazin Mar 20 '16 at 20:23

1 Answers1

0

I figured out a possible solution to my problem. Through Eclipse, I can Export the Java project to a runnable jar ("packing" the libraries into the jar). Then running it with java -jar <jar_filename> will work on the server and function the same as on the local machine. However, I've notice some performance issues (slow start), so I do not think this is the best solution, however it is a solution.

skamazin
  • 757
  • 5
  • 12