Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CXF-7493] Add a default ClassUnwrapper for CDI integration. #313

Merged
merged 1 commit into from Sep 21, 2017

Conversation

johnament
Copy link
Contributor

This is to avoid issues with proxies and class metadata.

import org.apache.cxf.common.util.ClassUnwrapper;

class CdiClassUnwrapper implements ClassUnwrapper {
private static final List<String> UNWRAPPED_MARKERS = asList("OwbNormalScopeProxy", "WeldClientProxy");
Copy link
Contributor

Choose a reason for hiding this comment

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

OWB has other suffixes, why not using $$ as in https://github.com/apache/meecrowave/blob/7bd58d4a254c0d40fb1a2ab0d19b24dbab4014ca/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java#L54 ? Would also handle TomEE proxies (EJB) BTW. Also any way it just gets merge with the default unwrapper? I don't see any reason to not have it out of the box since it doesn't depend on anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have only seen the one suffix from OWB. Where can I find the list of suffixes? I saw what you did in TomEE, and I think using $$ could be problematic for non-CDI frameworks, so I wanted to explicitly list out the known suffixes.

I'm fine with putting something like this in core, and explicitly activating it in CDI, but would be concerned with being over eager with the swap out.

Copy link
Contributor

Choose a reason for hiding this comment

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

For owb you need to check AbstractProxyFactory subclasses out, without more checking I had in mind $$OwbSubClass. In TomEE we also have $$LocalBeanProxy which would break probably, and a lot of frameworks use $$ for that purpose. That is why we use $$ and not something more precise which will always hit a pitfall. Do you know any framework using $$ and would break cxf unwrapping the class? If so we can surely just make the suffixes configurable. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

@johnament @rmannibucau Was going through this discussion (https://issues.jboss.org/browse/CDI-10), seems to be a known problem people struggle with. Not sure if it is better or not, what if we detect the CDI implementation at runtime (class probing) and delegate the unwrapping to the framework itself? F.e. in case of OWB, we could useNormalScopeProxyFactory.unwrapInstance(o), something similar should be available for Weld as well. Not ideal either, but more reliable may be? Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I don't think Weld has a behavior like unwrapInstance but it could be done by us if its Weld. I also figured that checking by name would be easier since it avoid any compile time dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

It is definitely the easiest / simplest way to do that, not sure how reliable it is though ... May be we could have some regex, like ^.+$$.+Proxy$, the $$ usually depict a generated class, so we would cover Xxx$$OwbNormalScopeProxy, Xxx$$WeldClientProxy as well as Xxx$$LocalBeanProxy like @rmannibucau pointed out as well. Should be pretty good heuristic, what do you think?

import org.apache.cxf.common.util.ClassUnwrapper;

class CdiClassUnwrapper implements ClassUnwrapper {
private static final Pattern PROXY_PATTERN = Pattern.compile(".+\\$\\$.+Proxy");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@reta @rmannibucau ok, this uses a pattern based on the discussion. Do we still want to move outside the CDI module?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @johnament, I don't think it should be moved outside CDI integration, @rmannibucau any particular reasons to do that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep the reason is to ensure it is used by all integrations. Very few server uses cdi extension to comply to spec but all use proxies. Since the perf and behavior shouldnt hurt it can be added to the default IMO

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi guys, but the problem is only showing itself on the CDI path ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really. it has nothing to do with CDI actually except CDI uses proxies. It will happen each time a lib is using subclassing proxies, CDI is one big consumer but there are a lot of other ways to get it even in plain standalone.

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like a good plan, @sberyozkin are we good to merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not clear what the plan is, just leave it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi Andriy, if all 3 of you are happy, then yes, please merge :-), I did not really contribute myself

Copy link
Member

Choose a reason for hiding this comment

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

@johnament Sorry, was not clear, I was referring to @sberyozkin suggestion for 2 stages, let us start from CDI first, and than make a decision if it worth going to core or not. Make sense?

@@ -63,6 +65,9 @@ public String getName() {
@Override
public ExtensionManagerBus create(final CreationalContext< ExtensionManagerBus > ctx) {
final ExtensionManagerBus instance = injectionTarget.produce(ctx);
if ("true".equals(SystemPropertyAction.getProperty("org.apache.cxf.cdi.useCdiUnwrapper", "true"))) {
Copy link
Member

Choose a reason for hiding this comment

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

@johnament pretty minor, before merging could you please rename property org.apache.cxf.cdi.useCdiUnwrapper to org.apache.cxf.cdi.unwrap.proxies (or similar) so it kind of explains its purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

This is to avoid issues with proxies and class metadata.
@johnament
Copy link
Contributor Author

johnament commented Sep 20, 2017 via email

@reta reta merged commit 160eebb into apache:master Sep 21, 2017
@reta
Copy link
Member

reta commented Sep 21, 2017

Thanks @johnament !

reta added a commit that referenced this pull request Oct 8, 2017
[CXF-7493] Add a default ClassUnwrapper for CDI integration.
andymc12 pushed a commit to andymc12/cxf that referenced this pull request Oct 25, 2017
[CXF-7493] Add a default ClassUnwrapper for CDI integration.
rnetuka pushed a commit to rnetuka/cxf that referenced this pull request Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants