Skip to content

Commit 8993bee

Browse files
author
1991wangliang@gmail.com
committed
兼容springboot 1.5.x
1 parent 5294cec commit 8993bee

6 files changed

Lines changed: 215 additions & 59 deletions

File tree

txlcn-logger/src/main/java/com/codingapi/txlcn/logger/Slf4jTxLogger.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.codingapi.txlcn.logger;
1717

18-
import com.codingapi.txlcn.common.util.Transactions;
1918
import lombok.extern.slf4j.Slf4j;
2019

2120
/**
Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
/*
2-
* Copyright 2017-2019 CodingApi .
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package com.codingapi.txlcn.tc.aspect.interceptor;
17-
18-
import com.codingapi.txlcn.tc.aspect.weave.DTXLogicWeaver;
19-
import org.aopalliance.intercept.MethodInvocation;
20-
import org.springframework.transaction.interceptor.TransactionInterceptor;
21-
22-
import java.util.Properties;
23-
24-
/**
25-
* Description:
26-
* Date: 1/12/19
27-
*
28-
* @author ujued
29-
*/
30-
31-
public class DTXInterceptor extends TransactionInterceptor {
32-
33-
private final DTXLogicWeaver dtxLogicWeaver;
34-
35-
private Properties transactionAttributes;
36-
37-
public DTXInterceptor(DTXLogicWeaver dtxLogicWeaver) {
38-
this.dtxLogicWeaver = dtxLogicWeaver;
39-
}
40-
41-
@Override
42-
public void setTransactionAttributes(Properties transactionAttributes) {
43-
this.transactionAttributes = transactionAttributes;
44-
super.setTransactionAttributes(transactionAttributes);
45-
}
46-
47-
@Override
48-
public Object invoke(MethodInvocation invocation) throws Throwable {
49-
return dtxLogicWeaver.runTransaction(InterceptorInvocationUtils.load(invocation,transactionAttributes), () -> super.invoke(invocation));
50-
}
51-
52-
}
1+
///*
2+
// * Copyright 2017-2019 CodingApi .
3+
// *
4+
// * Licensed under the Apache License, Version 2.0 (the "License");
5+
// * you may not use this file except in compliance with the License.
6+
// * You may obtain a copy of the License at
7+
// *
8+
// * http://www.apache.org/licenses/LICENSE-2.0
9+
// *
10+
// * Unless required by applicable law or agreed to in writing, software
11+
// * distributed under the License is distributed on an "AS IS" BASIS,
12+
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// * See the License for the specific language governing permissions and
14+
// * limitations under the License.
15+
// */
16+
//package com.codingapi.txlcn.tc.aspect.interceptor;
17+
//
18+
//import com.codingapi.txlcn.tc.aspect.weave.DTXLogicWeaver;
19+
//import org.aopalliance.intercept.MethodInvocation;
20+
//import org.springframework.transaction.interceptor.TransactionInterceptor;
21+
//
22+
//import java.util.Properties;
23+
//
24+
///**
25+
// * Description:
26+
// * Date: 1/12/19
27+
// *
28+
// * @author ujued
29+
// */
30+
//
31+
//public class DTXInterceptor extends TransactionInterceptor {
32+
//
33+
// private final DTXLogicWeaver dtxLogicWeaver;
34+
//
35+
// private Properties transactionAttributes;
36+
//
37+
// public DTXInterceptor(DTXLogicWeaver dtxLogicWeaver) {
38+
// this.dtxLogicWeaver = dtxLogicWeaver;
39+
// }
40+
//
41+
// @Override
42+
// public void setTransactionAttributes(Properties transactionAttributes) {
43+
// this.transactionAttributes = transactionAttributes;
44+
// super.setTransactionAttributes(transactionAttributes);
45+
// }
46+
//
47+
// @Override
48+
// public Object invoke(MethodInvocation invocation) throws Throwable {
49+
// return dtxLogicWeaver.runTransaction(InterceptorInvocationUtils.load(invocation,transactionAttributes), () -> super.invoke(invocation));
50+
// }
51+
//
52+
//}

txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionControlTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@ public void notifyGroup(String groupId, String unitId, String transactionType, i
158158
// 关闭事务组失败
159159
dtxExceptionHandler.handleNotifyGroupBusinessException(Arrays.asList(groupId, state, unitId, transactionType), e.getCause());
160160
}
161-
txLogger.transactionInfo(groupId, unitId, "notify group exception state %d.", state);
161+
txLogger.transactionInfo(groupId, unitId, "notify group exception state {}.", state);
162162
}
163163
}

