JSON-RPC-Java learning architecture introduction

xiaoxiao2021-03-06  15

JSON-RPC-Java consists of two components that are visualized by users, they are JSONRPCBRIDGE and JSONRPCSERVLET, and the two coordination implements the process of the JSON server to request objects and respond to users. JSONRPCBRIDGE is a session object that has a reference to a reference to a particular client to a particular client. It receives the JSON-RPC request from the server (which is JSONRPCSERVLET), then it will decode JSON object to Java object, and then play a method The role calling, but also transmits the Java object result group code returned by the method to the JSON object to the client processing. The specific transition from the Java object to the JavaScript object is handled by a serialized class Serializer that is responsible for serialization.

JSONRPCBRIDGE must be placed in the httpsession object, and the registration property is named "JSONRPCBRIDGE" so that the JSonrPCServlet can locate the bridge responsible for calling the Java object exported to the client. To do this, in order to export all instances of an object to the client, there should be as follows: Jsonrpcbridge.registerObject ("MyObject", myObject);

In order to export all of the static methods of a class, you should: Jsonrpcbridge.registerClass ("MyObject", myObject);

If registerObject and registerclass are used multiple times to use objects with the same key value, they will be updated by the latest objects.

In JSON, you can also use a single example mode of GlobalBridge to export all instance methods for all HTTP clients. It can be used to register factory classes, but pay attention to certification and security issues when using. Logo as follows: jsonrpcbridge.getglobalbridge (). RegisterObject ("MyObject", myObject); the same equation can also export all static methods.

The most important part of the agreement is the servlet, and now come and simply introduce:

In this agreement, the JSONRPCSERVLET acts as a transmitter, processes the JSON-RPC request over HTTP and distributes them to the JSONRPCBRIDGE instance process registered in HttpSession. Jsonrpcbridge is automatically placed in the session (session) by JSONRPCSERVLET to the session (session), you want to use JSON-RPC-Java, you must modify the Web.xml file as follows:

com.metaparadigm.jsonrpc.jsonrpcservlet com.metaparadigm.jsonrpc.jsonrpcservlet com.metaparadigm.jsonrpc.jsonrpcservlet / json-rpc Of course, for the above configuration file, you can do according to specific needs A certain modification. Next, just write the client JSP code and JS code, and then combine the server-side JAVA program to use the protocol.

转载请注明原文地址:https://www.9cbs.com/read-45982.html

New Post(0)