package com.qianwen.core.context; import java.util.function.Function; import com.qianwen.core.context.props.BladeContextProperties; import com.qianwen.core.tool.utils.StringUtil; import com.qianwen.core.tool.utils.ThreadLocalUtil; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.http.HttpHeaders; import org.springframework.lang.Nullable; @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) /* loaded from: blade-core-context-9.3.0.0-SNAPSHOT.jar:org/springblade/core/context/BladeServletContext.class */ public class BladeServletContext implements BladeContext { private final BladeContextProperties contextProperties; private final BladeHttpHeadersGetter httpHeadersGetter; public BladeServletContext(final BladeContextProperties contextProperties, final BladeHttpHeadersGetter httpHeadersGetter) { this.contextProperties = contextProperties; this.httpHeadersGetter = httpHeadersGetter; } @Override // org.springblade.core.context.BladeContext @Nullable public String getRequestId() { return get(this.contextProperties.getHeaders().getRequestId()); } @Override // org.springblade.core.context.BladeContext @Nullable public String getAccountId() { return get(this.contextProperties.getHeaders().getAccountId()); } @Override // org.springblade.core.context.BladeContext @Nullable public String getTenantId() { return get(this.contextProperties.getHeaders().getTenantId()); } @Override // org.springblade.core.context.BladeContext @Nullable public String get(String ctxKey) { HttpHeaders headers = (HttpHeaders)ThreadLocalUtil.getIfAbsent("bladeContext", this.httpHeadersGetter::get); if (headers == null || headers.isEmpty()) { return null; } return headers.getFirst(ctxKey); } @Override // org.springblade.core.context.BladeContext @Nullable public T get(String ctxKey, Function function) { String ctxValue = get(ctxKey); if (StringUtil.isBlank(ctxValue)) { return null; } return function.apply(ctxKey); } }