Commit 35ec20d0 authored by 赵啸非's avatar 赵啸非

添加返回http code 500错误

parent eecfa776
package com.mortals.xhx.base.framework.config; package com.mortals.xhx.base.framework.config;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.mortals.xhx.base.framework.DateJacksonConverter; import com.mortals.xhx.base.framework.DateJacksonConverter;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -24,8 +25,12 @@ public class ConverterConfig { ...@@ -24,8 +25,12 @@ public class ConverterConfig {
@Bean @Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) { public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper); mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
return mappingJackson2HttpMessageConverter; return mappingJackson2HttpMessageConverter;
} }
} }
package com.mortals.xhx.base.framework.config; package com.mortals.xhx.base.framework.config;
import com.mortals.framework.filter.RepeatableFilter;
import com.mortals.framework.filter.XssFilter; import com.mortals.framework.filter.XssFilter;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.framework.filter.RepeatReadHttpRequest; import com.mortals.xhx.base.framework.filter.RepeatReadHttpRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -21,6 +21,7 @@ import java.util.Map; ...@@ -21,6 +21,7 @@ import java.util.Map;
* @author zxfei * @author zxfei
*/ */
@Configuration @Configuration
@Slf4j
public class FilterConfig { public class FilterConfig {
@Value("${xss.enabled}") @Value("${xss.enabled}")
private String enabled; private String enabled;
...@@ -60,7 +61,6 @@ public class FilterConfig { ...@@ -60,7 +61,6 @@ public class FilterConfig {
public static class RequestReplaceFilter implements Filter { public static class RequestReplaceFilter implements Filter {
@Override @Override
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException { public void init(javax.servlet.FilterConfig filterConfig) throws ServletException {
} }
@Override @Override
...@@ -70,6 +70,7 @@ public class FilterConfig { ...@@ -70,6 +70,7 @@ public class FilterConfig {
@Override @Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
log.info("RequestReplaceFilter~~~~~~~~~~~~~~~~~");
filterChain.doFilter(new RepeatReadHttpRequest((HttpServletRequest) servletRequest), servletResponse); filterChain.doFilter(new RepeatReadHttpRequest((HttpServletRequest) servletRequest), servletResponse);
} }
} }
......
package com.mortals.xhx.base.framework.exception; package com.mortals.xhx.base.framework.exception;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -10,6 +14,9 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -10,6 +14,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** /**
* 统一异常处理 * 统一异常处理
*/ */
...@@ -17,6 +24,12 @@ import com.mortals.framework.exception.AppException; ...@@ -17,6 +24,12 @@ import com.mortals.framework.exception.AppException;
@Slf4j @Slf4j
public class ExceptionHandle { public class ExceptionHandle {
@Autowired
private HttpServletRequest request;
@Autowired
private HttpServletResponse response;
public static final String KEY_RESULT_CODE = "code"; public static final String KEY_RESULT_CODE = "code";
public static final String KEY_RESULT_MSG = "msg"; public static final String KEY_RESULT_MSG = "msg";
public static final String KEY_RESULT_DATA = "data"; public static final String KEY_RESULT_DATA = "data";
...@@ -25,6 +38,9 @@ public class ExceptionHandle { ...@@ -25,6 +38,9 @@ public class ExceptionHandle {
@ExceptionHandler(value = Exception.class) @ExceptionHandler(value = Exception.class)
@ResponseBody @ResponseBody
public String handle(Exception e) { public String handle(Exception e) {
log.info("[request url]========{}", request.getRequestURL());
response.getStatus();
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE); ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
if (e instanceof AppException) { if (e instanceof AppException) {
...@@ -33,9 +49,15 @@ public class ExceptionHandle { ...@@ -33,9 +49,15 @@ public class ExceptionHandle {
stack.getClassName(), stack.getMethodName(), stack.getLineNumber(), e.getClass().getName()); stack.getClassName(), stack.getMethodName(), stack.getLineNumber(), e.getClass().getName());
AppException ex = (AppException) e; AppException ex = (AppException) e;
ret.put(KEY_RESULT_MSG, ex.getMessage()); ret.put(KEY_RESULT_MSG, ex.getMessage());
}
if (e instanceof HttpMessageNotReadableException) {
log.error("[system error]", e);
response.setStatus(HttpStatus.HTTP_BAD_REQUEST);
ret.put(KEY_RESULT_MSG, "参数错误,"+ StrUtil.subBefore(e.getMessage(), ";", false));
} else { } else {
log.error("[system error]", e); log.error("[system error]", e);
ret.put(KEY_RESULT_MSG, "未知错误!"); response.setStatus(HttpStatus.HTTP_INTERNAL_ERROR);
ret.put(KEY_RESULT_MSG, "未知错误!" + e.getMessage());
} }
return ret.toJSONString(); return ret.toJSONString();
} }
......
...@@ -13,6 +13,7 @@ spring: ...@@ -13,6 +13,7 @@ spring:
jackson: jackson:
serialization: serialization:
WRITE_DATES_AS_TIMESTAMPS: true WRITE_DATES_AS_TIMESTAMPS: true
fail_on_empty_beans: true
default-property-inclusion: NON_NULL default-property-inclusion: NON_NULL
# time-zone: GMT+8 # time-zone: GMT+8
# date-format: yyyy-MM-dd HH:mm:ss # date-format: yyyy-MM-dd HH:mm:ss
......
...@@ -26,7 +26,7 @@ Content-Type: application/json ...@@ -26,7 +26,7 @@ Content-Type: application/json
{ {
"siteId": 1, "siteId": 1,
"appTypeNotList": [4], "appTypeNotList": [4],
"page": 1, "page": 123123123213123212312231231231,
"size": -1 "size": -1
} }
###自助终端应用列表 ###自助终端应用列表
......
...@@ -158,4 +158,4 @@ Content-Type: application/json ...@@ -158,4 +158,4 @@ Content-Type: application/json
POST {{baseUrl}}/site/getSitesGroupByAreaLevel POST {{baseUrl}}/site/getSitesGroupByAreaLevel
Content-Type: application/json Content-Type: application/json
{"areaLevel":3} {"areaLevel":3,"siteName": "%翠屏区%"}
...@@ -208,13 +208,11 @@ Content-Type: application/x-www-form-urlencoded ...@@ -208,13 +208,11 @@ Content-Type: application/x-www-form-urlencoded
businessid=125&matter=125&devicenum=C0-FB-F9-CD-3B-5D&peopleid=13 businessid=125&matter=125&devicenum=C0-FB-F9-CD-3B-5D&peopleid=13
### 参数列表组合查询 ### 参数列表组合查询
POST {{baseUrl}}/param/list POST {{baseUrl}}/param/interlist
Content-Type: application/json Content-Type: application/json
{ {
"page":1, "page":1,
"size": -1,
"firstOrganize": "Window",
"secondOrganize": "hongqi" "secondOrganize": "hongqi"
} }
......
This diff is collapsed.
...@@ -181,7 +181,6 @@ public class AccessLogFilter implements GlobalFilter, Ordered { ...@@ -181,7 +181,6 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
} }
private void writeAccessLog(AccessLogPdu accessLogPdu) { private void writeAccessLog(AccessLogPdu accessLogPdu) {
// log.info("accessLog:{}",JSON.toJSONString(accessLogPdu));
messageProducer.syncAccessSend(accessLogPdu); messageProducer.syncAccessSend(accessLogPdu);
} }
...@@ -211,8 +210,6 @@ public class AccessLogFilter implements GlobalFilter, Ordered { ...@@ -211,8 +210,6 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
if (contentLength > 0) { if (contentLength > 0) {
httpHeaders.setContentLength(contentLength); httpHeaders.setContentLength(contentLength);
} else { } else {
// TODO: this causes a 'HTTP/1.1 411 Length Required' // on
// httpbin.org
httpHeaders.set(HttpHeaders.TRANSFER_ENCODING, "chunked"); httpHeaders.set(HttpHeaders.TRANSFER_ENCODING, "chunked");
} }
return httpHeaders; return httpHeaders;
...@@ -220,8 +217,6 @@ public class AccessLogFilter implements GlobalFilter, Ordered { ...@@ -220,8 +217,6 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
@Override @Override
public Flux<DataBuffer> getBody() { public Flux<DataBuffer> getBody() {
// log.info("outputMessage.getBody() contentLength:");
return outputMessage.getBody(); return outputMessage.getBody();
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment