I'm using the Retrofit library to make client calls. In some environments, I want to encrypt some of my traffic a certain way. In other environments, I don't. Normally I'd do this with a property configuration or a Spring profile, but this code looks like this:
//This is an @Bean method
new RestAdapter.Builder()
.setConverter(new JacksonConverter(this.jacksonObjectMapper))
.setErrorHandler(new RetrofitErrorHandler())
.setLog(new RetrofitLogback())
.setLogLevel(logLevel)
.setEndpoint(host)
.setClient(sslClient()) //sometimes do this, sometimes don't do this
.setLogLevel(RestAdapter.LogLevel.FULL)
.build()
There are many places in our code that conditionally need sslClient() and some that should never use the sslClient. Does Spring have a way to configure this conveniently?
The most naive way to do this is to find all this retrofit setup and wrap some of it in an if statement. But maybe there is a much cleaner way to refactor this code that has nothing to do with Spring.
Aucun commentaire:
Enregistrer un commentaire