JSON:JavaScript Object Notation,JavaScript对象的一种字面量描述格式,是一种轻量级的数据交换格式。
RPC:Remote procedure call,远程过程(函数、方法)调用。
jsonrpc 依赖 jsonrpc-1.0.jar 文件,以及一个 js文件(jsonrpc.js)
(1)web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
<!--注册配置的Bean对象-->
org.jsonrpc.service.RegistServiceToJsonrpcBridgeListener
</listener-class>
</listener>
<servlet>
<servlet-name>JSONRPCServlet</servlet-name>
<servlet-class>
com.metaparadigm.jsonrpc.JSONRPCServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>JSONRPCServlet</servlet-name>
<url-pattern>/JSON-RPC</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file> index.html </welcome-file>
</welcome-file-list>
</web-app>
(2)jsonrpc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd ">
<bean name="jsonrpcServiceConfigurer"
class="org.jsonrpc.service.spring.JsonrpcServiceConfigurer">
<property name="services">
<map>
<entry key="helloWorld">
<ref bean="helloWorld" />
</entry>
</map>
</property>
</bean>
</beans>
(3)applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd ">
<import resource="jsonrpc.xml"/>
<bean id="helloWorld"
class="com.logcd.service.impl.HelloWorldImpl">
</bean>
</beans>
(4)HelloWorld.java和HelloWorldImpl.java
public interface HelloWorld {
public String sayHelloWorld(String name);
}
public class HelloWorldImpl implements HelloWorld{
public String sayHelloWorld(String name) {
return "Hello World! hello, " + name;
}
}
(5)调用
<script type="text/javascript" src="script/jsonrpc.js"></script><script>
var jsonrpc = null;
//初始化JSONRpcClient对象
jsonrpc = new JSONRpcClient("JSON-RPC");
function jsonrpcHello(){
var name = "阿花!";
var result = jsonrpc.helloWorld.sayHelloWorld(resultCallback,name);
}
function resultCallback(result, e){
alert("The server replied: " + result);
}
</script>
分享到:
相关推荐
scrapy-jsonrpc, Scrapy对使用 JSON RPC控制spider的扩展 爬虫 jsonrpcScrapy jsonrpc是一个扩展,通过 json rpc控制一个正在运行的爬虫网络爬虫。 服务通过协议提供对Crawler对象的访问。安装使用 pip 安装 scrapy-...
JsonRPC, 简单的Json RPC PHP客户机/服务器只 JsonRPC PHP客户端和服务器一个简单的json rpc客户机/服务器。 特性仅限 json rpc 2.0服务器支持批处理请求和通知基于身份验证和IP的客户端限制自定义中间件完全单元...
jsonrpc-c-master 基于 json rpc 1.0 纯C开发的服务端代码和示例
<artifactId>jsonrpc4j <version>1.5.0 <groupId>javax.portlet <artifactId>portlet-api <version>2.0 Service代码: @JsonRpcService("/member") public interface MemberService { ... } 因为是基于...
jsonRPC.rar 是jsonRPC的入门案例,供参考来快速使用jsonRPC,不好勿喷
jsonrpc-frontend:前端应用程序发送 json-rpc 请求进行测试
jsonrpc是一个基于Java的高性能开源RPC框架
jsonrpc-服务器jsonrpc-server 演示了如何使用编码通过 HTTP 为 RPC 方法提供服务。用法安装 go install github.com/kelseyhightower/jsonrpc-server启动 jsonrpc 服务器: jsonrpc-server使用 curl 进行 RPC 调用 ...
特征在网络套接字上使用jsonrpc调用您的QObjects。服务器使用率要创建提供一种将两个数字相加的方法的服务,只需创建一个以该方法为插槽的QObject。 class MyService : QObject{ Q_OBJECTpublic slots: inline int ...
非常适合java springboot好用的jsonrpc服务。 客户端调用: Content-Type:application/json {"id":"1","jsonrpc":"2.0","method":"multiplier","params":[5,8]} 服务端返回:{ "jsonrpc": "2.0", "id": "1", ...
zeromq-jsonrpc-example 在 zeromq 上使用 jsonrpc 的示例和实验 run app-brokerrun 3 instances of app -p 5560run the ruby file to to hit the load balanced rpc servers, client will show which server is ...
jsonrpc4j-1.0.jar jsonrpc
安装npm install express-jsonrpc2使用var path = require('path'), express = require('express'), app = express(); var JsonRPC = require('express-jsonrpc2'), PropTypes = JsonRPC....
jsonRPC java远程调用(请求) 返回json
JsonRpc-Cpp - JSON-RPC implementation. * Copyright (C) 2008-2011 Sebastien Vincent * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser ...
json rpc 测试工具 (test-jsonrpc)
在网络上搜到整理的,我用这个ajax jsonrpc包实现了在当前页面判断用户是否存在。
import fastapi_jsonrpc as jsonrpc from pydantic import BaseModel from fastapi import Body app = jsonrpc . API () api_v1 = jsonrpc . Entrypoint ( '/api/v1/jsonrpc' ) class MyError ( jsonrpc . Base...
android-json-rpc是一个在android程序中使用的JSON-RPC客户端类库。它提供了一个简单的API来执行JSON-RPC服务调用