mirror of
https://github.com/didi/KnowStreaming.git
synced 2025-12-24 03:42:07 +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 org.springframework.beans.factory.annotation.Autowired;
|
||||
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
|
||||
public class OpLogWrapServiceImpl implements OpLogWrapService {
|
||||
@@ -18,6 +21,12 @@ public class OpLogWrapServiceImpl implements OpLogWrapService {
|
||||
@Override
|
||||
public Integer saveOplogAndIgnoreException(OplogDTO oplogDTO) {
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
log.error("method=saveOplogAndIgnoreException||oplogDTO={}||errMsg=exception.", oplogDTO, e);
|
||||
|
||||
Reference in New Issue
Block a user