<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Extreme Pattern: HelloDwr bundle</title>
    <link>http://blog.extremepattern.com/articles/2006/10/27/hellodwr-bundle</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>enjoy</description>
    <item>
      <title>HelloDwr bundle</title>
      <description>&lt;h3&gt;源起&lt;/h3&gt;


	&lt;p&gt;想要測試一下 &lt;span class="caps"&gt;DWR&lt;/span&gt; 的功能，為了方便，這個例子是用 &lt;span class="caps"&gt;DWR2&lt;/span&gt; 來測的。&lt;/p&gt;


	&lt;p&gt;http://getahead.ltd.uk/dwr/getstarted
http://getahead.ltd.uk/dwr/server/annotations&lt;/p&gt;


	&lt;p&gt;建議與 &lt;a href="/articles/2006/10/26/hellojsp-bundle"&gt;HelloJsp Bundle&lt;/a&gt;  交互參考。&lt;/p&gt;


	&lt;h3&gt;src/haha/Component.java&lt;/h3&gt;


	&lt;p&gt;這個物件將使用 LogService 與 HttpService 做一些設定，把原本 &lt;span class="caps"&gt;WEB&lt;/span&gt;-INF/web.xml 的設定改成直接註冊到 HttpService 的做法。&lt;/p&gt;


	&lt;p&gt;另外一個需要的設定檔的 &lt;span class="caps"&gt;WEB&lt;/span&gt;-INF/dwr.xml  採用 annotation 可以放到 src/haha/HeheBean.java 原始碼中間去，省掉 dwr.xml 檔案載入問題。&lt;/p&gt;


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

	&lt;h3&gt;src/haha/HeheBean.java&lt;/h3&gt;


	&lt;p&gt;要遠端存取的物件。&lt;/p&gt;


&lt;pre&gt;
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;
    }
}
&lt;/pre&gt;

	&lt;h3&gt;osgi console&lt;/h3&gt;


&lt;pre&gt;
osgi&amp;gt; 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

&lt;/pre&gt;

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


	&lt;h3&gt;Download&lt;/h3&gt;


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


	&lt;p&gt;&lt;img src="/files/archive.png" alt="" /&gt; &lt;a href="/files/HelloDwr-with-target-2006-1027.zip"&gt;HelloDwr and osgi target platform&lt;/a&gt;&lt;/p&gt;


	&lt;h3&gt;觀察&lt;/h3&gt;


	&lt;ol&gt;
	&lt;li&gt;目前只有 hello 一下，看一下 debug 輸出，沒有測到太多部份。&lt;/li&gt;
		&lt;li&gt;試圖將 dwr 獨立成可重複使用的 bundle，沒有成功，因為 dwr 運作時需要載入 HeheBean.class 來讀取 annotation，如何將 HeheBean 變成服務反注入 dwr 還有待練習。&lt;/li&gt;
	&lt;/ol&gt;</description>
      <pubDate>Fri, 27 Oct 2006 03:25:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:1a468af7-5c04-443b-9d22-f6d799704ebe</guid>
      <author>LIN</author>
      <link>http://blog.extremepattern.com/articles/2006/10/27/hellodwr-bundle</link>
      <category>eclipse</category>
      <category>java</category>
    </item>
  </channel>
</rss>

