Seasar DI Container with AOP

S2Hessianを使うと、Seasar2のコンポーネントをWSDLなしにクライアントから簡単に呼び出す事ができるようになります。JAVAでRich Clientを作る時にはいちいちWSDLを設定する必要がなく、また簡易なプロトコルですのでパフォーマンスも良いと思います。
S2HessianDotNetを使用すれば、C#でSmart Clientを書いて、そこから簡単にSeasar2のコンポーネントを呼び出せます。

セットアップ

Visual Studio 2003で開発しましたが、C#が動けば大丈夫の筈です。
解凍するとnethessian.NETとhessiantestの2つのディレクトリが出来ますの適当な所に置いて下さい。

使い方

Tomcatを起動し、s2hessianが動いていることが前提です。。
hessiantestのForm1のボタンを押すと12のTestCaseが走ります。

Form1のbutton1_Click

下記の様に int,double,Boolean,System.DateTimeや、Hashtable、ArrayListおよび各種 Objectが自由に使用出来ます。
まだ一部動作確認がしていない、Sytem Objectがあります。問題があればコメントをお願いします。
まず下記の様にDotNetProxy を作成します。
DotNetProxy dnp= new DotNetProxy("http://localhost:8080/s2hessian/s2h/");
Method CALLは下記の形式になります。
(return type) dnp.invoke("コンポーネントの名前","メソッド",typeof(return type),メソッドの引数)

C#のクラスとJAVAのクラスの対応を指定するには、2つの方法があります。

  • dnp.setClassConv(typeof(nethessiantest.MyObject1),"org.seasar.s2hessian.example.MyObject");の様に指定
  • [JavaClass("org.seasar.s2hessian.example.MyObject")] の様に CLASSの前に属性で指定
  •     private void button1_Click(object sender, System.EventArgs e)
    {
    textBox1.Text="";
    DotNetProxy dnp= new DotNetProxy("http://localhost:8080/s2hessian/s2h/");

    //Test1
    int resi = (int)dnp.invoke("test","intPlus",typeof(int),300,5);
    textBox1.Text+="Test1 intPlus result: "+resi.ToString()+"\r\n";
         //Test2 Boolean bres=(Boolean)dnp.invoke("test","boolTest",typeof(Boolean),false);
    textBox1.Text+="Test2 boolTest result: " +bres.ToString()+"\r\n";      //Test3
    long lres=(long)dnp.invoke("test","longPlus",typeof(long),385555L,1000000L);
    textBox1.Text+="Test3 longPlus result: " +lres.ToString()+"\r\n";

         //Test4
    double dres=(double)dnp.invoke("test","doublePlus",typeof(double),555.385555,1000000.0);
    textBox1.Text+="Test4 doublePlus result: " +dres.ToString()+"\r\n";

    //Test5
    string sres=(string)dnp.invoke("test","stringCat",typeof(string),"Seaser=","Test");
    textBox1.Text+="Test5 stringCat result: " +sres+"\r\n";

    //Test6
    sres=(string)dnp.invoke("test","dateCheck1",typeof(string),DateTime.Now);
    textBox1.Text+="Test6 dateCheck1 result: " +sres+"\r\n";

      //Test7
    DateTime dtres=(DateTime)dnp.invoke("test","dateCheck2",typeof(DateTime));
    textBox1.Text+="Test7 dateCheck2 result: " +dtres.ToLongDateString()+""
    +dtres.ToLongTimeString()+"\r\n";

    //Test8 int[] it={1,2,3,4,5};
    int[] iares=(int[])dnp.invoke("test","intArray",typeof(int[]),it);
    textBox1.Text+="Test8 intArray result: ";
    for (int i=0;i<iares.Length;i++)
    {
    textBox1.Text+=" "+iares[i].ToString();
    }
    textBox1.Text+="\r\n";

    //Test9
    Hashtable ht=new Hashtable();
    ht.Add("test1",1);
    ht.Add("test2","t2");
    Hashtable htres=(Hashtable)dnp.invoke("test","hashTable",typeof(Hashtable),ht);
    textBox1.Text+="Test9 hashTable result: ";
    textBox1.Text+=" "+htres["test1"].ToString();
    textBox1.Text+=" "+htres["test2"].ToString();
    textBox1.Text+="\r\n";

    //Test10
    ArrayList al=new ArrayList();
    al.Add(100);
    al.Add("t200");
    ArrayList alres=(ArrayList)dnp.invoke("test","arrayList",typeof(ArrayList),al);
    textBox1.Text+="Test10 arrayList result: ";
    textBox1.Text+=" "+alres[0].ToString();
    textBox1.Text+=" "+alres[1].ToString();
    textBox1.Text+="\r\n";

    //Test11
    //dnp.setClassConv("nethessiantest.MyObject1","org.seasar.s2hessian.example.MyObject"); MyObject1 mo=new MyObject1();
    mo.setInt1(100);
    mo.setString1("Seasar");
    MyObject1 mores=(MyObject1)dnp.invoke("test","myObjectTest",typeof(MyObject1),mo);
    textBox1.Text+="Test11 myObjectTest result: ";
    textBox1.Text+=" "+mo.getInt1().ToString();
    textBox1.Text+=" "+mo.getString1().ToString();
    textBox1.Text+="\r\n"; //Test12
    dnp.setClassConv("nethessiantest.MyObject2","org.seasar.s2hessian.example.MyObject2");
    MyObject1 mon=new MyObject1();
    mon.setInt1(200);
    mon.setString1("Seasar3");
    MyObject2 mo2=new MyObject2();
    mo2.setMo1(mon);
    MyObject2 mo2res=(MyObject2)dnp.invoke("test","myObjectTest2",typeof(MyObject2),mo2);
    MyObject1 mofrom2=new MyObject1();
    mofrom2=mo2res.getMo1();
    textBox1.Text+="Test12 myObjectTest2result: ";
    textBox1.Text+=" "+mofrom2.getInt1().ToString();
    textBox1.Text+=" "+mofrom2.getString1().ToString();
    textBox1.Text+="\r\n";
    //Test13
    al=new ArrayList();
    al.Add(mon);
    al.Add(mon);
    ArrayList alres2=(ArrayList)dnp.invoke("test","arrayList",typeof(ArrayList),al);
    textBox1.Text+="Test13 arrayList result: ";
    textBox1.Text+=" "+alres2[0].ToString();
    textBox1.Text+=" "+alres2[1].ToString();
    Boolean bxres=(alres2[0]==alres2[1]);
    textBox1.Text+=" "+bxres.ToString();
    textBox1.Text+="\r\n"; }