当前位置: 首页>>代码示例>>Java>>正文


Java JSONRPC2Response类代码示例

本文整理汇总了Java中com.thetransactioncompany.jsonrpc2.JSONRPC2Response的典型用法代码示例。如果您正苦于以下问题:Java JSONRPC2Response类的具体用法?Java JSONRPC2Response怎么用?Java JSONRPC2Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JSONRPC2Response类属于com.thetransactioncompany.jsonrpc2包,在下文中一共展示了JSONRPC2Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseJson

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private List<Object> parseJson(JSONRPC2Response response,
                               Class<?> clazz,
                               Boolean isArray) {
    Gson gson = new Gson();
    List objectList = new ArrayList();
    if (isArray) {
        JSONObject jsonObject = response.toJSONObject();
        JSONArray jsonArray = (JSONArray) jsonObject.get("result");

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject item = (JSONObject) jsonArray.get(i);
            objectList.add(gson.fromJson(item.toJSONString(), clazz));
        }
    } else {
        Object modelObject = gson.fromJson(response.getResult()
                .toString(), clazz);
        objectList.add(modelObject);
    }
    return objectList;
}
 
开发者ID:CactusSoft,项目名称:zabbkit-android,代码行数:22,代码来源:ZabbKitServerManager.java

示例2: onMessage

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
@Override
    public void onMessage(@NonNull final String message) {
//        Log.d(TAG, "received: " + message);
        System.out.println(message);
        try {
            final JSONRPC2Message jsonMessage = JSONRPC2Message.parse(message);
            if (jsonMessage instanceof JSONRPC2Request) {
                onHandleRequest(((JSONRPC2Request) jsonMessage));
            } else if (jsonMessage instanceof JSONRPC2Response) {
                onHandleResponse(((JSONRPC2Response) jsonMessage));
            } else if (jsonMessage instanceof JSONRPC2Notification) {
                onHandleNotification(((JSONRPC2Notification) jsonMessage));
            }
        } catch (@NonNull final JSONRPC2ParseException e) {
            //TODO error handling
            e.printStackTrace();
        }
    }
 
开发者ID:Ghedeon,项目名称:Rebro,代码行数:19,代码来源:WsClient.java

示例3: onHandleRequest

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
private void onHandleRequest(@NonNull final JSONRPC2Request request) {
        final RpcMethod rpcMethod = RpcMethod.valueOf(request.getMethod());
        switch (rpcMethod) {
            case LIST:
                final List<RTable> RTables = realmManager.list();
                final ListResponse listResponse = new ListResponse();
                listResponse.setConnectionId(connectionId);
                listResponse.setDbName(realmManager.getRealmFileName());
                listResponse.setTables(RTables);
                final JSONRPC2Response response = new JSONRPC2Response(listResponse, request.getID());
                send(response.toString());
//                Log.d(TAG, "send: " + response.toString());
                break;
            default:
        }
    }
 
开发者ID:Ghedeon,项目名称:Rebro,代码行数:17,代码来源:WsClient.java

示例4: onWebSocketText

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
@OnMessage
public void onWebSocketText(final Session sess, final JSONRPC2Message msg, @PathParam(CCOWContextListener.PATH_NAME) final String applicationName) {
	if (msg instanceof JSONRPC2Request) {
		//All operations that are invokable on ContextManager that does not return void
		logger.debug("The message is a Request");
	}
	else if (msg instanceof JSONRPC2Notification) {
		//All operations that are invokable on ContextManager that does return void
		logger.debug("The message is a Notification");
	}
	else if (msg instanceof JSONRPC2Response) {
		//All operations that are invokable from ContextManager that does not return void and are initially called from ContextManager
		participant.onMessage((JSONRPC2Response) msg);
		logger.debug("The message is a Response");
	}
}
 
开发者ID:jkiddo,项目名称:ccow,代码行数:17,代码来源:SubscriptionEndpoint.java

