dbflute-flexserver-exampleの実装
前回の続き dbflute-flex-exampleの実装を始めました。 - すらすら はてな
web.xmlの設定
RemotingGatewayを登録しておくこと。
この辺はs2flex2-exampleのweb.xmlを参考に。
<servlet> <servlet-name>gateway</servlet-name> <servlet-class>org.seasar.flex2.rpc.remoting.RemotingGateway</servlet-class> <init-param> <param-name>showGetResponse</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>useSession</param-name> <param-value>true</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <!--(中略)--> <servlet-mapping> <servlet-name>gateway</servlet-name> <url-pattern>/bin/gateway</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>gateway</servlet-name> <url-pattern>/gateway</url-pattern> </servlet-mapping>
サービスの実装。
Flex側で呼び出すServiceを実装する。といっても特に難しいことはなし。
今回はシンプルにMemberIdからMemberを検索するServiceを実装してみる。
まずは サービスのインターフェースを作成する。
特に注意すべき点はなし。
package com.example.dbflute.flex.service; import com.example.dbflute.flex.dbflute.dto.MemberDto; public interface MemberService { public MemberDto selectMemberByMemberId(Integer memberId); }
そしてサービスの実装クラスを作成。
注意すべき点は、クラスの宣言の前に@RemotingServiceアノテーションをつけること。
package com.example.dbflute.flex.service.impl; import org.seasar.flex2.rpc.remoting.service.annotation.RemotingService; import com.example.dbflute.flex.dbflute.dto.MemberDto; import com.example.dbflute.flex.dbflute.exbhv.MemberBhv; import com.example.dbflute.flex.dbflute.exentity.Member; import com.example.dbflute.flex.service.MemberService; @RemotingService public class MemberServiceImpl implements MemberService { MemberBhv memberBhv; public void setMemberBhv(MemberBhv memberBhv) { this.memberBhv = memberBhv; } public MemberDto selectMemberByMemberId(Integer memberId) { final Member entity = memberBhv.selectByPKValueWithDeletedCheck(memberId); MemberDto memberDto = new MemberDto(); memberDto.setMemberId(entity.getMemberId()); memberDto.setMemberName(entity.getMemberName()); memberDto.setMemberAccount(entity.getMemberAccount()); memberDto.setMemberBirthday(entity.getMemberBirthday()); memberDto.setMemberFormalizedDatetime(entity.getMemberFormalizedDatetime()); memberDto.setMemberStatusCode(entity.getMemberStatusCode()); return memberDto; } }
作成したサービスは、S2コンテナされるようなパッケージに配置すること
convention.diconが以下のようになっていれば
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN" "http://www.seasar.org/dtd/components21.dtd"> <components> <component class="org.seasar.framework.convention.impl.NamingConventionImpl"> <initMethod name="addRootPackageName"> <arg>"com.example.dbflute.flex"</arg> </initMethod> </component> </components>
サービスとその実装クラスのパッケージは
にすれば良い。
あとはサービスは実装した時点でテストケースを書いておく。Flex側ではテストコードが書きにくいので。