user2365991
user2365991

Reputation: 11

Json Response exception

I get this exception while using json

json: com.thetransactioncompany.jsonrpc2.JSONRPC2ParseException: Invalid JSON-RPC 2.0:

Version string missing? Im getting exception at the below line:

JSONRPC2Response response = session.send(requestOut);

Here is my code:

JSONRPC2Session session = new JSONRPC2Session(endPointURL);
        JSONRPC2SessionOptions options=session.getOptions();
        ///options.setRequestContentType("text/html");
        options.setAllowedResponseContentTypes(new String[]{"text/html; charset=UTF-8"});



        String method = "Request";
        String timestamp=PaymentStringUtil.gofTimeStamp();
        Map<String, Object> reqParams = new HashMap<String, Object>();

        reqParams.put("words", StringUtil.sha1("SA3PROU","a8affe42f8bbc90621762c53fd973bceee175db2","20140120100821"));
        reqParams.put("tourcode", "SA3PROU");
        reqParams.put("timestamp","20140120100821");



        System.out.println(reqParams);

        JSONRPC2Request requestOut = new JSONRPC2Request(method,reqParams,1);
        System.out.println(requestOut);
        try {
            System.out.println("Inside try-----------");

            JSONRPC2Response response = session.send(requestOut);
            //System.out.println(session.send(requestOut));


            System.out.println(response.indicatesSuccess());
            if (response.indicatesSuccess()) {




        System.out.println("Inside the indicate success");
                JSONParser jsonParser =new JSONParser();
                JSONObject jsonObject=(JSONObject)jsonParser.parse(response.getResult().toString());
                JSONObject response=(JSONObject)jsonObject.get("Request");
                //set the response obj
            } else {
                System.out.println("Outside the indicate success");
                System.out.println(response.getError().getMessage());

            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();


        }

        return response;
    }

Here is the stack trace:

Invalid JSON-RPC 2.0 response com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException: Invalid JSON-RPC 2.0 response at com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session.send(JSONRPC2Session.java:586) at com.garuda.api.test.Configure.requestProvider(Configure.java:81) at com.garuda.api.test.Configure.main(Configure.java:128) Caused by: com.thetransactioncompany.jsonrpc2.JSONRPC2ParseException: Invalid JSON-RPC 2.0: Version string missing at com.thetransactioncompany.jsonrpc2.JSONRPC2Parser.ensureVersion2(JSONRPC2Parser.java:236) at com.thetransactioncompany.jsonrpc2.JSONRPC2Parser.parseJSONRPC2Response(JSONRPC2Parser.java:481) at com.thetransactioncompany.jsonrpc2.JSONRPC2Response.parse(JSONRPC2Response.java:229) at com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session.send(JSONRPC2Session.java:579) ... 2 more

Upvotes: 1

Views: 1644

Answers (1)

DanielBarbarian
DanielBarbarian

Reputation: 5343

Looking at the source code of JSONRPC2Parser the version for JSON-RPC 2.0 must be present in the request object in the jsonrpc member. If it is not present at all you get the error you are describing. According to the JSON-RPC 2.0 specification the version must be present and be 2.0.

Upvotes: 1

Related Questions