我编写了一个自定义RpcRequestBuilder进行身份验证,非常类似:
http://stuffthathappens.com/blog/2009/12/22/custom-http-headers-with-gwt-rpc
但是我需要每个GWT RPC服务在使用之前设置我的自定义构建器,或者如果可能的话,告诉GWT使用我的版本作为默认值。我怎么能这样做?
答案 0 :(得分:5)
public static final UtilServiceAsync getInstance() {
if (instance == null) {
instance = (UtilServiceAsync) GWT.create(UtilService.class);
ServiceDefTarget target = (ServiceDefTarget) instance;
RpcRequestBuilder reqBuilder = new RpcRequestBuilder() {
@Override
protected RequestBuilder doCreate(String serviceEntryPoint) {
RequestBuilder rb = super.doCreate(serviceEntryPoint);
rb.setHeader("HEADER_SIGNATURE", "your token");
return rb;
}
};
target.setRpcRequestBuilder(reqBuilder);
//target.setServiceEntryPoint(GWT.getModuleBaseURL() + "springGwtServices/" + "utilService");
}
return instance;
}