mkopylec / charon-spring-boot-starter

Reverse proxy implementation in form of a Spring Boot starter.
Apache License 2.0
245 stars 55 forks source link

charon.mappings not getting updated when using MappingProvider #35

Closed markusmoormann closed 6 years ago

markusmoormann commented 6 years ago

I'm just testing around with your library and realized that it seems not to work when using a MappingProvider

@Component
@EnableConfigurationProperties(CharonProperties::class, ServerProperties::class)
class ProxyMappingProvider(server: ServerProperties,
                           charon: CharonProperties,
                           mappingsCorrector: MappingsCorrector,
                           clientProvider: HttpClientProvider) :
        MappingsProvider(server, charon, mappingsCorrector, clientProvider) {

    override fun shouldUpdateMappings(p0: HttpServletRequest?): Boolean {
        return true
    }

    override fun retrieveMappings(): List<MappingProperties> {
        val mappingProperties = MappingProperties()
        mappingProperties.name = "test"
        mappingProperties.path = "test"
        mappingProperties.destinations = listOf("https://google.de")
        return listOf(mappingProperties)
    }
}

This doesn't work because after retrieving the new mappings httpClientProvider.updateHttpClients(); is called which iterates ofter the mappings in the CharonProperties. So before updating the HttpClients the CharonProperties need to be informed over the new settings. I've prepared a patch for this

mkopylec commented 6 years ago

Thanks for spotting the bug. I'm strugling if we should or should not update CharonProperties with the new mappings values. Maybe CharonProperties should always represent the yml file configuration and therefore not be changed after mappings update. I've created an alternative fix for the bug: https://github.com/mkopylec/charon-spring-boot-starter/pull/37 What do you think about it?

mkopylec commented 6 years ago

Fixed in 2.1.1