Tapestry4になって、Engine Serviceの記述方法ががらっと変わりました。
Tapestry3では、application specificationに記述をしましたが、Tapestry4では、HiveMindに設定をします。
以下の設定では、dataSqueezerや、Engine Service内でVisitオブジェクトを使用したいため、サービスを追加しています。
hivemodule.xml
<contribution configuration-id="tapestry.state.ApplicationObjects"> <state-object name="AppVisit" scope="session"> <create-instance class="jp.co.taosoftware.tagraw.tape.AppVisit" /> </state-object> </contribution> <contribution configuration-id="tapestry.services.ApplicationServices"> <service name="SessionService" object="service:SessionService"/> </contribution> <service-point id="SessionService" interface="org.apache.tapestry.engine.IEngineService"> <invoke-factory> <construct class="jp.co.taosoftware.tagraw.service.SessionService"> <set-object property="exceptionReporter" value="infrastructure:requestExceptionReporter"/> <set-object property="response" value="infrastructure:response"/> <set-object property="linkFactory" value="infrastructure:linkFactory"/> <set-object property="dataSqueezer" value="infrastructure:dataSqueezer"/> <set-service property="appStateMgr" service-id="tapestry.state.ApplicationStateManager"/> </construct> </invoke-factory> </service-point>
SessionService.java
public class SessionService extends BaseEngine implements IEngineService { public static final String SERVICE_NAME = "SessionService"; /** @since 4.0 */ private RequestExceptionReporter _exceptionReporter; private LinkFactory _linkFactory; private WebResponse _response; //Inject private DataSqueezer squeezer; private ApplicationStateManager appStateMgr; public String getName() { return SERVICE_NAME; } public ILink getLink(boolean aPost, Object parameter) { Mapparameters = new HashMap (); parameters.put(ServiceConstants.SERVICE, getName()); return _linkFactory.constructLink(this, false, parameters, true); } public void service(IRequestCycle aCycle) throws IOException { String outString = "OK"; AppVisit visit = (AppVisit)getAppStateMgr().get("AppVisit"); OutputStream output = _response.getOutputStream(new ContentType("text/html")); output.write(outString.getBytes()); } public DataSqueezer getDataSqueezer() { return this.squeezer; } public void setDataSqueezer(DataSqueezer aSqueezer) { this.squeezer = aSqueezer; } public UserFacade getUserFacade() { return this.userFacade; } public void setUserFacade(UserFacade aUserFacade) { this.userFacade = aUserFacade; } public ApplicationStateManager getAppStateMgr() { return this.appStateMgr; } public void setAppStateMgr(ApplicationStateManager aAppStateMgr) { this.appStateMgr = aAppStateMgr; } public IAuthenticateStrategy getAuthenticateStrategy() { return this.authenticateStrategy; } public void setAuthenticateStrategy(IAuthenticateStrategy aAuthenticateStrategy) { this.authenticateStrategy = aAuthenticateStrategy; } /** @since 4.0 */ public void setExceptionReporter(RequestExceptionReporter exceptionReporter) { _exceptionReporter = exceptionReporter; } /** @since 4.0 */ public void setLinkFactory(LinkFactory linkFactory) { _linkFactory = linkFactory; } /** @since 4.0 */ public void setResponse(WebResponse response) { _response = response; } public RequestExceptionReporter get_exceptionReporter() { return this._exceptionReporter; } }
実際には、getLinkのparameterのセットや、serviceメソッドを上記ソースコードに記述していくことになります。
http://localhost:8080/tagraw/app?service=SessionServiceにアクセスをすると、serviceメソッドが呼び出されます。
コメントを残す
コメントを投稿するにはログインしてください。