Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
205 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Wed Jan 11 14:37:59 GMT 2017 | ||
#Fri Feb 17 20:25:46 GMT+03:00 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.googlecode.jsonrpc4j; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* 20.04.2016 | ||
* KostaPC | ||
*/ | ||
|
||
public class VarArgsUtil { | ||
|
||
public static Map<String, Object> convertArgs(Object[] params) { | ||
|
||
final Map<String, Object> unsafeMap = new HashMap<>(); | ||
for (int i = 0; i < params.length; i += 2) { | ||
if(params[i] instanceof String && params[i]!=null && !params[i].toString().isEmpty()) { | ||
unsafeMap.put(params[i].toString(), params[i + 1]); | ||
} | ||
} | ||
return unsafeMap; | ||
|
||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/test/java/com/googlecode/jsonrpc4j/server/JsonRpcServerAnnotateMethodVarArgsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.googlecode.jsonrpc4j.server; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.googlecode.jsonrpc4j.JsonRpcBasicServer; | ||
import com.googlecode.jsonrpc4j.JsonRpcMethod; | ||
import org.easymock.EasyMockRunner; | ||
import org.easymock.Mock; | ||
import org.easymock.MockType; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT; | ||
import static com.googlecode.jsonrpc4j.util.Util.*; | ||
|
||
@RunWith(EasyMockRunner.class) | ||
public class JsonRpcServerAnnotateMethodVarArgsTest { | ||
|
||
@Mock(type = MockType.NICE) | ||
private ServiceInterfaceWithCustomMethodNameWithVarArgsAnnotation mockService; | ||
|
||
private ByteArrayOutputStream byteArrayOutputStream; | ||
private JsonRpcBasicServer jsonRpcServerAnnotatedMethod; | ||
|
||
@Before | ||
public void setup() { | ||
byteArrayOutputStream = new ByteArrayOutputStream(); | ||
jsonRpcServerAnnotatedMethod = new JsonRpcBasicServer(mapper, mockService, ServiceInterfaceWithCustomMethodNameWithVarArgsAnnotation.class); | ||
} | ||
|
||
@Test | ||
public void callMethodWithVarArgParameters() throws Exception { | ||
jsonRpcServerAnnotatedMethod.handleRequest( | ||
messageWithMapParamsStream( | ||
"testMethodVararg", | ||
"argOne","one", | ||
"argTwo",2, | ||
"argThree","three", | ||
"argFour", 4, | ||
"argFive", (Object)"five", | ||
"argSix", 6.0f, | ||
"argSeven", 7d | ||
), | ||
byteArrayOutputStream | ||
); | ||
|
||
System.out.println("res: "+result()); | ||
|
||
} | ||
|
||
private JsonNode result() throws IOException { | ||
return decodeAnswer(byteArrayOutputStream).get(RESULT); | ||
} | ||
|
||
|
||
public interface ServiceInterfaceWithCustomMethodNameWithVarArgsAnnotation { | ||
@JsonRpcMethod("Test.custom") | ||
String customMethod(); | ||
|
||
@JsonRpcMethod("Test.custom2") | ||
String customMethod2(String stringParam1); | ||
|
||
@JsonRpcMethod("testMethodVararg") | ||
String testMethodVararg(Object... params); | ||
} | ||
|
||
} |