经过多次交流后,我们终于找到了一个解决方案,并且我想分享给大家以便帮助其他人。
首先,我必须提到Colin Alworth的帮助,没有他的支持,这个解决方案是不可能的。
同时,我也要提到我对最终解决方案并不是很自豪,但它对我们有效,并且目前是我们最好的选择。
最终我们所做的是,如Colin在上一篇文章中所述,将每个服务接口的GWT.create替换为创建GenericBigService接口。
所以我们的第一个补丁如下:
1)创建GenericBigService接口,它继承了所有服务接口(目前有52个接口),并创建它的Async兄弟。我们通过一个phytom脚本完成了这个操作。
因此,我们的GenericBigInterface看起来像这样:
package com.arballon.gwt.core.client;
import com.google.gwt.user.client.rpc.RemoteService;
public interface GenericBigService extends RemoteService,
AccountingService,
ActionClassifierService,
AFIPWebService,
AnalyticalService,
AuthorizationService,
BudgetService,
BusinessUnitService,
CatalogPartService,
CategoryService,
ClientDepositService,
.....
.....
{ }
2) 每个服务接口中都有一个Util内部静态类,用于实例化异步实例,在其中我们将GWT.create替换为创建GenericBigInterface。
因此,我们的某个服务接口如下所示:
public interface FinancialPeriodBalanceCategoryService extends RemoteService {
public static class Util {
private static FinancialPeriodBalanceCategoryServiceAsync instance;
public static FinancialPeriodBalanceCategoryServiceAsync getInstance() {
if (instance == null) {
instance = GWT.create(GenericBigService.class);
((ServiceDefTarget)instance).setServiceEntryPoint(GWT.getModuleBaseURL()+"FinancialPeriodBalanceCategoryService");
}
return instance;
}
}
我们需要进行serServiceEntyPoint调用,以保持我们的web.xml不被修改。
当我们第一次编译时,它能够成功编译,但在运行时,服务器调用会抛出异常。
IncompatibleRemoteServiceException Blocked attempt to access interface GenericBigService
“
”是由FinancialPeriodBalanceCategoryService未实现的。
没错,我们正在使用一个没有实现的接口调用服务,这就是问题出现的地方。目前我们还没有找到更好的解决方案,所以我们决定实现以下方法:
我们将RPC.java替换为自己的副本,并进行以下代码更改:
在decodeRequest方法中,我们做了以下更改:
if (type != null) {
if (!implementsInterface(type, serviceIntfName)) {
if(!serviceIntfName.contains("GenericBigService")){
throw new IncompatibleRemoteServiceException(
"Blocked attempt to access interface '" + serviceIntfName
+ "', which is not implemented by '" + printTypeName(type)
+ "'; this is either misconfiguration or a hack attempt");
}
}
这样做的好处有:
1)我们花了1小时20分钟来完成6个排列,现在只需要20分钟。
2)在devMode中,所有操作都开始变得更快了。启动保持不变,但是一旦开始执行,速度就非常快。
3)编译大小减少是另一个有趣的结果,我们将剩余的片段从6MB减少到1.2MB,整个JS编译的大小减少了约50%至60%。
我们对GWT-RPC感到非常满意,不想放弃它,但是typeSerializers确实是一个问题,主要是由于生成的JS文件过大。
这种解决方案不太优雅,但它可以很好地工作。
再次感谢Colin的帮助!
祝好,
Daniel