mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-23 13:03:42 +08:00
update pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/WebUtils.java.
This commit is contained in:
parent
be9db232e3
commit
d824675168
@ -18,6 +18,7 @@ package com.pig4cloud.pig.common.core.util;
|
|||||||
|
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.pig4cloud.pig.common.core.constant.CommonConstants;
|
||||||
import com.pig4cloud.pig.common.core.exception.CheckedException;
|
import com.pig4cloud.pig.common.core.exception.CheckedException;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
@ -36,7 +37,6 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
|
|||||||
* @param contentType contentType
|
* @param contentType contentType
|
||||||
*/
|
*/
|
||||||
public void renderJson(HttpServletResponse response, Object result, String contentType) {
|
public void renderJson(HttpServletResponse response, Object result, String contentType) {
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding(CommonConstants.UTF8);
|
||||||
response.setContentType(contentType);
|
response.setContentType(contentType);
|
||||||
try (PrintWriter out = response.getWriter()) {
|
try (PrintWriter out = response.getWriter()) {
|
||||||
out.append(JSONUtil.toJsonStr(result));
|
out.append(JSONUtil.toJsonStr(result));
|
||||||
@ -164,7 +164,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public String getClientId(HttpServletRequest request) {
|
public String getClientId() {
|
||||||
if (WebUtils.getRequest().isPresent()) {
|
if (WebUtils.getRequest().isPresent()) {
|
||||||
String header = WebUtils.getRequest().get().getHeader(HttpHeaders.AUTHORIZATION);
|
String header = WebUtils.getRequest().get().getHeader(HttpHeaders.AUTHORIZATION);
|
||||||
return splitClient(header)[0];
|
return splitClient(header)[0];
|
||||||
@ -173,7 +173,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static String[] splitClient(String header) throws UnsupportedEncodingException {
|
private static String[] splitClient(String header) {
|
||||||
if (header == null || !header.startsWith(BASIC_)) {
|
if (header == null || !header.startsWith(BASIC_)) {
|
||||||
throw new CheckedException("请求头中client信息为空");
|
throw new CheckedException("请求头中client信息为空");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user