Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ subprojects {

// https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8190378
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
// for json-rpc, see https://github.com/briandilley/jsonrpc4j/issues/278
implementation group: 'javax.jws', name: 'javax.jws-api', version: '1.1'
annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'

testImplementation group: 'junit', name: 'junit', version: '4.13.2'
Expand Down
4 changes: 3 additions & 1 deletion framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
// end http

// https://mvnrepository.com/artifact/com.github.briandilley.jsonrpc4j/jsonrpc4j
implementation group: 'com.github.briandilley.jsonrpc4j', name: 'jsonrpc4j', version: '1.6'
implementation group: 'com.github.briandilley.jsonrpc4j', name: 'jsonrpc4j', version: '1.7'

// https://mvnrepository.com/artifact/javax.portlet/portlet-api
compileOnly group: 'javax.portlet', name: 'portlet-api', version: '3.0.1'
Expand All @@ -59,6 +59,8 @@ dependencies {

testImplementation group: 'org.springframework', name: 'spring-test', version: "${springVersion}"
testImplementation group: 'javax.portlet', name: 'portlet-api', version: '3.0.1'
// Mockito inspects JsonRpcServer's Jakarta servlet overload when creating mocks
testImplementation group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: '5.0.0'
Comment thread
waynercheung marked this conversation as resolved.

implementation group: 'org.zeromq', name: 'jeromq', version: '0.5.3'
api project(":chainbase")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ public void testScalarParametersEscapeAsKnownFrameworkDefect() {
@Test
public void testStringParameterConversionContract() throws Exception {
JsonNode objectResponse = handle(request("callStr", "[\"args\",{\"blockNumber\":\"0x1\"}]"));
assertParseErrorWithLostId(objectResponse);
assertParameterConversionError(objectResponse, 1);

JsonNode arrayResponse = handle(request("callStr", "[\"args\",[1,2]]"));
assertParseErrorWithLostId(arrayResponse);
assertParameterConversionError(arrayResponse, 1);

JsonNode firstIndexResponse = handle(request("oneArg", "[{\"a\":1}]"));
assertParameterConversionError(firstIndexResponse, 0);

JsonNode numberResponse = handle(request("callStr", "[\"args\",123]"));
Assert.assertEquals("str:123", numberResponse.get("result").asText());
Expand Down Expand Up @@ -130,6 +133,16 @@ private static void assertInvalidParams(JsonNode response) {
Assert.assertEquals(7, response.get("id").asInt());
}

private static void assertParameterConversionError(JsonNode response, int index) {
JsonNode error = response.get("error");
Assert.assertEquals(-32602, error.get("code").asInt());
Assert.assertEquals("Failed to read method parameter at index " + index,
error.get("message").asText());
Assert.assertFalse(error.has("data"));
Assert.assertTrue(response.get("id").isInt());
Assert.assertEquals(7, response.get("id").asInt());
}

private static void assertParseErrorWithLostId(JsonNode response) {
JsonNode error = response.get("error");
Assert.assertEquals(-32700, error.get("code").asInt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,43 @@ public void testServletBatchPropagatesInterceptorWrappedFatalError() throws Exce

@Test
public void testServletForwardsUnknownMethodNotificationError() throws Exception {
assertNotificationErrorIsForwarded("test_missing", -32601, "method not found");
assertNotificationErrorIsForwarded("test_missing", "[]", -32601, "method not found");
}

@Test
public void testServletForwardsArityNotificationError() throws Exception {
assertNotificationErrorIsForwarded("test_echo", -32602, "method parameters invalid");
assertNotificationErrorIsForwarded("test_echo", "[]", -32602, "method parameters invalid");
}

@Test
public void testServletForwardsUnmappedNotificationError() throws Exception {
assertNotificationErrorIsForwarded("test_unhandled", -32603, "Internal error");
assertNotificationErrorIsForwarded("test_unhandled", "[]", -32603, "Internal error");
}

@Test
public void testServletForwardsParameterConversionNotificationError() throws Exception {
assertNotificationErrorIsForwarded("test_echo", "[{\"a\":1}]", -32602,
"Failed to read method parameter at index 0");
}

@Test
public void testServletSingleParameterConversionErrorKeepsId() throws Exception {
TestableServlet servlet = newServlet(new ErrorServiceImpl());

assertJsonRpcResponse(post(servlet, request("test_echo", "[{\"a\":1}]", 7)),
errorResponse(-32602, "Failed to read method parameter at index 0", "7"));
}

@Test
public void testServletBatchParameterConversionErrorKeepsIdAndSibling() throws Exception {
TestableServlet servlet = newServlet(new ErrorServiceImpl());

MockHttpServletResponse response = post(servlet,
"[" + request("test_echo", "[{\"a\":1}]", 1) + "," + request("test_ok", "[]", 2) + "]");

assertJsonRpcResponse(response, MAPPER.createArrayNode()
.add(errorResponse(-32602, "Failed to read method parameter at index 0", "1"))
.add(MAPPER.readTree("{\"jsonrpc\":\"2.0\",\"result\":\"ok\",\"id\":2}")));
}

@Test
Expand Down Expand Up @@ -523,10 +549,11 @@ private static String request(String method, String params, int id) {
+ "\",\"params\":" + params + ",\"id\":" + id + "}";
}

private static void assertNotificationErrorIsForwarded(String method, int code, String message)
throws Exception {
private static void assertNotificationErrorIsForwarded(String method, String params, int code,
String message) throws Exception {
TestableServlet servlet = newServlet(new ErrorServiceImpl());
String notification = "{\"jsonrpc\":\"2.0\",\"method\":\"" + method + "\",\"params\":[]}";
String notification = "{\"jsonrpc\":\"2.0\",\"method\":\"" + method
+ "\",\"params\":" + params + "}";
JsonNode expected = errorResponse(code, message, "null");

assertJsonRpcResponse(post(servlet, notification), expected);
Expand Down
Loading
Loading