天天看点

shindig3 beta2 gadget渲染及bugs

org.apache.shindig.gadgets.servlet.GadgetRenderingServlet负责了gadget iframe内容的渲染工作,/gadgets/ifr请求会转发到此servlet的doGet()方法中。

典型的ifr渲染请求参数如下:

container = 

default

country = 

ALL

lang =  

ALL

mid = 

nocache = 

parent = 

http://localhost:8080/launcher/os/samplecontainer/samplecontainer.html://localhost:8080

r = 

0.9123992353660967

st = 

canonical:john.doe:3929:shindig:http%3A//172.20.95.28/zhaofx/gadgets.nsf/task.xml:0:default

url =  

http://172.20.95.28/zhaofx/gadgets.nsf/task.xml

view

default

1. 其中container指定shindig选择那个container渲染配置,默认是default。在classpath: containers/default/container.js中定义了默认gadgets渲染的参数。看来shindig已经想到了不同的渲染场景,比如,某些igoogle的gadget并不能被默认自带的container渲染,只能由igoogle的 gadgets容器来渲染,我们就可以再定义自己的container配置(可能会有代理到igoogle的配置,这个以后再细看)。

2. lang 制定了gadget被渲染是采用的预研,用这个来选择gadget xml定义的

<Locale messages="http://api.mail.163.com/bearapi/ALL_ALL.xml"/>

<Locale messages="http://api.mail.163.com/bearapi/zh-CN_ALL.xml"/>

本地化字符串文件,最终会讲这些messages文件中的字符串值,在开始渲染前,替换到gadget中。当然,gadget content定义中的字符串替换,要遵循shindig的格式:

<Content type="url" href="__MSG_content_url__" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" /> 其中content_url就是我们定义的属性及字符串名称。

3. st中,john.doe是当前查看用户,canonical是管理员名。这个属性,会被shindig的权限filter进行处理,生成或者加载缓存的已有的authentication,或者被拒绝请求。看org.apache.shindig.auth.AuthenticationServletFilter类doFilter方法。

4. url当然就是gadget的定义xml url.

gadget定义中

<Content type="url" href="__MSG_content_url__" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" />

如果type为html,或者没有指定,GadgetRenderingServlet将会使用org.apache.shindig.gadgets.render.HtmlRenderer.proxyRenderer,使用代理方式在shindig端使用httpClient的方式请求gadget内容,然后将渲染结果返回浏览器。

如果type为url类型,GadgetRenderingServlet会直接返回302跳转,让浏览器自己讲gadget iframe跳转到content href指定的内容。

这两者有个重要的区别,前者采用shindig服务器端代理reader,会导致浏览器本地cookie不能被一起发送到gadget content href指向的服务器,而后者是浏览器跳转的,当然回带上cookie内容。至于后者跳转得到的gadget内容中,是否能调用osapi js全局对象,使用shindig gadget js库,这个问题还需要进一步确认。

org.apache.shindig.gadgets.render.ProxyRenderer.render(Gadget)方法中,我们发现shindig在做gadget content 代理请求的时候,并没有进行cookie拷贝,也没有尝试携带任何的gadget属性和首选项等属性。如果要动态的给content herf传递参数,就不能用cookie,不知道gadget xml规范有没有用属性自动取到cookie值的方式,如果有就可以用属性名拼接href的方式,将cookie传到服务器。

继续阅读