gwtjax-rserrai

How to change base url endpoint for errai jaxrs proxy?


I' need to call different endpoint located on different server, i try to change value of base url of my rest services.

but i found only this method

 RestClient.create(MyService.class, otherServiceBaseUrl,
            myCallback,               
            200).doStaf() ;

Any suggestion to more elegant way for setup the base url for all services in my MyService class ?


Solution

  • I found this solution. I create a abstract class DinamicCaller.

       public abstract class DinamicCaller<T> {
    
    
        public T call() {
            T call = getCaller().call();
            ((AbstractJaxrsProxy) call).setBaseUrl(getBaseUrl());
            return call;
        }
    
        public T call(RemoteCallback<?> callback) {
            T call = getCaller().call(callback);
            ((AbstractJaxrsProxy) call).setBaseUrl(getBaseUrl());
    
            return call;
        }
    
        public T call(RemoteCallback<?> callback, ErrorCallback<?> errorCallback) {
    
            T call = getCaller().call(callback, errorCallback);
            ((AbstractJaxrsProxy) call).setBaseUrl(getBaseUrl());
    
            return call;
    
        }
    
        protected abstract Caller<T> getCaller();
    
    
        protected abstract String getBaseUrl();
    }
    

    I create a Concrete Class

    public class CallerCORSNegoziService extends DinamicCaller<CORSNegoziService> {
    
        @Inject
        NegozioManager negozioManager;
        @Inject
        Caller<CORSNegoziService> caller;
    
    
        @Override
        protected Caller<CORSNegoziService> getCaller() {
            return caller;
        }
    
        @Override
        protected String getBaseUrl() {
            return negozioManager.getNegozio().getUrl();
        }
    }
    

    On my class I inject the concrete class

    @Inject
    CallerCORSNegoziService service;
    

    And I use it

    @UiHandler("testButton")
    public void testButtonClick(ClickEvent event) {
          service.call(testCallback, testCallback).findAllNegozi();
    }
    

    Is ugly but work.