problem: in some cases WS may produce empty or broken messages that breaks the connection

solution: better handling for invalid JSON

(cherry picked from commit 1b6a995c4e746f0704643426fc20f7496fc09cef)
This commit is contained in:
Igor Artamonov
2022-11-18 22:44:09 -05:00
committed by a10zn8
parent 255a3833fd
commit 3123e89bc8
4 changed files with 65 additions and 8 deletions

View File

@@ -223,4 +223,27 @@ class ResponseRpcParserSpec extends Specification {
!act.hasResult()
}
def "Keep provided ID even if JSON is not full"() {
setup:
def json = '{"jsonrpc": "2.0", "id": 1}'
when:
def act = parser.parse(json.getBytes())
then:
act.id.asNumber() == 1
act.error != null
act.hasError()
!act.hasResult()
}
def "Keep provided ID even if JSON is broken"() {
setup:
def json = '{"jsonrpc": "2.0", "id": 101, "resu'
when:
def act = parser.parse(json.getBytes())
then:
act.id.asNumber() == 101
act.error != null
act.hasError()
!act.hasResult()
}
}

View File

@@ -103,4 +103,24 @@ class ResponseWSParserSpec extends Specification {
act.error == null
new String(act.value) == "null"
}
def "Keep provided ID even if JSON is not full"() {
setup:
def json = '{"jsonrpc": "2.0", "id": 1}'
when:
def act = parser.parse(json.getBytes())
then:
act.id.asNumber() == 1
act.error != null
}
def "Keep provided ID even if JSON is broken"() {
setup:
def json = '{"jsonrpc": "2.0", "id": 101, "resu'
when:
def act = parser.parse(json.getBytes())
then:
act.id.asNumber() == 101
act.error != null
}
}