How can I change the default RpcRequestBuilder?

I wrote a custom RpcRequestBuilder for authentication, something like this:

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

But I need each RPC GWT service to install my custom builder before using it or, if possible, tell GWT to use my default version. How can i do this?

+3
source share
1 answer
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;
}
+5
source

Source: https://habr.com/ru/post/1782639/


All Articles