HelloDwr bundle

0

源起

想要測試一下 DWR 的功能,為了方便,這個例子是用 DWR2 來測的。

http://getahead.ltd.uk/dwr/getstarted http://getahead.ltd.uk/dwr/server/annotations

建議與 HelloJsp Bundle 交互參考。

src/haha/Component.java

這個物件將使用 LogService 與 HttpService 做一些設定,把原本 WEB-INF/web.xml 的設定改成直接註冊到 HttpService 的做法。

另外一個需要的設定檔的 WEB-INF/dwr.xml 採用 annotation 可以放到 src/haha/HeheBean.java 原始碼中間去,省掉 dwr.xml 檔案載入問題。

....
DwrServlet dwrServlet = new DwrServlet();
Hashtable initparams = new Hashtable();
initparams.put("debug", "true");
initparams.put("classes", HeheBean.class.getCanonicalName());
httpService.registerServlet("/dwr", dwrServlet, initparams,commonContext);
....

src/haha/HeheBean.java

要遠端存取的物件。

package haha;

import org.directwebremoting.annotations.Create;
import org.directwebremoting.annotations.RemoteMethod;

@Create
public class HeheBean {

    private String name;

    @RemoteMethod
    public int getFoo(){
        return 43;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

osgi console

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20061023
1    ACTIVE      HelloDwr_1.0.0
2    ACTIVE      javax.servlet_2.4.0.200609281713
3    ACTIVE      org.apache.commons.logging_1.0.4
4    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
5    ACTIVE      org.eclipse.equinox.http.jetty_1.0.0.v20061012
6    ACTIVE      org.eclipse.equinox.http.servlet_1.0.0.v20061023
7    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
8    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
9    ACTIVE      org.mortbay.jetty_5.1.11.200609281713

開瀏覽器到 http://localhost/index.html 測看看,也可以改點東西玩看看,只要改完在 console 輸入 update 1 就會生效。

Download

為了方便測試,將所有需要的 bundle 包一起,同時還有 HelloDwr 的原始碼,有需要的人可以用 eclipse 3.2 玩看看。

HelloDwr and osgi target platform

觀察

  1. 目前只有 hello 一下,看一下 debug 輸出,沒有測到太多部份。
  2. 試圖將 dwr 獨立成可重複使用的 bundle,沒有成功,因為 dwr 運作時需要載入 HeheBean.class 來讀取 annotation,如何將 HeheBean 變成服務反注入 dwr 還有待練習。

Comments

(leave url/email »)

   Preview comment