Skip to content

Commit 277cc7e

Browse files
committed
fix formatting issues, http status code unit tests and upgrade dependency versions
1 parent 01817f3 commit 277cc7e

File tree

87 files changed

+1896
-1828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1896
-1828
lines changed

build.gradle

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
plugins {
22
id 'java'
3-
id 'nebula.optional-base' version '3.0.3'
4-
id 'nebula.provided-base' version '3.0.3'
3+
id 'nebula.optional-base' version '3.1.0'
4+
id 'nebula.provided-base' version '3.1.0'
55
id 'findbugs'
66
id 'pmd'
77
id 'jacoco'
88
id 'build-announcements'
9-
id 'nebula.info' version '3.0.3'
10-
id 'com.github.ben-manes.versions' version '0.12.0'
9+
id 'nebula.info' version '3.4.1'
10+
id 'com.github.ben-manes.versions' version '0.13.0'
1111
id 'osgi'
1212
id 'maven-publish'
1313
id 'nebula.nebula-javadoc-jar' version '2.2.2'
1414
id 'nebula.nebula-source-jar' version '2.2.2'
15-
id 'com.jfrog.bintray' version '1.6'
15+
id 'com.jfrog.bintray' version '1.7.3'
1616
}
1717

1818
description = 'This project aims to provide the facility to easily implement JSON-RPC for the java programming language.'
@@ -26,6 +26,9 @@ compileJava {
2626
options.encoding = 'UTF-8'
2727
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
2828
}
29+
test {
30+
maxParallelForks 5
31+
}
2932
compileTestJava {
3033
options.encoding = 'UTF-8'
3134
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
@@ -37,11 +40,11 @@ repositories {
3740

3841
dependencies {
3942
ext {
40-
jacksonVersion = '2.7.2'
41-
springVersion = '4.2.5.RELEASE'
42-
springBotVersion = '1.3.3.RELEASE'
43-
jettyVersion = '9.3.8.RC0'
44-
slf4jVersion = '1.7.9'
43+
jacksonVersion = '2.8.5'
44+
springVersion = '4.3.5.RELEASE'
45+
springBotVersion = '1.4.3.RELEASE'
46+
jettyVersion = '9.4.0.RC3'
47+
slf4jVersion = '1.7.22'
4548
}
4649

4750
compile 'net.iharder:base64:2.3.9'
@@ -59,7 +62,7 @@ dependencies {
5962
compile "org.springframework:spring-webmvc:${springVersion}", optional
6063

6164
compile 'commons-codec:commons-codec:1.10', optional
62-
compile 'org.apache.httpcomponents:httpcore-nio:4.4.4', optional
65+
compile 'org.apache.httpcomponents:httpcore-nio:4.4.5', optional
6366

6467
testCompile 'junit:junit:4.12'
6568
testCompile 'org.easymock:easymock:3.4'
@@ -73,22 +76,22 @@ dependencies {
7376
testCompile("org.eclipse.jetty:jetty-servlet:${jettyVersion}") {
7477
exclude module: 'org.eclipse.jetty.orbit'
7578
}
76-
testRuntime 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
77-
testRuntime 'org.apache.logging.log4j:log4j-core:2.5'
79+
testRuntime 'org.apache.logging.log4j:log4j-slf4j-impl:2.7'
80+
testRuntime 'org.apache.logging.log4j:log4j-core:2.7'
7881

7982
}
8083

8184
jar {
8285
manifest {
83-
instruction 'Import-Package',
84-
'org.aopalliance.intercept;resolution:="optional"',
85-
'org.apache.http.*;resolution:="optional"',
86-
'org.springframework.*;resolution:="optional"',
87-
'org.apache.commons.logging;resolution:="optional"',
88-
'javax.portlet;resolution:="optional"',
89-
'javax.servlet*;version=0.0.0',
90-
'*'
91-
}
86+
instruction 'Import-Package',
87+
'org.aopalliance.intercept;resolution:="optional"',
88+
'org.apache.http.*;resolution:="optional"',
89+
'org.springframework.*;resolution:="optional"',
90+
'org.apache.commons.logging;resolution:="optional"',
91+
'javax.portlet;resolution:="optional"',
92+
'javax.servlet*;version=0.0.0',
93+
'*'
94+
}
9295
}
9396

9497
jacoco {
@@ -171,4 +174,4 @@ bintray {
171174

172175
bintrayUpload {
173176
dependsOn "publishToMavenLocal"
174-
}
177+
}

src/main/java/com/googlecode/jsonrpc4j/AnnotationsErrorResolver.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,46 @@
1010
*/
1111
public enum AnnotationsErrorResolver implements ErrorResolver {
1212
INSTANCE;
13-
13+
1414
/**
1515
* {@inheritDoc}
1616
*/
1717
@Override
1818
public JsonError resolveError(Throwable thrownException, Method method, List<JsonNode> arguments) {
1919
JsonRpcError resolver = getResolverForException(thrownException, method);
2020
if (notFoundResolver(resolver)) return null;
21-
21+
2222
String message = hasErrorMessage(resolver) ? resolver.message() : thrownException.getMessage();
2323
return new JsonError(resolver.code(), message, new ErrorData(resolver.exception().getName(), message));
2424
}
25-
25+
2626
private JsonRpcError getResolverForException(Throwable thrownException, Method method) {
2727
JsonRpcErrors errors = ReflectionUtil.getAnnotation(method, JsonRpcErrors.class);
2828
if (hasAnnotations(errors)) {
2929
for (JsonRpcError errorDefined : errors.value()) {
30-
if (isExceptionInstanceOfError(thrownException, errorDefined)) { return errorDefined; }
30+
if (isExceptionInstanceOfError(thrownException, errorDefined)) {
31+
return errorDefined;
32+
}
3133
}
3234
}
3335
return null;
3436
}
35-
37+
3638
private boolean notFoundResolver(JsonRpcError resolver) {
3739
return resolver == null;
3840
}
39-
41+
4042
private boolean hasErrorMessage(JsonRpcError em) {
4143
// noinspection ConstantConditions
4244
return em.message() != null && em.message().trim().length() > 0;
4345
}
44-
46+
4547
private boolean hasAnnotations(JsonRpcErrors errors) {
4648
return errors != null;
4749
}
48-
50+
4951
private boolean isExceptionInstanceOfError(Throwable target, JsonRpcError em) {
5052
return em.exception().isInstance(target);
5153
}
52-
54+
5355
}

src/main/java/com/googlecode/jsonrpc4j/ConvertedParameterTransformer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* Implementations of this interface are able to transform the converted parameters before a method invocation in the
55
* JSON-RPC service. This allows for mutation of the deserialized arguments before a method invocation or for validation
66
* of the actual argument objects.
7-
*
7+
* <p>
88
* Any exceptions thrown in the {@link ConvertedParameterTransformer#transformConvertedParameters(Object, Object[])}
99
* method, will be returned as an error to the JSON-RPC client.
1010
*/
1111
public interface ConvertedParameterTransformer {
12-
12+
1313
/**
1414
* Returns the parameters that will be passed to the method on invocation.
1515
*
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
package com.googlecode.jsonrpc4j;
22

3-
import static com.googlecode.jsonrpc4j.ErrorResolver.JsonError.ERROR_NOT_HANDLED;
4-
53
import com.fasterxml.jackson.databind.JsonNode;
64

75
import java.lang.reflect.Method;
86
import java.util.List;
97

8+
import static com.googlecode.jsonrpc4j.ErrorResolver.JsonError.ERROR_NOT_HANDLED;
9+
1010
/**
1111
* An {@link ErrorResolver} that puts type information into the
1212
* data portion of the error. This {@link ErrorResolver} always
1313
* returns a {@link com.googlecode.jsonrpc4j.ErrorResolver.JsonError JsonError}.
14-
*
1514
*/
1615
@SuppressWarnings("WeakerAccess")
1716
public enum DefaultErrorResolver implements ErrorResolver {
1817
INSTANCE;
19-
18+
2019
/**
2120
* {@inheritDoc}
2221
*/
2322
public JsonError resolveError(Throwable t, Method method, List<JsonNode> arguments) {
2423
return new JsonError(ERROR_NOT_HANDLED.code, t.getMessage(), new ErrorData(t.getClass().getName(), t.getMessage()));
2524
}
26-
25+
2726
}

src/main/java/com/googlecode/jsonrpc4j/DefaultExceptionResolver.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.googlecode.jsonrpc4j;
22

3-
import static com.googlecode.jsonrpc4j.Util.hasNonNullObjectData;
4-
import static com.googlecode.jsonrpc4j.Util.hasNonNullTextualData;
5-
3+
import com.fasterxml.jackson.databind.node.ObjectNode;
64
import org.slf4j.Logger;
75
import org.slf4j.LoggerFactory;
86

9-
import com.fasterxml.jackson.databind.node.ObjectNode;
10-
117
import java.lang.reflect.Constructor;
128
import java.lang.reflect.InvocationTargetException;
139

10+
import static com.googlecode.jsonrpc4j.Util.hasNonNullObjectData;
11+
import static com.googlecode.jsonrpc4j.Util.hasNonNullTextualData;
12+
1413
/**
1514
* Default implementation of the {@link ExceptionResolver} interface that attempts to re-throw the same exception
1615
* that was thrown by the server. This always returns a {@link Throwable}.
@@ -19,17 +18,19 @@
1918
public enum DefaultExceptionResolver implements ExceptionResolver {
2019
INSTANCE;
2120
private static final Logger logger = LoggerFactory.getLogger(DefaultExceptionResolver.class);
22-
21+
2322
/**
2423
* {@inheritDoc}
2524
*/
2625
public Throwable resolveException(ObjectNode response) {
2726
ObjectNode errorObject = ObjectNode.class.cast(response.get(JsonRpcBasicServer.ERROR));
28-
if (!hasNonNullObjectData(errorObject, JsonRpcBasicServer.DATA)) return createJsonRpcClientException(errorObject);
29-
27+
if (!hasNonNullObjectData(errorObject, JsonRpcBasicServer.DATA))
28+
return createJsonRpcClientException(errorObject);
29+
3030
ObjectNode dataObject = ObjectNode.class.cast(errorObject.get(JsonRpcBasicServer.DATA));
31-
if (!hasNonNullTextualData(dataObject, JsonRpcBasicServer.EXCEPTION_TYPE_NAME)) return createJsonRpcClientException(errorObject);
32-
31+
if (!hasNonNullTextualData(dataObject, JsonRpcBasicServer.EXCEPTION_TYPE_NAME))
32+
return createJsonRpcClientException(errorObject);
33+
3334
try {
3435
String exceptionTypeName = dataObject.get(JsonRpcBasicServer.EXCEPTION_TYPE_NAME).asText();
3536
String message = hasNonNullTextualData(dataObject, JsonRpcBasicServer.ERROR_MESSAGE) ? dataObject.get(JsonRpcBasicServer.ERROR_MESSAGE).asText() : null;
@@ -39,7 +40,7 @@ public Throwable resolveException(ObjectNode response) {
3940
return createJsonRpcClientException(errorObject);
4041
}
4142
}
42-
43+
4344
/**
4445
* Creates a {@link JsonRpcClientException} from the given
4546
* {@link ObjectNode}.
@@ -51,7 +52,7 @@ private JsonRpcClientException createJsonRpcClientException(ObjectNode errorObje
5152
int code = errorObject.has(JsonRpcBasicServer.ERROR_CODE) ? errorObject.get(JsonRpcBasicServer.ERROR_CODE).asInt() : 0;
5253
return new JsonRpcClientException(code, errorObject.get(JsonRpcBasicServer.ERROR_MESSAGE).asText(), errorObject.get(JsonRpcBasicServer.DATA));
5354
}
54-
55+
5556
/**
5657
* Attempts to create an {@link Throwable} of the given type with the given message. For this method to create a
5758
* {@link Throwable} it must have either a default (no-args) constructor or a constructor that takes a {@code String}
@@ -68,10 +69,10 @@ private JsonRpcClientException createJsonRpcClientException(ObjectNode errorObje
6869
private Throwable createThrowable(String typeName, String message) throws IllegalAccessException, InvocationTargetException, InstantiationException {
6970
Class<? extends Throwable> clazz = loadThrowableClass(typeName);
7071
if (clazz == null) return null;
71-
72+
7273
Constructor<? extends Throwable> defaultCtr = getDefaultConstructor(clazz);
7374
Constructor<? extends Throwable> messageCtr = getMessageConstructor(clazz);
74-
75+
7576
if (message != null && messageCtr != null) {
7677
return messageCtr.newInstance(message);
7778
} else if (message != null && defaultCtr != null) {
@@ -87,7 +88,7 @@ private Throwable createThrowable(String typeName, String message) throws Illega
8788
return null;
8889
}
8990
}
90-
91+
9192
private Class<? extends Throwable> loadThrowableClass(String typeName) {
9293
Class<?> clazz;
9394
try {
@@ -102,7 +103,7 @@ private Class<? extends Throwable> loadThrowableClass(String typeName) {
102103
}
103104
return null;
104105
}
105-
106+
106107
private Constructor<? extends Throwable> getDefaultConstructor(Class<? extends Throwable> clazz) {
107108
Constructor<? extends Throwable> defaultCtr = null;
108109
try {
@@ -112,7 +113,7 @@ private Constructor<? extends Throwable> getDefaultConstructor(Class<? extends T
112113
}
113114
return defaultCtr;
114115
}
115-
116+
116117
private Constructor<? extends Throwable> getMessageConstructor(Class<? extends Throwable> clazz) {
117118
Constructor<? extends Throwable> messageCtr = null;
118119
try {
@@ -122,9 +123,9 @@ private Constructor<? extends Throwable> getMessageConstructor(Class<? extends T
122123
}
123124
return messageCtr;
124125
}
125-
126+
126127
@SuppressWarnings("UnusedParameters")
127128
private void handleException(Exception e) {
128-
/* do nothing */
129+
/* do nothing */
129130
}
130131
}

0 commit comments

Comments
 (0)