Jsonrpc4j客户端上的JsonParseException

时间:2018-10-09 14:17:34

标签: java client jsonrpc4j

我正在尝试使用jsonrpc4创建客户端,但是我始终会遇到JsonParseException错误。 我已经尝试了很多方法,例如简单的client.invoke和动态代理,但是它不起作用,我也不明白为什么。

这是我的代码

public static void main(String[] args) throws Throwable {
        try {
            String username = "****";
            String password = "****";
            String cred = Base64.encodeBytes((username + ":" + password).getBytes());

            Map<String, String> headers = new HashMap<>(1);
            headers.put("Authorization", "Basic " + cred);

            JsonRpcHttpClient client = new JsonRpcHttpClient(new URL("https://dms1.ok.by/api/v1/json­rpc"));
            String elem =  client.invoke("myMethod", new Object [] {"param"}, String.class);

        }
        catch(Throwable throwable) {
            throwable.printStackTrace();
        }
    }
com.googlecode.jsonrpc4j.HttpException: stream is closed at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:161) 
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:185) 
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:110) 
    at net.nameshield.registryapi.monRobot.main(monRobot.java:38) 
     Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') 
    at [Source: com.googlecode.jsonrpc4j.NoCloseInputStream@1184ab05; line: 1, column: 2] 
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) 
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558) 
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:456) 
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2689) 
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:878) 
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:772) 
    at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3834) 
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3783) 
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2908) 
    at com.googlecode.jsonrpc4j.ReadContext.nextValue(ReadContext.java:25) 
    at com.googlecode.jsonrpc4j.JsonRpcClient.readResponseNode(JsonRpcClient.java:312) 
    at com.googlecode.jsonrpc4j.JsonRpcClient.getValidResponse(JsonRpcClient.java:246) 
    at com.googlecode.jsonrpc4j.JsonRpcClient.readResponse(JsonRpcClient.java:194) 
    at com.googlecode.jsonrpc4j.JsonRpcClient.readResponse(JsonRpcClient.java:531) 
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:159) 
... 3 more

0 个答案:

没有答案