org.zodiac.autoconfigure.web.embed.EmbedWebappAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.web.embed;
import javax.validation.Validator;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.web.HttpContextProperties;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.web.PrefixHandlerMappingSupport;
import org.zodiac.core.web.embed.EmbedConstants;
import org.zodiac.core.web.embed.SimpleEmbedWebappEndpoint;
@SpringBootConfiguration
@ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_HTTP_CONTEXT_EMBED_WEBAPP_ENABLED, havingValue = "true")
public class EmbedWebappAutoConfiguration extends PrefixHandlerMappingSupport {
private final HttpContextProperties httpContextProperties;
public EmbedWebappAutoConfiguration(ApplicationContext applicationContext,
HttpContextProperties httpContextProperties) {
super(applicationContext);
this.httpContextProperties = httpContextProperties;
}
@Bean(value = EmbedConstants.DEFAULT_SIMPLE_EMBED_WEBAPP_ENDPOINT_BEAN_NAME)
@ConditionalOnMissingBean
public SimpleEmbedWebappEndpoint simpleEmbedWebappEndpoint(Validator validator) {
return new SimpleEmbedWebappEndpoint(validator, httpContextProperties);
}
@Bean
public Object simpleEmbedWebappEndpointPrefixHandlerMapping(SimpleEmbedWebappEndpoint endpoint) {
return super.newPrefixHandlerMapping(httpContextProperties.getEmbed().getBaseUri(), endpoint);
}
}