1

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

1
  • Show us your code and the response string. Else, noone will be able to help you. I assume, that your Response is not in a correct format. Commented Jan 27, 2014 at 8:37

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

It is present in the request message.
Do you get any stacktrace? I am trying to follow the code and I see there being a method for adding jsonrpc, but I can't see it actually calling that method.
Im simply calling the method from main method.
But you have the request message somewhere? You said that jsonrpc is present in the request message.
it automatically gets added to the request parameter.if you print the request parameters yo get this:
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.