Skip to content

Conversation

yasserzamani
Copy link
Member

Resolves WW-4105.

* </p>
*
*/
public class SpringUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name it ProxyUtil or something like that. This class can be used to deal with known proxies and not only spring proxies.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I will do in next commit. However, I also try my effort to remove it to commons-lang if guys there accepted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpringUtils doesn't sound good but I have no better name for now. Also it's the only case we have now so we can always refactor this code and introduce an interface with few implementation latter on.

For future reference: it would be good to have a ProxyAware interface in the core with a default implementation (that does nothing) and then in the Spring Plugin provide a real implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Unfortunately I did not understand well. Do you mean that the user has to be careful to implement ProxyAware or inherit Spring Plugin's default implementation in his proxied actions? If so, there are two disadvantages, first he has to be careful about which actions may be proxied, and second he has to add Spring Plugin dependency or implement it manually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, no ... it was just for a future reference when we will want turn this into a bean

try {
if (isAopProxy(candidate) &&
implementsInterface(candidate.getClass(), "org.springframework.aop.framework.Advised")) {
Object targetSource = MethodUtils.invokeMethod(candidate, "getTargetSource");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is targetSource here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is what Spring himself does to unwrap it's proxies. Please see AopTestUtils.java

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... Never used AopTestUtils. But Advised extends TargetClassAware. Can getTargetClass just be invoked instead of two method calls? See AopUtils.

Copy link
Member Author

@yasserzamani yasserzamani May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTargetClass just returns a Class but getting the target Object (i.e. actual action object) let us pass it directly to ReflectionProvider without any needed modification of ReflectionProvider codes.

*/
public static boolean isAopProxy(Object object) {
Class<?> clazz = object.getClass();
return (implementsInterface(clazz, "org.springframework.aop.SpringProxy") &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract strings to constants.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I will do in next commit.

* </p>
*
*/
public class SpringUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another maybe. This can be turned to injectable bean so it can be easily overridable if needed. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why someone may need to override such specific methods?

As all methods could be static, I thought normally it should be a static utils class rather than a bean object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support other possible proxies. Or in case something changes in spring-aop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should update Struts itself in both cases when reported by a user.

@yasserzamani
Copy link
Member Author

@lukaszlenart , I updated with @aleksandr-m reviews. I hope it is ready for merge if you pals agree.

@lukaszlenart
Copy link
Member

I think with can go ahead and merge this, @aleksandr-m any objections?

@aleksandr-m
Copy link
Contributor

@lukaszlenart I think it is ok.

@asfgit asfgit merged commit 9a8b4f4 into apache:master May 17, 2017
@yasserzamani yasserzamani deleted the WW-4105_2 branch May 17, 2017 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants