私が「 Addition Service」と呼んでいるものを実行する次の Java サーブレットがあります。
public class AdditionService extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
// The request will have 2 Integers inside its body that need to be
// added together and returned in the response.
Integer addend = extractAddendFromRequest(request);
Integer augend = extractAugendFromRequest(request);
Integer sum = addend + augend;
PrintWriter writer = response.getWriter();
writer.write(sum);
}
}
と を使用して GWT の RequestFactory に同じこと (アプリ サーバーで 2 つの数値を追加し、合計を応答として返す) を実行させようとしていますValueProxy
がAdditionService
、いくつかの問題が発生しています。
AdditionRequest
追加される 2 つの整数を保持する値オブジェクトである (クライアント層) を次に示します。
// Please note the "tier" (client, shared, server) I have placed all of my Java classes in
// as you read through the code.
public class com.myapp.client.AdditionRequest {
private Integer addend;
private Integer augend;
public AdditionRequest() {
super();
this.addend = 0;
this.augend = 0;
}
// Getters & setters for addend/augend.
}
次に私のプロキシ(クライアント層):
@ProxyFor(value=AdditionRequest.class)
public interface com.myapp.client.AdditionRequestProxy extends ValueProxy {
public Integer getAddend();
public Integer getAugend();
public void setAddend(Integer a);
public void setAugend(Integer a);
}
次のサービス API (共有層):
@Service(value=DefaultAdditionService.class)
public interface com.myapp.shared.AdditionService extends RequestContext {
Request<Integer> sum(AdditionRequest request);
}
次に、リクエスト ファクトリ (共有層):
public class com.myapp.shared.ServiceProvider implements RequestFactory {
public AdditionService getAdditionService() {
return new DefaultAdditionService();
}
// ... but since I'm implementing RequestFactory, there's about a dozen
// other methods GWT is forcing me to implement: find, getEventBus, fire, etc.
// Do I really need to implement all these?
}
最後に、魔法が起こる場所 (サーバー層):
public class com.myapp.server.DefaultAdditionService implements AdditionService {
@Override
public Request<Integer> sum(AdditionRequest request) {
Integer sum = request.getAddend() + request.getAugend();
return sum;
}
// And because AdditionService extends RequestContext there's another bunch of
// methods GWT is forcing me to implement here: append, create, isChanged, etc.
// Do I really need to implement all these?
}
ここに私の質問があります:
- 私の「ティア」戦略は正しいですか?すべてのタイプを正しいクライアント/共有/サーバー パッケージにパッケージ化しましたか?
AdditionService
サーバー上にある(共有の)参照DefaultAdditionService
が実行されるべきではないため、セットアップが正しいとは思いません。共有型は、クライアントとサーバーの両方に存在できる必要がありますが、どちらにも依存してはなりません...
ServiceProvider
を実装するクラスにする必要がありますか、それともそれを拡張RequestFactory
するインターフェイスにする必要がありますか? 後者の場合、どこでimpl を定義すればよいのでしょうか? また、それを他のすべてのクラスにリンクするにはどうすればよいでしょうか?ServiceProvider
ServiceProvider
とのこれらすべてのメソッドはDefaultAdditionService
どうですか? これらの 20 以上のコア GWT メソッドをすべて実装する必要がありますか? それとも、API の使い方が間違っているのでしょうか、それとも簡単に使えないのでしょうか?- ここでサービスロケーターはどこに影響しますか? どのように?