本文整理汇总了Java中com.thetransactioncompany.jsonrpc2.JSONRPC2Request类的典型用法代码示例。如果您正苦于以下问题:Java JSONRPC2Request类的具体用法?Java JSONRPC2Request怎么用?Java JSONRPC2Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONRPC2Request类属于com.thetransactioncompany.jsonrpc2包,在下文中一共展示了JSONRPC2Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的package包/类
@Override
protected Boolean doInBackground(Request... params) {
Request request = params[0];
JSONRPC2Request jsonRpcRequest = new JSONRPC2Request(
request.methodName, request.params, request.id);
if (request.auth != null) {
jsonRpcRequest.appendNonStdAttribute(UrlParams.AUTH,
request.auth);
}
mClass = request.clazz;
mListener = request.listener;
String JSONStr = jsonRpcRequest.toJSONString();
String ReqStr = jsonRpcRequest.toString();
Boolean success = sendRequest(jsonRpcRequest, request.isArray);
removeRequest(request.requestId);
return success;
}
示例2: onMessage
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的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();
}
}
示例3: onHandleRequest
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的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:
}
}
示例4: onWebSocketText
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的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");
}
}
示例5: ContextChangesPending
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的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;
}
示例6: onWebSocketText
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的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());
}
}
示例7: process
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的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());
}
}
示例8: parseJsonRequest
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的package包/类
/**
* Parse HttpServletRequest to JSON-RPC request
* Assumed the request content is encoded with UTF-8
* @param request HttpServletRequest
* @return JSONRPC2Request
* @throws IOException
*/
protected JSONRPC2Request parseJsonRequest(HttpServletRequest request) throws IOException, JSONRPC2ParseException {
String contentType = request.getHeader("Content-Type");
Integer contentLength = Ints.tryParse(request.getHeader("Content-Length"));
Preconditions.checkArgument(requestValidator(contentType, contentLength), "Invalid JSON request");
BufferedReader reader = request.getReader();
StringBuffer message = new StringBuffer();
char[] buffer = new char[contentLength];
int numRead = 0;
while (numRead < contentLength) {
int read = reader.read(buffer, 0, buffer.length);
String s = new String(buffer, 0, read);
numRead += s.getBytes(Charsets.UTF_8).length;
message.append(s);
}
return JSONRPC2Request.parse(message.toString(), true, true, true);
}
示例9: handleLoadData
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的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;
}
示例10: parseJSONRequest
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的package包/类
/**
* Parses the JSON request.
*
* @param request
* the request
* @return the JSON object
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws JSONRPC2ParseException if JSON request is invalid
*/
protected JSONRPC2Request parseJSONRequest(final HttpServletRequest request)
throws IOException, JSONRPC2ParseException {
final BufferedReader reader = request.getReader();
final StringBuilder sb = new StringBuilder();
String line = reader.readLine();
while (line != null) {
sb.append(line + "\n");
line = reader.readLine();
}
reader.close();
AbstractService.log.debug("---------JSON RPC request: {}",
sb.toString());
return JSONRPC2Request.parse(sb.toString());
}
示例11: doInBackground
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的package包/类
@Override
protected JSONRPC2Response doInBackground(String... params1) {
if(params == null) {
params = new HashMap<String, Object>();
}
String method = params1[0];
session.getOptions().setRequestContentType("application/json");
session.getOptions().setConnectTimeout(100);
JSONRPC2Request request = new JSONRPC2Request(method, params, requestID);
JSONRPC2Response response = null;
try {
response = session.send(request);
Log.i("response", response.toString());
} catch (JSONRPC2SessionException e) {
// e.printStackTrace();
}
requestID++;
return response;
}
示例12: testSendJsonRpcRequestNoParamsPassed_SuccessResponse
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的package包/类
@Test
public void testSendJsonRpcRequestNoParamsPassed_SuccessResponse() throws Exception {
String url = "http://localhost:8080/Identities.php";
Class<?> responseClass = GetEventDataVO.class;
String method = "method1";
Map<String, Object> params = new HashMap<>();
params.put("param1", "value1");
CreateIdentityRequestVO createIdentityRequestVO = ImmutableCreateIdentityRequestVO.builder().setAuth("auth").build();
String responseJson = JsonUtils.convertObjectToJson(GsonUtils.GSON, createIdentityRequestVO);
PowerMockito.mockStatic(JsonUtils.class);
URL mockUrl = PowerMockito.mock(URL.class);
JSONRPC2Session mockJSONRPC2Session = PowerMockito.mock(JSONRPC2Session.class);
JSONRPC2SessionOptions mockOptions = Mockito.mock(JSONRPC2SessionOptions.class);
JSONRPC2Request mockJSONRPC2Request = Mockito.mock(JSONRPC2Request.class);
JSONRPC2Response mockJSONRPC2Response = Mockito.mock(JSONRPC2Response.class);
PowerMockito.whenNew(URL.class).withArguments(Mockito.anyString()).thenReturn(mockUrl);
PowerMockito.whenNew(JSONRPC2Session.class).withArguments(Mockito.isA(URL.class)).thenReturn(mockJSONRPC2Session);
Mockito.when(mockJSONRPC2Session.getOptions()).thenReturn(mockOptions);
PowerMockito.whenNew(JSONRPC2Request.class).withParameterTypes(String.class, Object.class).withArguments(Mockito.anyString(), Mockito.anyString()).thenReturn(mockJSONRPC2Request);
Mockito.when(mockJSONRPC2Session.send(Mockito.isA(JSONRPC2Request.class))).thenReturn(mockJSONRPC2Response);
Mockito.when(mockJSONRPC2Response.indicatesSuccess()).thenReturn(true);
Mockito.when(mockJSONRPC2Response.getResult()).thenReturn(responseJson);
PowerMockito.when(JsonUtils.convertJsonToObject(Mockito.isA(Gson.class), Mockito.anyString(), Mockito.isA(Class.class))).thenReturn(createIdentityRequestVO);
jsonRpcUtils = new JsonRpcUtils();
Object responseObject = jsonRpcUtils.sendJsonRpcRequest(url, responseClass, method);
assertThat(responseObject).isNotNull();
PowerMockito.verifyNew(URL.class, Mockito.times(1)).withArguments(Mockito.anyString());
PowerMockito.verifyNew(JSONRPC2Session.class, Mockito.times(1)).withArguments(Mockito.isA(URL.class));
Mockito.verify(mockJSONRPC2Session, Mockito.times(1)).getOptions();
PowerMockito.verifyNew(JSONRPC2Request.class, Mockito.times(1)).withArguments(Mockito.anyString(), Mockito.anyString());
Mockito.verify(mockJSONRPC2Session, Mockito.times(1)).send(Mockito.isA(JSONRPC2Request.class));
Mockito.verify(mockJSONRPC2Response, Mockito.times(1)).indicatesSuccess();
Mockito.verify(mockJSONRPC2Response, Mockito.times(1)).getResult();
}
示例13: testSendJsonRpcRequest_JSONRPC2SessionExceptionSendingRequest
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的package包/类
@Test
public void testSendJsonRpcRequest_JSONRPC2SessionExceptionSendingRequest() throws Exception {
String url = "http://localhost:8080/Identities.php";
Class<?> responseClass = GetEventDataVO.class;
String method = "method1";
Map<String, Object> params = new HashMap<>();
params.put("param1", "value1");
URL mockUrl = PowerMockito.mock(URL.class);
JSONRPC2Session mockJSONRPC2Session = PowerMockito.mock(JSONRPC2Session.class);
JSONRPC2SessionOptions mockOptions = Mockito.mock(JSONRPC2SessionOptions.class);
JSONRPC2Request mockJSONRPC2Request = Mockito.mock(JSONRPC2Request.class);
PowerMockito.whenNew(URL.class).withArguments(Mockito.anyString()).thenReturn(mockUrl);
PowerMockito.whenNew(JSONRPC2Session.class).withArguments(Mockito.isA(URL.class)).thenReturn(mockJSONRPC2Session);
Mockito.when(mockJSONRPC2Session.getOptions()).thenReturn(mockOptions);
PowerMockito.whenNew(JSONRPC2Request.class).withParameterTypes(String.class, Map.class, Object.class).withArguments(Mockito.anyString(), Mockito.isA(Map.class), Mockito.any()).thenReturn(mockJSONRPC2Request);
Mockito.when(mockJSONRPC2Session.send(Mockito.isA(JSONRPC2Request.class))).thenThrow(new JSONRPC2SessionException("exception"));
jsonRpcUtils = new JsonRpcUtils();
Object responseObject = jsonRpcUtils.sendJsonRpcRequest(url, responseClass, method, params);
assertThat(responseObject).isNull();
//PowerMockito.verifyNew(URL.class, Mockito.times(1)).withArguments(Mockito.anyString());
//PowerMockito.verifyNew(JSONRPC2Session.class, Mockito.times(1)).withArguments(Mockito.isA(URL.class));
//Mockito.verify(mockJSONRPC2Session, Mockito.times(1)).getOptions();
//PowerMockito.verifyNew(JSONRPC2Request.class, Mockito.times(1)).withArguments(Mockito.anyString(), Mockito.isA(Map.class), Mockito.any());
//Mockito.verify(mockJSONRPC2Session, Mockito.times(1)).send(Mockito.isA(JSONRPC2Request.class));
}
示例14: testSendJsonRpcRequest_SuccessResponse
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的package包/类
@Test
public void testSendJsonRpcRequest_SuccessResponse() throws Exception {
String url = "http://localhost:8080/Identities.php";
Class<?> responseClass = GetEventDataVO.class;
String method = "method1";
Map<String, Object> params = new HashMap<>();
params.put("param1", "value1");
CreateIdentityRequestVO createIdentityRequestVO = ImmutableCreateIdentityRequestVO.builder().setAuth("auth").build();
String responseJson = JsonUtils.convertObjectToJson(GsonUtils.GSON, createIdentityRequestVO);
PowerMockito.mockStatic(JsonUtils.class);
URL mockUrl = PowerMockito.mock(URL.class);
JSONRPC2Session mockJSONRPC2Session = PowerMockito.mock(JSONRPC2Session.class);
JSONRPC2SessionOptions mockOptions = Mockito.mock(JSONRPC2SessionOptions.class);
JSONRPC2Request mockJSONRPC2Request = Mockito.mock(JSONRPC2Request.class);
JSONRPC2Response mockJSONRPC2Response = Mockito.mock(JSONRPC2Response.class);
PowerMockito.whenNew(URL.class).withArguments(Mockito.anyString()).thenReturn(mockUrl);
PowerMockito.whenNew(JSONRPC2Session.class).withArguments(Mockito.isA(URL.class)).thenReturn(mockJSONRPC2Session);
Mockito.when(mockJSONRPC2Session.getOptions()).thenReturn(mockOptions);
PowerMockito.whenNew(JSONRPC2Request.class).withParameterTypes(String.class, Map.class, Object.class).withArguments(Mockito.anyString(), Mockito.isA(Map.class), Mockito.any()).thenReturn(mockJSONRPC2Request);
Mockito.when(mockJSONRPC2Session.send(Mockito.isA(JSONRPC2Request.class))).thenReturn(mockJSONRPC2Response);
Mockito.when(mockJSONRPC2Response.indicatesSuccess()).thenReturn(true);
Mockito.when(mockJSONRPC2Response.getResult()).thenReturn(responseJson);
PowerMockito.when(JsonUtils.convertJsonToObject(Mockito.isA(Gson.class), Mockito.anyString(), Mockito.isA(Class.class))).thenReturn(createIdentityRequestVO);
jsonRpcUtils = new JsonRpcUtils();
Object responseObject = jsonRpcUtils.sendJsonRpcRequest(url, responseClass, method, params);
assertThat(responseObject).isNotNull();
PowerMockito.verifyNew(URL.class, Mockito.times(1)).withArguments(Mockito.anyString());
PowerMockito.verifyNew(JSONRPC2Session.class, Mockito.times(1)).withArguments(Mockito.isA(URL.class));
Mockito.verify(mockJSONRPC2Session, Mockito.times(1)).getOptions();
PowerMockito.verifyNew(JSONRPC2Request.class, Mockito.times(1)).withArguments(Mockito.anyString(), Mockito.isA(Map.class), Mockito.any());
Mockito.verify(mockJSONRPC2Session, Mockito.times(1)).send(Mockito.isA(JSONRPC2Request.class));
Mockito.verify(mockJSONRPC2Response, Mockito.times(1)).indicatesSuccess();
Mockito.verify(mockJSONRPC2Response, Mockito.times(1)).getResult();
}
示例15: testSendJsonRpcRequest_SuccessResponseNullParamsPassed
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; //导入依赖的package包/类
@Test
public void testSendJsonRpcRequest_SuccessResponseNullParamsPassed() throws Exception {
String url = "http://localhost:8080/Identities.php";
Class<?> responseClass = GetEventDataVO.class;
String method = "method1";
Map<String, Object> params = null;
CreateIdentityRequestVO createIdentityRequestVO = ImmutableCreateIdentityRequestVO.builder().setAuth("auth").build();
String responseJson = JsonUtils.convertObjectToJson(GsonUtils.GSON, createIdentityRequestVO);
PowerMockito.mockStatic(JsonUtils.class);
URL mockUrl = PowerMockito.mock(URL.class);
JSONRPC2Session mockJSONRPC2Session = PowerMockito.mock(JSONRPC2Session.class);
JSONRPC2SessionOptions mockOptions = Mockito.mock(JSONRPC2SessionOptions.class);
JSONRPC2Request mockJSONRPC2Request = Mockito.mock(JSONRPC2Request.class);
JSONRPC2Response mockJSONRPC2Response = Mockito.mock(JSONRPC2Response.class);
PowerMockito.whenNew(URL.class).withArguments(Mockito.anyString()).thenReturn(mockUrl);
PowerMockito.whenNew(JSONRPC2Session.class).withArguments(Mockito.isA(URL.class)).thenReturn(mockJSONRPC2Session);
Mockito.when(mockJSONRPC2Session.getOptions()).thenReturn(mockOptions);
PowerMockito.whenNew(JSONRPC2Request.class).withParameterTypes(String.class, Object.class).withArguments(Mockito.anyString(), Mockito.anyString()).thenReturn(mockJSONRPC2Request);
Mockito.when(mockJSONRPC2Session.send(Mockito.isA(JSONRPC2Request.class))).thenReturn(mockJSONRPC2Response);
Mockito.when(mockJSONRPC2Response.indicatesSuccess()).thenReturn(true);
Mockito.when(mockJSONRPC2Response.getResult()).thenReturn(responseJson);
PowerMockito.when(JsonUtils.convertJsonToObject(Mockito.isA(Gson.class), Mockito.anyString(), Mockito.isA(Class.class))).thenReturn(createIdentityRequestVO);
jsonRpcUtils = new JsonRpcUtils();
Object responseObject = jsonRpcUtils.sendJsonRpcRequest(url, responseClass, method, params);
assertThat(responseObject).isNotNull();
PowerMockito.verifyNew(URL.class, Mockito.times(1)).withArguments(Mockito.anyString());
PowerMockito.verifyNew(JSONRPC2Session.class, Mockito.times(1)).withArguments(Mockito.isA(URL.class));
Mockito.verify(mockJSONRPC2Session, Mockito.times(1)).getOptions();
PowerMockito.verifyNew(JSONRPC2Request.class, Mockito.times(1)).withArguments(Mockito.anyString(), Mockito.anyString());
Mockito.verify(mockJSONRPC2Session, Mockito.times(1)).send(Mockito.isA(JSONRPC2Request.class));
Mockito.verify(mockJSONRPC2Response, Mockito.times(1)).indicatesSuccess();
Mockito.verify(mockJSONRPC2Response, Mockito.times(1)).getResult();
}