Merge pull request #13656 from dataease/pr@dev@fix_dynamic_context_path
fix(X-Pack): 设置动态访问路径后导出pdf失败 #12945
This commit is contained in:
commit
ab95605cc3
@ -2,7 +2,11 @@ package io.dataease.commons.utils;
|
|||||||
|
|
||||||
import io.dataease.commons.constants.AuthConstants;
|
import io.dataease.commons.constants.AuthConstants;
|
||||||
import io.dataease.plugins.common.util.SpringContextUtil;
|
import io.dataease.plugins.common.util.SpringContextUtil;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -10,8 +14,18 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class ServletUtils {
|
public class ServletUtils {
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static String contextPath;
|
||||||
|
|
||||||
|
@Value("${server.servlet.context-path:#{null}}")
|
||||||
|
public void setContextPath(String contextPath) {
|
||||||
|
ServletUtils.contextPath = contextPath;
|
||||||
|
}
|
||||||
|
|
||||||
public static HttpServletRequest request() {
|
public static HttpServletRequest request() {
|
||||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||||
@ -48,8 +62,7 @@ public class ServletUtils {
|
|||||||
}
|
}
|
||||||
Environment environment = SpringContextUtil.getBean(Environment.class);
|
Environment environment = SpringContextUtil.getBean(Environment.class);
|
||||||
Integer port = environment.getProperty("server.port", Integer.class);
|
Integer port = environment.getProperty("server.port", Integer.class);
|
||||||
return "http://" + hostAddress + ":" + port;
|
return "http://" + hostAddress + ":" + port + (StringUtils.isBlank(contextPath) ? "" : contextPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,8 +30,6 @@ public class IndexController {
|
|||||||
@Resource
|
@Resource
|
||||||
private PanelLinkService panelLinkService;
|
private PanelLinkService panelLinkService;
|
||||||
|
|
||||||
@Value("${server.servlet.context-path:#{null}}")
|
|
||||||
private String contextPath;
|
|
||||||
|
|
||||||
@GetMapping(value = "/")
|
@GetMapping(value = "/")
|
||||||
public String index() {
|
public String index() {
|
||||||
@ -56,6 +54,7 @@ public class IndexController {
|
|||||||
} else {
|
} else {
|
||||||
url = panelLinkService.getUrlByUuid(index);
|
url = panelLinkService.getUrlByUuid(index);
|
||||||
}
|
}
|
||||||
|
String contextPath = ServletUtils.getContextPath();
|
||||||
if (StringUtils.isNotBlank(contextPath)) {
|
if (StringUtils.isNotBlank(contextPath)) {
|
||||||
url = contextPath + url;
|
url = contextPath + url;
|
||||||
}
|
}
|
||||||
@ -85,6 +84,7 @@ public class IndexController {
|
|||||||
@GetMapping("/tempMobileLink/{id}/{token}")
|
@GetMapping("/tempMobileLink/{id}/{token}")
|
||||||
public void tempMobileLink(@PathVariable("id") String id, @PathVariable("token") String token) {
|
public void tempMobileLink(@PathVariable("id") String id, @PathVariable("token") String token) {
|
||||||
String url = "/#preview/" + id;
|
String url = "/#preview/" + id;
|
||||||
|
String contextPath = ServletUtils.getContextPath();
|
||||||
if (StringUtils.isNotBlank(contextPath)) {
|
if (StringUtils.isNotBlank(contextPath)) {
|
||||||
url = contextPath + url;
|
url = contextPath + url;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,8 +36,7 @@ public class PanelLinkService {
|
|||||||
private static final String USERPARAM = "&user=";
|
private static final String USERPARAM = "&user=";
|
||||||
private static final String SHORT_URL_PREFIX = "/link/";
|
private static final String SHORT_URL_PREFIX = "/link/";
|
||||||
|
|
||||||
@Value("${server.servlet.context-path:#{null}}")
|
|
||||||
private String contextPath;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PanelLinkMapper mapper;
|
private PanelLinkMapper mapper;
|
||||||
@ -281,6 +280,7 @@ public class PanelLinkService {
|
|||||||
List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example);
|
List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example);
|
||||||
PanelLinkMapping mapping = mappings.get(0);
|
PanelLinkMapping mapping = mappings.get(0);
|
||||||
String uuid = mapping.getUuid();
|
String uuid = mapping.getUuid();
|
||||||
|
String contextPath = ServletUtils.getContextPath();
|
||||||
return (StringUtils.isNotBlank(contextPath) ? contextPath : "") + SHORT_URL_PREFIX + (StringUtils.isBlank(uuid) ? mapping.getId() : uuid);
|
return (StringUtils.isNotBlank(contextPath) ? contextPath : "") + SHORT_URL_PREFIX + (StringUtils.isBlank(uuid) ? mapping.getId() : uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user