SCA 之Tuscany 8 ——helloworld JSONP和JSONRPC
一、JSONP1) 什么是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对象的一种字面量描述格式,是一种轻量级的数据交换格式。 (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¶ms=WyJXb3JsZCJd&id=1 which should return a page saying: {"id":1,"result":"Hello World"} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |