SCA 之Tuscany 8 ——helloworld JSONP和JSONRPC

前端之家收集整理的这篇文章主要介绍了SCA 之Tuscany 8 ——helloworld JSONP和JSONRPC前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、JSONP

1) 什么是JSONP?

JSONP是一个非官方的协议,它允许在服务器端集成Script tags返回至客户端,通过javascript callback的形式实现跨域访问(这仅仅是JSONP简单的实现形式)。

2)Tuscany 如何使用JSONP?

在hello world的基础上做如下的改动(SCA对各协议的支持是很广泛的,都是通过绑定来实现):

(1)增加pom中的依赖文件

      <dependency>
         <groupId>org.apache.tuscany.sca</groupId>
         <artifactId>tuscany-binding-jsonp-runtime</artifactId>
         <version>${tuscany.version}</version>
         <scope>test</scope>
      </dependency>

         <!-- to support running the composite with mvn tuscany:run -->
         <plugin>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-maven-plugin</artifactId>
            <version>${tuscany.version}</version>
      <dependencies>
         <dependency>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-binding-jsonp-runtime</artifactId>
            <version>${tuscany.version}</version>
         </dependency>
      </dependencies>
         </plugin>

(2)更新composite文件来变化绑定协议

    <component name="HelloworldComponent">
        <implementation.java class="sample.HelloworldImpl"/>
        <service name="Helloworld">
           <tuscany:binding.jsonp/>
        </service>
    </component>

测试:



二、JSONRPC

JSON:JavaScript Object Notation,JavaScript对象的一种字面量描述格式,是一种轻量级的数据交换格式。
RPC:Remote procedure call,远程过程(函数方法)调用jsonrpc 依赖 jsonrpc-1.0.jar 文件,以及一个 js文件(jsonrpc.js)

(1)更新POM文件支持JSONRPC jar

      <dependency>
         <groupId>org.apache.tuscany.sca</groupId>
         <artifactId>tuscany-binding-jsonrpc-runtime</artifactId>
         <version>${tuscany.version}</version>
         <scope>test</scope>
      </dependency>

      <dependencies>
         <dependency>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-binding-jsonrpc-runtime</artifactId>
            <version>${tuscany.version}</version>
         </dependency>
      </dependencies>

(2)更新composite

    <component name="HelloworldComponent">
        <implementation.java class="sample.HelloworldImpl"/>
        <service name="Helloworld">
           <tuscany:binding.jsonrpc/>
        </service>
    </component>

(3)

As with all the getting-started samples you can run this sample with: mvn tuscany:run Then at a web browser enter the following URL: (JSON-RPC aruguments are base64 encoded,so in this URL "WyJXb3JsZCJd" unecoded is "["World"]") http://localhost:8080/HelloworldComponent/Helloworld?method=sayHello&params=WyJXb3JsZCJd&id=1 which should return a page saying: {"id":1,"result":"Hello World"}

原文链接:https://www.f2er.com/json/290737.html

猜你在找的Json相关文章