示例5: ContextChangesPending

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
@Override
public Form ContextChangesPending(final long contextCoupon) throws Exception {

	final JSONRPC2Request request = new JSONRPC2Request("ContextParticipant.ContextChangesPending", UUID.randomUUID().toString());
	final SettableFuture<JSONRPC2Response> future = SettableFuture.create();
	cache.put(request.getID().toString(), future);
	session.getBasicRemote().sendObject(request);

	final JSONRPC2Response response = future.get(3000, TimeUnit.MILLISECONDS);
	if(!response.indicatesSuccess())
		throw new RuntimeException("Error processing request: " + response.toJSONString());
	final Form form = new Form();
	final JSONObject r = (JSONObject) response.getResult();
	r.forEach((k,v)->form.add(k, v));
	return form;
}
 
开发者ID:jkiddo,项目名称:ccow,代码行数:17,代码来源:WSContextParticipantProxy.java

示例6: onWebSocketText

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
@OnMessage
public void onWebSocketText(final Session sess, final JSONRPC2Message msg) throws IOException, EncodeException {
	
	this.latestMessage = msg;
	
	if (msg instanceof JSONRPC2Request) {
		//All operations that are invokable on ContextManager that does not return void
		System.out.println("The message is a Request " + msg.toJSONString());
		final JSONRPC2Response data = new JSONRPC2Response(((JSONRPC2Request) msg).getID());
		final Map<String,String> result = Maps.newHashMap();
		result.put("decision", "valid");
		result.put("reason", "");
		data.setResult(result);
		sess.getBasicRemote().sendObject(data);
	}
	else if (msg instanceof JSONRPC2Notification) {
		//All operations that are invokable on ContextManager that does return void
		System.out.println("The message is a Notification " + msg.toJSONString());
	}
	else if (msg instanceof JSONRPC2Response) {
		//Can only be ContextChangesPending
		System.out.println("The message is a Response " + msg.toJSONString());
	}
}
 
开发者ID:jkiddo,项目名称:ccow,代码行数:25,代码来源:WSClientConnection.java

示例7: process

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
    if (req.getMethod().equals("Echo")) {
        JSONRPC2Error err = JSONRPC2Helper.validateParams(requiredArgs, req);
        if (err != null)
            return new JSONRPC2Response(err, req.getID());

        HashMap inParams = (HashMap) req.getParams();
        String echo = (String) inParams.get("Echo");
        Map outParams = new HashMap();
        outParams.put("Result", echo);
        return new JSONRPC2Response(outParams, req.getID());
    }
    else {
        // Method name not supported
        return new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
    }
}
 
开发者ID:i2p,项目名称:i2p.plugins.i2pcontrol,代码行数:18,代码来源:EchoHandler.java

示例8: handleLoadData

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
private JSONRPC2Response handleLoadData(JSONRPC2Request request, MessageContext context){
	if (!request.getParamsType().equals(JSONRPC2ParamsType.OBJECT) ||
			!(request.getParams() instanceof Map)) {
		return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS,
				request.getID());
	}
	Map<?,?> map = (Map<?,?>) request.getParams();
	if (!map.containsKey(JsonRpcConstants.PARAM_NAME_DATASET)) {
		return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS,
				request.getID());
	}
	String datasetName = getArg(map, JsonRpcConstants.PARAM_NAME_DATASET);
	if (datasetName == null) {
		return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS,
				request.getID());
	}
	datasetName = datasetName.trim();
	JSONRPC2Response response = new JSONRPC2Response(solver.getInputs(datasetName),request.getID());

	System.out.println("reponse: " + datasetName);
	return response;

}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:24,代码来源:JsonKidneyServer.java

示例9: testCreateSingleSwitch

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
/**
 * Test whether the creation of a host actually succeeds.
 */
@SuppressWarnings("unchecked")
public void testCreateSingleSwitch() {
    final PhysicalSwitch sw = new PhysicalSwitch(1);
    PhysicalNetwork.getInstance().addSwitch(sw);

    super.createNetwork();
    final JSONRPC2Response resp = super.createSwitch(1,
            Collections.singletonList(1));

    Assert.assertNull("CreateOVXSwitch should not return null",
            resp.getError());

    Assert.assertTrue("CreateOVXSwitch has incorrect return type",
            resp.getResult() instanceof Map<?, ?>);

    Map<String, Object> result = (Map<String, Object>) resp.getResult();

    Assert.assertEquals((long) 46200400562356225L,
            result.get(TenantHandler.VDPID));
}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:24,代码来源:PassingAPITest.java

示例10: testCreatePort

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
/**
 * Tests whether a create port call succeeds.
 */
