尝试解析收到的消息时使用jetty websocket的异常

时间:2014-08-28 12:38:46

标签: java websocket

   public void onMessage(String msg) {
      System.out.printf("Got msg: %s%n", msg);
      if(msg.charAt(0)=='a'){
         JsonParserFactory factory=JsonParserFactory.getInstance();
         JSONParser parser=factory.newJsonParser();
         //Map jsonMap=parser.parseJson(msg); uncommenting this line will give the Exception
      }
    }

这是代码,当我取消注释注释行时,我得到了这个异常

    2014-08-28 15:26:17.518:WARN:o.WebSocketConnection:WebSocketClient@497985732-26: Unhandled Error (closing connection)
java.io.IOException: Cannot append to finished buffer
    at org.eclipse.jetty.websocket.common.message.SimpleTextMessage.appendFrame(SimpleTextMessage.java:47)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:60)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextFrame(JettyAnnotatedEventDriver.java:201)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:160)
    at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:302)
    at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:214)
    at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:220)
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:258)
    at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.readParse(AbstractWebSocketConnection.java:613)
    at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:468)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Unknown Source)
Connection closed: 1008 - IOException
2014-08-28 15:26:17.502:WARN:o.WebSocketConnection:WebSocketClient@497982731-29: Unhandled Error (closing connection)
org.eclipse.jetty.websocket.api.WebSocketException: Cannot call method public void oooo.WebSocketConnection#onMessage(java.lang.String) with args: [java.lang.String]
    at org.eclipse.jetty.websocket.common.events.annotated.CallableMethod.call(CallableMethod.java:99)
    at org.eclipse.jetty.websocket.common.events.annotated.OptionalSessionCallableMethod.call(OptionalSessionCallableMethod.java:72)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextMessage(JettyAnnotatedEventDriver.java:209)
    at org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:64)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextFrame(JettyAnnotatedEventDriver.java:201)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:160)
    at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:302)
    at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:214)
    at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:220)
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:258)
    at org.eclipse.jetty.websocket.client.io.WebSocketClientConnection.onOpen(WebSocketClientConnection.java:92)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.upgradeConnection(UpgradeConnection.java:269)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:207)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:150)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Unknown Source)
Caused by: 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jetty.websocket.common.events.annotated.CallableMethod.call(CallableMethod.java:71)
    at org.eclipse.jetty.websocket.common.events.annotated.OptionalSessionCallableMethod.call(OptionalSessionCallableMethod.java:72)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextMessage(JettyAnnotatedEventDriver.java:209)
    at org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:64)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextFrame(JettyAnnotatedEventDriver.java:201)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:160)
    at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:302)
    at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:214)
    at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:220)
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:258)
    at org.eclipse.jetty.websocket.client.io.WebSocketClientConnection.onOpen(WebSocketClientConnection.java:92)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.upgradeConnection(UpgradeConnection.java:269)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:207)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:150)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Unknown Source)
Caused by: 
com.json.exceptions.JSONParsingException: @Key-Heirarchy::?@Key::a?= is expected...but found [@Position::1
    at com.json.utils.JSONUtility.handleFailure(JSONUtility.java:124)
    at com.json.parsers.JSONParser.consumeKeyOrName(JSONParser.java:933)
    at com.json.parsers.JSONParser.parseJsonBlock(JSONParser.java:208)
    at com.json.parsers.JSONParser.parseJson(JSONParser.java:139)
    at oooo.WebSocketConnection.onMessage(WebSocketConnection.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jetty.websocket.common.events.annotated.CallableMethod.call(CallableMethod.java:71)
    at org.eclipse.jetty.websocket.common.events.annotated.OptionalSessionCallableMethod.call(OptionalSessionCallableMethod.java:72)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextMessage(JettyAnnotatedEventDriver.java:209)
    at org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:64)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextFrame(JettyAnnotatedEventDriver.java:201)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:160)
    at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:302)
    at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:214)
    at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:220)
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:258)
    at org.eclipse.jetty.websocket.client.io.WebSocketClientConnection.onOpen(WebSocketClientConnection.java:92)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.upgradeConnection(UpgradeConnection.java:269)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:207)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:150)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Unknown Source)
2014-08-28 15:26:17.627:WARN:oejwc.Parser:WebSocketClient@497982732-23: 
org.eclipse.jetty.websocket.api.WebSocketException: java.lang.NullPointerException
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:280)
    at org.eclipse.jetty.websocket.client.io.WebSocketClientConnection.onOpen(WebSocketClientConnection.java:92)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.upgradeConnection(UpgradeConnection.java:269)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:207)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:150)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Unknown Source)
Caused by: 
java.lang.NullPointerException
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:259)
    at org.eclipse.jetty.websocket.client.io.WebSocketClientConnection.onOpen(WebSocketClientConnection.java:92)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.upgradeConnection(UpgradeConnection.java:269)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:207)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:150)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Unknown Source)
2014-08-28 15:26:17.627:WARN:oejut.QueuedThreadPool:WebSocketClient@497982732-23: 
org.eclipse.jetty.websocket.api.WebSocketException: java.lang.NullPointerException
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:280)
    at org.eclipse.jetty.websocket.client.io.WebSocketClientConnection.onOpen(WebSocketClientConnection.java:92)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.upgradeConnection(UpgradeConnection.java:269)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:207)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:150)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Unknown Source)
Caused by: 
java.lang.NullPointerException
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:259)
    at org.eclipse.jetty.websocket.client.io.WebSocketClientConnection.onOpen(WebSocketClientConnection.java:92)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.upgradeConnection(UpgradeConnection.java:269)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:207)
    at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:150)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
    at java.lang.Thread.run(Unknown Source)

我不知道造成这种情况的原因是什么,我正在使用jetty websocket和quick-json,我也尝试过GSON并在解析时遇到了同样的异常。 谢谢你的帮助。

0 个答案:

没有答案