31
分享会

又一个季度过去了,依照惯例开业务分享会,这次到了个欧洲小镇一般的地方,到处种满了葡萄。

Tagged with:
30

好多年了,google上的gwt资料还是只翻译了一些介绍,想看详细点的东西,还是都是大片英文资料。

Restlet自己做了个gwt的扩展,叫Restlet-GWT module,如果服务器端用restlet,客户端用gwt应该是最合适不过了。

今天尝试了用jquery写个脚本去post,restlet 输出请求http 200状态正常,方法为Options,不是get也不是post,莫名其妙,restlet也不执行任何方法,修改为正常表单提交,服务器端却又输出正常,程序调用也正常。

update:刚发现只是firefox 3.5下是这样

不过在上文提示下,测试了一下,不跨域的情况,是没这个问题,firefox在安全性上比IE严格。

如此,还是少碰gwt吧,便携式的jquery,常规下比gwt好使。

Tagged with:
29

http://twit88.com/blog/2008/07/11/java-json-parser-performance/

JSON-lib比较常用,不过性能比较差,跟帖系统试过几次莫名其妙cpu使用暴涨的现象,换了noggit就没再出现。

Jackson不是太清楚,现在好多人使用json-lib,一般情况没什么问题的,不过为了长远考虑,还是使用noggit吧。

Tagged with:
29

Netvibes也不是不提供运行环境 ,起码还是提供了Exposition Widget Server,不过只是基于php的,没有发现有java的。

相对于opensocial的shindig项目,显得更加脆弱,两者都让人不太放心。

搜索到去年Netvibes承诺opensource,至今不见踪影,定义了UWA,只在自己网站搞,始终不是做平台的,它也就是个做网站的。搜狐的开放平台貌似也逐渐沉寂,精彩实用的widget并不多见,而显然目前平台也只是提供搜狐blog自娱自乐,所谓平台开放只是不切实际的梦想。

27

Rest抽象得不错,把整个网站当成Resource,用post,get,put,delete四种操作来获取更新和删除Resource。

一般开发人员只用过post和get,测试了许久,put跟delete两种操作是搞不定的,有文章用jquery模拟这两种操作,其实还是用post方法,带个method参数叫put/delete。不过http是有这两种操作的,Restlet自带的客户端程序就可以实现:


Client client = new Client(Protocol.HTTP);
Reference itemsUri = new Reference("http://localhost:8182/note");
Form form = new Form();
form.add("name", "test");
Representation rep = form.getWebRepresentation();
Response response = client.put(itemsUri, rep);

服务器端也用Restlet来实现,分别对应四种操作:

实现post


public void acceptRepresentation(Representation entity) throws ResourceException

实现get


public Representation getRepresentation(Variant variant)

实现put


public void storeRepresentation(Representation entity) throws ResourceException

实现delete


public void removeRepresentations() throws ResourceException

先得提供一个方法,这样Restlet才能接收post等方法提交,不然就只有get才能成功。


public boolean isModifiable() {
return true;
}

参数Representation entity可以带入Request的参数:


Form form = new Form(entity);
String subject= form.getFirstValue("subject");
String body= form.getFirstValue("body");

不知道碰到multipart/form-data的表单会不会出问题,上传图片又如何呢?

调用rest的接口,一般采用get方法,带入method参数,例如twitter的rest api:

https://twitter.com/statuses/user_timeline.xml?id=seanwong

json格式:

https://twitter.com/statuses/user_timeline.json?id=seanwong

翻页加参数page=2。

你追随的人的信息:

https://twitter.com/statuses/friends_timeline.xml?id=seanwong

要用post方法模拟put和delete也不难,只需判断多一个参数。

在application构造方法加入


<span>getTunnelService().setMethodParameter(<span>"_method"</span><span>); </span></span>

<span><span>

客户端可以通过_method参数来模拟put和delete

<form name=”form1″ action=”<%=request.getContextPath()%>/resources/users/1?_method=put” method=”POST”>

启动Restlet自带的web服务可以省去web app的配置,写个main就可以启动webserver了:


// Create a new Restlet component and add a HTTP server connector to it
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);

// Then attach it to the local host
component.getDefaultHost().attach(new NotesApplication(component.getContext().createChildContext()));

// Now, let's start the component!
// Note that the HTTP server connector is also automatically started.
component.start();

启动自带的server,测试起来还是比较方便的。

如twitter的链接,可以部署下:


public Restlet createRoot() {
Router router = new Router(this.getContext());

router.attach("/statuses/friends_timeline.xml", XMLResource.class);
router.attach("/statuses/friends_timeline.json", JSONResource.class);

return router;
}

参考:

http://bitworking.org/projects/URI-Templates/

http://ajaxcn.javaeye.com/

http://oracleseeker.com/2008/10/22/extending_restlet_application_support_create_update_resource/

Tagged with:
22

最近在看widget和gadget,想看看怎么来搞这些小页面,我们几年来做了有N个项目,互相调用纠缠不清,使用起来还是很不方便,最多是开放点webservice api给其他项目调用。

嗯,如果有这些小窗口,倒是可以把网站页面定制一下挂在任何地方了。

但我不能用Netvibes,也不能挂在google上,只有自己做容器提供运行平台才行,幸好还有shindig项目,唯一的一线希望。

不过测试结果不是太理想,不知道是不是google上的gadget有限制,跑在我测试环境下,很多gadget显示不正常。开始以为是opensocial版本问题,不过即使编译了最新版本,很多gadget还是一样运行不了。还有个问题,shindig输出的代码太长了,不太精简。

Tagged with:
18
stage play

DSC_0081办公室有鬼第三季:yes or no

看话剧还是比看电影好玩,尤其是这一出搞笑,时尚,加入了许多流行元素的话剧。

Tagged with:
11
food

DSC_0001

DSC_0004

Food I made, they look good, aren’t they?

DSC_0002

Tagged with:
02
new cook

A hai is the new cook when I was not in Beijing.

Tagged with:
preload preload preload