Search in sources :

Example 1 with JSONRPC2Session

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session in project junit-plugin by kiwitcms.

the class BaseRpcClient method executeViaPositionalParams.

protected Object executeViaPositionalParams(String serviceMethod, List<Object> params) {
    JSONRPC2Session mySession = prepareSession();
    // Construct new request
    int requestID = 1;
    JSONRPC2Request request = new JSONRPC2Request(serviceMethod, requestID);
    request.setPositionalParams(params);
    // Send request
    try {
        return getResponse(mySession.send(request));
    } catch (JSONRPC2SessionException e) {
        System.err.println(e.getMessage());
        return null;
    }
}
Also used : JSONRPC2SessionException(com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException) JSONRPC2Session(com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session) JSONRPC2Request(com.thetransactioncompany.jsonrpc2.JSONRPC2Request)

Example 2 with JSONRPC2Session

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session in project junit-plugin by kiwitcms.

the class BaseRpcClient method prepareSession.

protected JSONRPC2Session prepareSession() {
    URL serverURL = null;
    try {
        serverURL = new URL(BASE_URL.replace("xml-rpc", "json-rpc"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    }
    JSONRPC2Session mySession = new JSONRPC2Session(serverURL);
    mySession.getOptions().setRequestContentType("application/json");
    mySession.getOptions().trustAllCerts(true);
    mySession.setConnectionConfigurator(new SessionConfigurator(sessionId));
    return mySession;
}
Also used : MalformedURLException(java.net.MalformedURLException) JSONRPC2Session(com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session) URL(java.net.URL)

Example 3 with JSONRPC2Session

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session in project starcoin-java by starcoinorg.

the class JsonRPCClient method getObjectArray.

/**
 * 获取对象列表的接口
 *
 * @param session
 * @param method    rpc接口的方法名
 * @param params    rpc接口的参数列表
 * @param requestId 请求id
 * @param clazz     返回对象的封装类
 * @return
 * @throws JSONRPC2SessionException
 */
protected List<T> getObjectArray(JSONRPC2Session session, String method, List<Object> params, int requestId, Class<T> clazz) throws JSONRPC2SessionException {
    JSONRPC2Request request = new JSONRPC2Request(method, params, requestId);
    JSONRPC2Response response = session.send(request);
    if (response.indicatesSuccess()) {
        Object result = response.getResult();
        if (result != null) {
            return JSON.parseArray(result.toString(), clazz);
        }
    }
    return null;
}
Also used : JSONRPC2Response(com.thetransactioncompany.jsonrpc2.JSONRPC2Response) JSONObject(com.alibaba.fastjson.JSONObject) JSONRPC2Request(com.thetransactioncompany.jsonrpc2.JSONRPC2Request)

Example 4 with JSONRPC2Session

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session in project starcoin-java by starcoinorg.

the class JsonRPCClient method getObject.

/**
 * 获取单个对象的接口
 *
 * @param session
 * @param method    rpc接口的方法名
 * @param params    rpc接口的参数列表
 * @param requestId 请求id
 * @param clazz     返回对象的封装类
 * @return
 * @throws JSONRPC2SessionException
 */
protected T getObject(JSONRPC2Session session, String method, List<Object> params, int requestId, Class<T> clazz) throws JSONRPC2SessionException {
    JSONRPC2Request request = new JSONRPC2Request(method, params, requestId);
    JSONRPC2Response response = session.send(request);
    if (response.indicatesSuccess()) {
        Object result = response.getResult();
        if (result != null) {
            return JSON.parseObject(result.toString(), clazz);
        }
    }
    return null;
}
Also used : JSONRPC2Response(com.thetransactioncompany.jsonrpc2.JSONRPC2Response) JSONObject(com.alibaba.fastjson.JSONObject) JSONRPC2Request(com.thetransactioncompany.jsonrpc2.JSONRPC2Request)

Example 5 with JSONRPC2Session

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session in project junit-plugin by kiwitcms.

the class BaseRpcClient method executeViaNamedParams.

protected Object executeViaNamedParams(String serviceMethod, Map<String, Object> params) {
    JSONRPC2Session mySession = prepareSession();
    // Construct new request
    int requestID = 1;
    JSONRPC2Request request = new JSONRPC2Request(serviceMethod, requestID);
    request.setNamedParams(params);
    // Send request
    try {
        return getResponse(mySession.send(request));
    } catch (JSONRPC2SessionException e) {
        System.err.println(e.getMessage());
        return null;
    }
}
Also used : JSONRPC2SessionException(com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException) JSONRPC2Session(com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session) JSONRPC2Request(com.thetransactioncompany.jsonrpc2.JSONRPC2Request)

Aggregations

JSONRPC2Request (com.thetransactioncompany.jsonrpc2.JSONRPC2Request)7 JSONObject (com.alibaba.fastjson.JSONObject)4 JSONRPC2Response (com.thetransactioncompany.jsonrpc2.JSONRPC2Response)4 JSONRPC2Session (com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session)4 JSONRPC2SessionException (com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1