如何更改默认的RpcRequestBuilder?

时间:2010-12-29 18:20:22

标签: security gwt

我编写了一个自定义RpcRequestBuilder进行身份验证,非常类似:

http://stuffthathappens.com/blog/2009/12/22/custom-http-headers-with-gwt-rpc

但是我需要每个GWT RPC服务在使用之前设置我的自定义构建器,或者如果可能的话,告诉GWT使用我的版本作为默认值。我怎么能这样做?

1 个答案:

答案 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;
}