mirror of
https://github.com/didi/KnowStreaming.git
synced 2025-12-24 11:52:08 +08:00
[Bugfix] No thread-bound request found. (#743)
This commit is contained in:
@@ -7,6 +7,9 @@ import com.didiglobal.logi.security.service.OplogService;
|
|||||||
import com.xiaojukeji.know.streaming.km.core.service.oprecord.OpLogWrapService;
|
import com.xiaojukeji.know.streaming.km.core.service.oprecord.OpLogWrapService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class OpLogWrapServiceImpl implements OpLogWrapService {
|
public class OpLogWrapServiceImpl implements OpLogWrapService {
|
||||||
@@ -18,6 +21,12 @@ public class OpLogWrapServiceImpl implements OpLogWrapService {
|
|||||||
@Override
|
@Override
|
||||||
public Integer saveOplogAndIgnoreException(OplogDTO oplogDTO) {
|
public Integer saveOplogAndIgnoreException(OplogDTO oplogDTO) {
|
||||||
try {
|
try {
|
||||||
|
// fix request that cannot find thread binding (issue#743)
|
||||||
|
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
if (null == servletRequestAttributes) {
|
||||||
|
servletRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
|
||||||
|
RequestContextHolder.setRequestAttributes(servletRequestAttributes, true);
|
||||||
|
}
|
||||||
return oplogService.saveOplog(oplogDTO);
|
return oplogService.saveOplog(oplogDTO);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("method=saveOplogAndIgnoreException||oplogDTO={}||errMsg=exception.", oplogDTO, e);
|
log.error("method=saveOplogAndIgnoreException||oplogDTO={}||errMsg=exception.", oplogDTO, e);
|
||||||
|
|||||||
Reference in New Issue
Block a user