mmazi / rescu

A lightweight json Rest client utility for JAX-RS
MIT License
65 stars 60 forks source link

ClientConfig#DefaultParamsMap is digested after first call #130

Closed sutra closed 3 years ago

sutra commented 3 years ago

After firs call, the default params are digested, and the follow-up calls are using the digested values in the first call.

I think the defaultParamsMap settings should NOT be updated, and do the digesting in every calls.

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;

import si.mazi.rescu.ClientConfig;
import si.mazi.rescu.ParamsDigest;
import si.mazi.rescu.RestInvocation;
import si.mazi.rescu.RestProxyFactory;

public class ClientConfigTestMain {

    public static void main(String[] args) {
        ClientConfig config = new ClientConfig();

        MyParamsDigest myParamsDigest = new MyParamsDigest();
        config.addDefaultParam(HeaderParam.class, "Authorization", myParamsDigest);

        MySerivce mySerivce = RestProxyFactory.createProxy(MySerivce.class, "", config);

        System.out.println("before: " + config.getDefaultParamsMap());

        // frst call
        try {
            mySerivce.getSomething();
        } catch (Exception e) {
        }

        System.out.println("after first call: " + config.getDefaultParamsMap());

        // second call
        try {
            mySerivce.getSomething();
        } catch (Exception e) {
        }

        System.out.println("after second call: " + config.getDefaultParamsMap());

        // third call
        try {
            mySerivce.getSomething();
        } catch (Exception e) {
        }

        System.out.println("after third call: " + config.getDefaultParamsMap());
    }

}

@Path("/")
interface MySerivce {

    @GET
    void getSomething();

}

class MyParamsDigest implements ParamsDigest {

    private int value = 0;

    @Override
    public synchronized String digestParams(RestInvocation restInvocation) {
        return String.valueOf(++this.value);
    }

}
2021-01-21 13:50:49,692 DEBUG [main] rescu.Config (Config.java:99) - Configuration from rescu.properties:
2021-01-21 13:50:49,695 DEBUG [main] rescu.Config (Config.java:100) - httpConnTimeout = 30000
2021-01-21 13:50:49,695 DEBUG [main] rescu.Config (Config.java:101) - httpReadTimeout = 30000
2021-01-21 13:50:49,695 DEBUG [main] rescu.Config (Config.java:102) - proxyHost = null
2021-01-21 13:50:49,696 DEBUG [main] rescu.Config (Config.java:103) - proxyPort = null
2021-01-21 13:50:49,696 DEBUG [main] rescu.Config (Config.java:104) - proxyType = null
2021-01-21 13:50:49,696 DEBUG [main] rescu.Config (Config.java:105) - ignoreHttpErrorCodes = false
before: {interface javax.ws.rs.HeaderParam=Authorization=MyParamsDigest@79517588}
2021-01-21 13:50:49,791 DEBUG [main] rescu.HttpTemplate (HttpTemplate.java:115) - Executing GET request at /
after first call: {interface javax.ws.rs.HeaderParam=Authorization=1}
2021-01-21 13:50:49,792 DEBUG [main] rescu.HttpTemplate (HttpTemplate.java:115) - Executing GET request at /
after second call: {interface javax.ws.rs.HeaderParam=Authorization=1}
2021-01-21 13:50:49,793 DEBUG [main] rescu.HttpTemplate (HttpTemplate.java:115) - Executing GET request at /
after third call: {interface javax.ws.rs.HeaderParam=Authorization=1}
mmazi commented 3 years ago

Thanks for the test! I'll have a look at this by next week.