io.smilego.tenant.TenantInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multi-tenant-spring-boot-starter Show documentation
Show all versions of multi-tenant-spring-boot-starter Show documentation
A application used as an example on how to set up pushing
its components to the Central Repository.
package io.smilego.tenant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;
public class TenantInterceptor implements WebRequestInterceptor {
@Value("${multitenancy.tenant-header:"+TenantContext.TENANT_HEADER+"}")
private String tenantHeader;
@Override
public void preHandle(WebRequest webRequest) throws Exception {
String tenantId = null;
if (webRequest.getHeader(tenantHeader) != null) {
tenantId = webRequest.getHeader(TenantContext.TENANT_HEADER);
} else {
tenantId = ((ServletWebRequest)webRequest).getRequest().getServerName().split("\\.")[0];
}
TenantContext.setTenantId(tenantId);
}
@Override
public void postHandle(WebRequest webRequest, ModelMap modelMap) throws Exception {
TenantContext.clear();
}
@Override
public void afterCompletion(WebRequest webRequest, Exception e) throws Exception {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy