1 package cn.home1.oss.lib.webmvc.internal;
2
3 import static lombok.AccessLevel.PACKAGE;
4
5 import lombok.Getter;
6 import lombok.Setter;
7
8 import javax.servlet.http.HttpServletRequest;
9
10 import cn.home1.oss.lib.webmvc.api.DomainResolver;
11
12
13
14
15 @Getter
16 @Setter(PACKAGE)
17 public class DefaultDomainResolver implements DomainResolver {
18
19 private String domain;
20 private Boolean prodEnvironment;
21
22 public DefaultDomainResolver(final String domain, final Boolean prodEnvironment) {
23 this.domain = domain != null ? domain : "";
24 this.prodEnvironment = prodEnvironment;
25 }
26
27 @Override
28 public String resolveDomain(final HttpServletRequest request) {
29 final String serverName = request.getServerName();
30 final String domain;
31 if (this.domain.equals(serverName) || !this.prodEnvironment) {
32
33
34 domain = "";
35 } else {
36 domain = this.domain;
37 }
38 return domain;
39 }
40 }