txlcn-tracing/src/main/java/com/codingapi/txlcn/tracing/http/TracingHandlerInterceptor.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
import com.codingapi.txlcn.common.util.Maps;
1919
import com.codingapi.txlcn.tracing.TracingConstants;
2020
import com.codingapi.txlcn.tracing.TracingContext;
21+
import com.codingapi.txlcn.tracing.http.spring.WebMvcConfigurer;
2122
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
22-
import org.springframework.lang.NonNull;
2323
import org.springframework.stereotype.Component;
2424
import org.springframework.web.servlet.HandlerInterceptor;
2525
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
26-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2726

2827
import javax.servlet.http.HttpServletRequest;
2928
import javax.servlet.http.HttpServletResponse;
@@ -37,11 +36,10 @@
3736
*/
3837
@ConditionalOnClass(HandlerInterceptor.class)
3938
@Component
40-
public class TracingHandlerInterceptor implements HandlerInterceptor, WebMvcConfigurer {
39+
public class TracingHandlerInterceptor implements com.codingapi.txlcn.tracing.http.spring.HandlerInterceptor, WebMvcConfigurer {
4140

4241
@Override
43-
public boolean preHandle(
44-
@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler) {
42+
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
4543
String groupId = Optional.ofNullable(request.getHeader(TracingConstants.HEADER_KEY_GROUP_ID)).orElse("");
4644
String appList = Optional.ofNullable(request.getHeader(TracingConstants.HEADER_KEY_APP_MAP)).orElse("");
4745
TracingContext.tracing().init(Maps.newHashMap(TracingConstants.GROUP_ID, groupId, TracingConstants.APP_MAP, appList));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2017-2019 CodingApi .
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.codingapi.txlcn.tracing.http.spring;
17+
18+
import org.springframework.web.servlet.ModelAndView;
19+
20+
import javax.servlet.http.HttpServletRequest;
21+
import javax.servlet.http.HttpServletResponse;
22+
23+
public interface HandlerInterceptor extends org.springframework.web.servlet.HandlerInterceptor {
24+
25+
@Override
26+
default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
27+
return false;
28+
}
29+
30+
@Override
31+
default void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
32+
33+
}
34+
35+
@Override
36+
default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
37+
38+
}
39+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright 2017-2019 CodingApi .
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.codingapi.txlcn.tracing.http.spring;
17+
18+
import org.springframework.format.FormatterRegistry;
19+
import org.springframework.http.converter.HttpMessageConverter;
20+
import org.springframework.validation.MessageCodesResolver;
21+
import org.springframework.validation.Validator;
22+
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
23+
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
24+
import org.springframework.web.servlet.HandlerExceptionResolver;
25+
import org.springframework.web.servlet.config.annotation.*;
26+
27+
import java.util.List;
28+
29+
public interface WebMvcConfigurer extends org.springframework.web.servlet.config.annotation.WebMvcConfigurer {
30+
31+
@Override
32+
default void configurePathMatch(PathMatchConfigurer configurer) {
33+
34+
}
35+
36+
@Override
37+
default void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
38+
39+
}
40+
41+
@Override
42+
default void configureAsyncSupport(AsyncSupportConfigurer configurer) {
43+
44+
}
45+
46+
@Override
47+
default void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
48+
49+
}
50+
51+
@Override
52+
default void addFormatters(FormatterRegistry registry) {
53+
54+
}
55+
56+
@Override
57+
default void addInterceptors(InterceptorRegistry registry) {
58+
59+
}
60+
61+
@Override
62+
default void addResourceHandlers(ResourceHandlerRegistry registry) {
63+
64+
}
65+
66+
@Override
67+
default void addCorsMappings(CorsRegistry registry) {
68+
69+
}
70+
71+
@Override
72+
default void addViewControllers(ViewControllerRegistry registry) {
73+
74+
}
75+
76+
@Override
77+
default void configureViewResolvers(ViewResolverRegistry registry) {
78+
79+
}
80+
81+
@Override
82+
default void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
83+
84+
}
85+
86+
@Override
87+
default void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> handlers) {
88+
89+
}
90+
91+
@Override
92+
default void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
93+
94+
}
95+
96+
@Override
97+
default void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
98+
99+
}
100+
101+
@Override
102+
default void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
103+
104+
}
105+
106+
@Override
107+
default void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
108+
109+
}
110+
111+
@Override
112+
default Validator getValidator() {
113+
return null;
114+
}
115+
116+
@Override
117+
default MessageCodesResolver getMessageCodesResolver() {
118+
return null;
119+
}
120+
}

0 commit comments

Comments
 (0)