|
1 | 1 | package com.codingapi.tx.springcloud.http; |
2 | 2 |
|
3 | 3 | import com.codingapi.tx.aop.bean.TxTransactionLocal; |
| 4 | +import org.slf4j.Logger; |
| 5 | +import org.slf4j.LoggerFactory; |
4 | 6 | import org.springframework.http.HttpRequest; |
5 | 7 | import org.springframework.http.client.ClientHttpRequestExecution; |
6 | 8 | import org.springframework.http.client.ClientHttpRequestInterceptor; |
|
13 | 15 | */ |
14 | 16 | public class TransactionHttpRequestInterceptor implements ClientHttpRequestInterceptor { |
15 | 17 |
|
| 18 | + |
| 19 | + private Logger logger = LoggerFactory.getLogger(TransactionHttpRequestInterceptor.class); |
| 20 | + |
16 | 21 | @Override |
17 | 22 | public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { |
| 23 | + |
18 | 24 | TxTransactionLocal txTransactionLocal = TxTransactionLocal.current(); |
19 | | - String groupId = txTransactionLocal==null?null:txTransactionLocal.getGroupId(); |
| 25 | + String groupId = txTransactionLocal == null ? null : txTransactionLocal.getGroupId(); |
20 | 26 | int maxTimeOut = txTransactionLocal == null ? 0 : txTransactionLocal.getMaxTimeOut(); |
21 | | - request.getHeaders().add("tx-group",groupId); |
22 | | - request.getHeaders().add("tx-maxTimeOut", String.valueOf(maxTimeOut)); |
| 27 | + |
| 28 | + logger.info("LCN-SpringCloud TxGroup info -> groupId:"+groupId+",maxTimeOut:"+maxTimeOut); |
| 29 | + |
| 30 | + if(txTransactionLocal!=null) { |
| 31 | + request.getHeaders().add("tx-group", groupId); |
| 32 | + request.getHeaders().add("tx-maxTimeOut", String.valueOf(maxTimeOut)); |
| 33 | + } |
23 | 34 | return execution.execute(request,body); |
24 | 35 | } |
25 | 36 | } |
0 commit comments