Calling RPC API With Java Client

I am using upsource version 2.0.3682 and trying to call the json-rpc api through this rpc client but its failing in mapping the response object. Can you suggest possible fixes and guide to a couple of java examples that can make the api-integration smooth?

Below is the java client code

 
try {
    Map<String, String> headers = new HashMap<>(1);
    headers.put("Authorization", "Basic <encoded-credentials>");
    JsonRpcHttpClient client = new JsonRpcHttpClient(
            new URL("http://<servername>:8080/~rpc/getAllProjects"), headers);

    ProjectListDTO listDTO = client.invoke("getAllProjects", new Object[] {}, ProjectListDTO.class);
} catch (Throwable throwable) {
    throwable.printStackTrace();
}

 
public class ProjectListDTO {
    private List<ProjectInfoDTO> project;
}
 

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "project" (class com.myproject.upsource.ProjectListDTO), not marked as ignorable (0 known properties: ])
at [Source: N/A; line: -1, column: -1] (through reference chain: com.myproject.upsource.ProjectListDTO["project"])
     at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51)
     at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:839)
     at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1045)
     at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1352)
     at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1330)
     at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:264)
     at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
     at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3708)
     at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2071)
     at com.googlecode.jsonrpc4j.JsonRpcClient.readResponse(JsonRpcClient.java:283)
     at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:160)
     ... 9 more


Thanks!

4 comments
Comment actions Permalink

Amit,

Why wouldn't you use Upsource java-library?

There are some API description available at http://<upsource_host>/~api_doc/index.html Does it help you?

Thanks.

0
Comment actions Permalink

Can you point me to the upsource java library? Can it act as a json-rpc api client?

There are some API description available at http://<upsource_host>/~api_doc/index.html Does it help you?

Yes I have been through the API documentation. It provides basic http call examples. I am looking for a java code sample that can help me to quickly get kick started.

Thanks,
Amit.

0
Comment actions Permalink

Amit,

We have prepared a java code sample for you -

https://github.com/maxim5/Upsource.SampleRPC

Please let me know if it helps.

0
Comment actions Permalink

Thanks Artem. The sample really helped.

0

Please sign in to leave a comment.