shindig功能接口新增以及调用.doc_第1页
shindig功能接口新增以及调用.doc_第2页
shindig功能接口新增以及调用.doc_第3页
shindig功能接口新增以及调用.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Shindig新增功能接口作者:G1创建功能接口处理类(handler),为了结构同一,尽量在org.apache.shindig.social.opensocial.service包中创建2在类前加上以下标注Service(name = appscore, path = /userId+/groupId/appId),其中name为注册的请求地址,path为参数路径,括号有“+”表示为必选参数。3为handler创建构造器private final AppScoreService service;Injectpublic AppScoreHandler(AppScoreService service) this.service = service;并且声明处理类,在构造器前加Inject注释,让Guice加载时注入4新增方法返回值为Future类型,抛出ProtocolException添加注释Operation(httpMethods = POST, bodyParam = data)httoMethods为http请求类型,body为可选项,用来规定传入数据体名称opensocial标准中,查询httpMethods=GET,创建httpMethods=POST,更新httpMethods=PUT,删除httpMethods=DELETEbodyParam在handler中,可以通过Map map = request.getTypedParameter(data, Map.class);方式获得5在org.apache.shindig.social.core.config.SocialApiGuiceModule类中的protected SetClass getHandlers() return ImmutableSet.Class of(ActivityHandler.class, AppScoreHandler.class, AppDataHandler.class, PersonHandler.class, MessageHandler.class, AlbumHandler.class, MediaItemHandler.class);处添handler处理类6创建Services Interface,规定实现类的方法以及参数目前测试发现,通过js的rpc调用shindig新增功能接口时,不需要新增服务端js代码调用例子: !CDATA function render(myobject) alert(myobject.value); gadgets.window.adjustHeight(); function onload() var getParams = userId: viewer, myParam: this is a example; osapi.appscore.get(getParams).execute(render); gadgets.util.registerOnLoadHandler(onload); 测试1 REST基于json数据格式调用例子:public class Test public static void main(String args) throws Exception send(URL);private static final String URL = http:/app.i8169.local/rest/appscore/me;public static void send(String url) throws Exception HttpURLConnection conn = null;try URL u = new URL(url);conn = (HttpURLConnection) u.openConnection();conn.setDoOutput(true);conn.setDoInput(true);conn.setRequestMethod(PUT);conn.setRequestProperty(Content-type,application/json); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream();String str = a:d;out.write(str);out.flush();out.close();InputStream input = conn.getInputStream();byte b = new byteinput.available();input.read(b);System.out.println(new String(b);conn.disconnect(); catch (Exception e) e.printStackTrace(); finally if (conn != null) conn = null;注意调用的时候,需要设置Content-typeconn.setRequestProperty(Content-type,application/json);用来规定参数格式类型,目前shindig支持以下格式类型application/json, text/x-json, application/javascript, application/x-javascript, text/javascript, text/ecmascript, application/json-rpc, application/jsonrequest, text/xml, application/xml, application/atom+xml如果shindig发布在tomcat下,需要修改的tomcat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论