Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
211010717
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2021
211010717
Commits
e9ff5f99
Unverified
Commit
e9ff5f99
authored
4 years ago
by
squall
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
optimize: opt the logic of SpringProxyUtils.findTargetClass(#3155) (#3156)
parent
eee0c741
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spring/src/main/java/io/seata/spring/util/SpringProxyUtils.java
+8
-24
8 additions, 24 deletions
.../src/main/java/io/seata/spring/util/SpringProxyUtils.java
with
8 additions
and
24 deletions
spring/src/main/java/io/seata/spring/util/SpringProxyUtils.java
+
8
−
24
View file @
e9ff5f99
...
...
@@ -23,10 +23,9 @@ import java.util.Set;
import
io.seata.common.util.CollectionUtils
;
import
io.seata.rm.tcc.remoting.parser.DubboUtil
;
import
org.springframework.aop.
TargetSource
;
import
org.springframework.aop.
framework.Advised
;
import
org.springframework.aop.framework.AdvisedSupport
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.aop.target.EmptyTargetSource
;
/**
* Proxy tools base on spring
...
...
@@ -34,9 +33,7 @@ import org.springframework.aop.target.EmptyTargetSource;
* @author zhangsen
*/
public
class
SpringProxyUtils
{
private
SpringProxyUtils
()
{
}
/**
...
...
@@ -47,18 +44,14 @@ public class SpringProxyUtils {
* @throws Exception the exception
*/
public
static
Class
<?>
findTargetClass
(
Object
proxy
)
throws
Exception
{
if
(
AopUtils
.
isAopProxy
(
proxy
))
{
AdvisedSupport
advised
=
getAdvisedSupport
(
proxy
);
if
(
AopUtils
.
isJdkDynamicProxy
(
proxy
))
{
TargetSource
targetSource
=
advised
.
getTargetSource
();
return
targetSource
instanceof
EmptyTargetSource
?
getFirstInterfaceByAdvised
(
advised
)
:
targetSource
.
getTargetClass
();
}
Object
target
=
advised
.
getTargetSource
().
getTarget
();
return
findTargetClass
(
target
);
}
else
{
return
proxy
==
null
?
null
:
proxy
.
getClass
();
if
(
proxy
==
null
)
{
return
null
;
}
if
(
AopUtils
.
isAopProxy
(
proxy
)
&&
proxy
instanceof
Advised
)
{
Object
targetObject
=
((
Advised
)
proxy
).
getTargetSource
().
getTarget
();
return
findTargetClass
(
targetObject
);
}
return
proxy
.
getClass
();
}
public
static
Class
<?>[]
findInterfaces
(
Object
proxy
)
throws
Exception
{
...
...
@@ -79,15 +72,6 @@ public class SpringProxyUtils {
}
}
private
static
Class
<?>
getFirstInterfaceByAdvised
(
AdvisedSupport
advised
)
{
Class
<?>[]
interfaces
=
advised
.
getProxiedInterfaces
();
if
(
interfaces
.
length
>
0
)
{
return
interfaces
[
0
];
}
else
{
throw
new
IllegalStateException
(
"Find the jdk dynamic proxy class that does not implement the interface"
);
}
}
/**
* Gets advised support.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment