All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smilego.tenant.TenantInterceptor Maven / Gradle / Ivy

Go to download

A application used as an example on how to set up pushing its components to the Central Repository.

There is a newer version: 1.2.5
Show newest version
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