本文整理了Java中org.apache.logging.log4j.ThreadContext.clearAll()
方法的一些代码示例,展示了ThreadContext.clearAll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.clearAll()
方法的具体详情如下:
包路径:org.apache.logging.log4j.ThreadContext
类名称:ThreadContext
方法名:clearAll
[英]Clears the context map and stack.
[中]清除上下文映射和堆栈。
代码示例来源:origin: floragunncom/search-guard
@Override
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
org.apache.logging.log4j.ThreadContext.clearAll();
if(!checkAndAuthenticateRequest(request, channel, client)) {
original.handleRequest(request, channel, client);
}
}
};
代码示例来源:origin: floragunncom/search-guard
@Override
public <Request extends ActionRequest, Response extends ActionResponse> void apply(Task task, final String action, Request request,
ActionListener<Response> listener, ActionFilterChain<Request, Response> chain) {
try (StoredContext ctx = threadContext.newStoredContext(true)){
org.apache.logging.log4j.ThreadContext.clearAll();
apply0(task, action, request, listener, chain);
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@AfterClass
public static void cleanupClass() {
ConfigurationFactory.removeConfigurationFactory(cf);
ThreadContext.clearAll();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@AfterClass
public static void cleanupClass() {
ConfigurationFactory.removeConfigurationFactory(cf);
ThreadContext.clearAll();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@After
public void teardown() {
ThreadContext.clearAll();
removeAndStopAppenders();
reset();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@AfterClass
public static void cleanupClass() {
tcpServer.shutdown();
udpServer.shutdown();
ThreadContext.clearAll();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@After
public void teardown() {
tcpServer.shutdown();
loggerContext = null;
logger = null;
tcpServer.reset();
ThreadContext.clearAll();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@BeforeClass
public static void setupClass() {
ThreadContext.clearAll();
ConfigurationFactory.setConfigurationFactory(cf);
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@BeforeClass
public static void setupClass() {
ThreadContext.clearAll();
ConfigurationFactory.setConfigurationFactory(cf);
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Before
public void setup() throws Exception {
tcpServer = new TcpSocketTestServer(AvailablePortFinder.getNextAvailable());
tcpServer.start();
ThreadContext.clearAll();
loggerContext = loggerContextRule.getLoggerContext();
logger = loggerContext.getLogger(SocketAppenderBufferSizeTest.class.getName());
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@BeforeClass
public static void setupClass() throws Exception {
tcpServer = new TcpSocketTestServer(PORT);
tcpServer.start();
udpServer = new UdpSocketTestServer();
udpServer.start();
LoggerContext.getContext().reconfigure();
ThreadContext.clearAll();
}
代码示例来源:origin: zstackio/zstack
private void setThreadLoggingContext(Message msg) {
ThreadContext.clearAll();
if (msg instanceof APIMessage) {
ThreadContext.put(Constants.THREAD_CONTEXT_API, msg.getId());
ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, msg.getClass().getName());
} else {
Map<String, String> ctx = msg.getHeaderEntry(CloudBus.HEADER_TASK_CONTEXT);
if (ctx != null) {
ThreadContext.putAll(ctx);
}
}
if (msg.getHeaders().containsKey(CloudBus.HEADER_TASK_STACK)) {
List<String> taskStack = msg.getHeaderEntry(CloudBus.HEADER_TASK_STACK);
ThreadContext.setStack(taskStack);
}
}
代码示例来源:origin: zstackio/zstack
private Runnable saveThreadContext() {
ThreadContextMapSaved savedThread = new ThreadContextMapSaved();
savedThread.contextMap = ThreadContext.getContext();
savedThread.contextStack = ThreadContext.cloneStack();
return () -> {
ThreadContext.clearAll();
ThreadContext.putAll(savedThread.contextMap);
ThreadContext.setStack(savedThread.contextStack.asList());
};
}
代码示例来源:origin: zstackio/zstack
private void setThreadLoggingContext(Message msg) {
ThreadContext.clearAll();
if (msg instanceof APIMessage) {
ThreadContext.put(Constants.THREAD_CONTEXT_API, msg.getId());
ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, msg.getClass().getName());
} else {
Map<String, String> ctx = msg.getHeaderEntry(THREAD_CONTEXT);
if (ctx != null) {
ThreadContext.putAll(ctx);
}
}
if (msg.getHeaders().containsKey(THREAD_CONTEXT_STACK)) {
List<String> taskStack = msg.getHeaderEntry(THREAD_CONTEXT_STACK);
ThreadContext.setStack(taskStack);
}
if (msg.getHeaders().containsKey(TASK_CONTEXT)) {
TaskContext.setTaskContext(msg.getHeaderEntry(TASK_CONTEXT));
}
}
代码示例来源:origin: zstackio/zstack
private void setThreadContext(ProgressReportCmd cmd) {
ThreadContext.clearAll();
if (cmd.getThreadContextMap() != null) {
ThreadContext.putAll(cmd.getThreadContextMap());
}
if (cmd.getThreadContextStack() != null) {
ThreadContext.setStack(cmd.getThreadContextStack());
}
}
代码示例来源:origin: com.visionarts/power-jambda-core
public static void clear() {
ThreadContext.clearAll();
}
代码示例来源:origin: com.sqlapp/sqlapp-core
/**
* コンテキスト情報をクリアする。
*/
public static void release() {
THREAD_LOCAL_OBJECT_MAP.remove();
org.apache.logging.log4j.ThreadContext.clearAll();
}
代码示例来源:origin: com.floragunn/search-guard-6
@Override
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
org.apache.logging.log4j.ThreadContext.clearAll();
if(!checkAndAuthenticateRequest(request, channel, client)) {
original.handleRequest(request, channel, client);
}
}
};
代码示例来源:origin: com.floragunn/search-guard-6
@Override
public <Request extends ActionRequest, Response extends ActionResponse> void apply(Task task, final String action, Request request,
ActionListener<Response> listener, ActionFilterChain<Request, Response> chain) {
try (StoredContext ctx = threadContext.newStoredContext(true)){
org.apache.logging.log4j.ThreadContext.clearAll();
apply0(task, action, request, listener, chain);
}
}
代码示例来源:origin: yujunhao8831/spring-boot-start-current
@Override
protected void doFilterInternal ( HttpServletRequest request , HttpServletResponse response ,
FilterChain chain ) throws ServletException, IOException {
final String authToken = this.extractAuthTokenFromRequest( request , this.tokenHeader );
String username = null;
if ( StringUtils.isNotBlank( authToken ) ) {
username = jwtTokenUtil.getUsernameFromToken( authToken );
}
LogUtils.getLogger().debug( "authToken : {},username : {}" , authToken , username );
if ( username != null && SecurityContextHolder.getContext().getAuthentication() == null ) {
// 对于简单的验证,只需检查令牌的完整性即可。 您不必强制调用数据库。 由你自己决定
// 是否查询数据看情况,目前是查询数据库
UserDetails userDetails = this.userDetailsService.loadUserByUsername( username );
if ( jwtTokenUtil.validateToken( authToken , userDetails ) ) {
UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken( userDetails , null , userDetails.getAuthorities() );
ThreadContext.put( USER_ID , String.valueOf( ( ( BasicJwtUser ) userDetails ).getId() ) );
ThreadContext.put( USER_NAME , username );
authentication.setDetails( new WebAuthenticationDetailsSource().buildDetails( request ) );
LogUtils.getLogger().debug( "authToken : {},username : {}" , authToken , username );
LogUtils.getLogger().debug( "该 " + username + "用户已认证, 设置安全上下文" );
SecurityContextHolder.getContext().setAuthentication( authentication );
}
}
chain.doFilter( request , response );
ThreadContext.clearAll();
}
内容来源于网络,如有侵权,请联系作者删除!