@SuppressWarnings("unchecked")
public void testCreatePort() {
    final TestSwitch sw = new TestSwitch(1);
    PhysicalNetwork.getInstance().addSwitch(sw);
    final PhysicalPort port = new PhysicalPort(new OFPhysicalPort(), sw,
            true);
    port.setHardwareAddress(new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06});
    port.setPortNumber((short) 1);
    sw.addPort(port);

    super.createNetwork();
    super.createSwitch(1, Collections.singletonList(1));

    final JSONRPC2Response resp = super.createPort(1, (long) 1, (short) 1);

    Assert.assertNull("CreateOVXPort should not return null",
            resp.getError());

    Assert.assertTrue("CreateOVXPort has incorrect return type",
            resp.getResult() instanceof Map<?, ?>);

    Map<String, Object> result = (Map<String, Object>) resp.getResult();

    Assert.assertEquals((short) 1, result.get(TenantHandler.VPORT));
}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:29,代码来源:PassingAPITest.java

示例11: createNetwork

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
public JSONRPC2Response createNetwork(final Integer port) {
    final CreateOVXNetwork cn = new CreateOVXNetwork();

    @SuppressWarnings("serial")
    final HashMap<String, Object> request = new HashMap<String, Object>() {
        {
            ArrayList<String> ctrls = new ArrayList<String>();
            ctrls.add("tcp:localhost:" + port);

            this.put(TenantHandler.CTRLURLS, ctrls);
            this.put(TenantHandler.NETADD, "10.0.0.0");
            this.put(TenantHandler.NETMASK, 24);
        }
    };

    return cn.process(request);

}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:19,代码来源:AbstractAPICalls.java

示例12: createSwitch

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
public JSONRPC2Response createSwitch(final Integer tenantId,
        final List<Integer> dpids) {
    OVXMap.getInstance();
    final CreateOVXSwitch cs = new CreateOVXSwitch();

    @SuppressWarnings("serial")
    final HashMap<String, Object> request = new HashMap<String, Object>() {
        {
            this.put(TenantHandler.TENANT, tenantId);
            this.put(TenantHandler.DPIDS, dpids);
        }
    };

    return cs.process(request);

}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:17,代码来源:AbstractAPICalls.java

示例13: createPort

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
public JSONRPC2Response createPort(final Integer tenantId, final Long dpid,
        final Short port) {

    final CreateOVXPort cp = new CreateOVXPort();

    @SuppressWarnings("serial")
    final HashMap<String, Object> request = new HashMap<String, Object>() {
        {
            this.put(TenantHandler.TENANT, tenantId);
            this.put(TenantHandler.DPID, dpid);
            this.put(TenantHandler.PORT, port);
        }
    };

    return cp.process(request);
}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:17,代码来源:AbstractAPICalls.java

示例14: setInternalRouting

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
public JSONRPC2Response setInternalRouting(final Integer tenantId,
        final Long dpid, final String protocol, final byte backups) {

    final SetOVXBigSwitchRouting sr = new SetOVXBigSwitchRouting();

    @SuppressWarnings("serial")
    final HashMap<String, Object> request = new HashMap<String, Object>() {
        {
            this.put(TenantHandler.TENANT, tenantId);
            this.put(TenantHandler.VDPID, dpid);
            this.put(TenantHandler.ALGORITHM, protocol);
            this.put(TenantHandler.BACKUPS, backups);
        }
    };

    return sr.process(request);
}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:18,代码来源:AbstractAPICalls.java

示例15: connectHost

import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; //导入依赖的package包/类
public JSONRPC2Response connectHost(final Integer tenantId,
        final Long dpid, final Short port, final String mac) {

    final ConnectHost ch = new ConnectHost();

    @SuppressWarnings("serial")
    final HashMap<String, Object> request = new HashMap<String, Object>() {
        {
            this.put(TenantHandler.TENANT, tenantId);
            this.put(TenantHandler.VDPID, dpid);
            this.put(TenantHandler.VPORT, port);
            this.put(TenantHandler.MAC, mac);
        }
    };

    return ch.process(request);
}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:18,代码来源:AbstractAPICalls.java


注:本文中的com.thetransactioncompany.jsonrpc2.JSONRPC2Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。