You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Andreas Benneke (JIRA)" <ji...@apache.org> on 2008/06/11 15:08:45 UTC

[jira] Created: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
--------------------------------------------------------------------------------------------------

                 Key: CXF-1645
                 URL: https://issues.apache.org/jira/browse/CXF-1645
             Project: CXF
          Issue Type: Bug
          Components: Core
    Affects Versions: 2.0.6, 2.1, 2.1.1, 2.0.7
            Reporter: Andreas Benneke


If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 

  Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
  targetMethod.invoke(getTarget(), resource);

This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).

This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)

As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:

  MethodInvoker targetInvoker = new MethodInvoker();
  targetInvoker.setTargetObject(getTarget());
  targetInvoker.setTargetMethod(method.getName());
  targetInvoker.setArguments(new Object[]{resource});
  targetInvoker.prepare();
  targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

Posted by "Andreas Benneke (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-1645?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12604769#action_12604769 ] 

Andreas Benneke commented on CXF-1645:
--------------------------------------

I've been thinking a bit about our solution(s) and think it might fail, if the method in question is overloaded. The for-loop (and even my spring solution) might end up calling a method with the wrong signature (which was not annotated). This might lead to unexpected results if the methods are doing different things...

What about this (going back to the original implementation):

  Method targetMethod = getTarget().getClass().getMethod(method.getName(), method.getParameterTypes());
  targetMethod.invoke(getTarget(), resource); 

Any thoughts?

> ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
> --------------------------------------------------------------------------------------------------
>
>                 Key: CXF-1645
>                 URL: https://issues.apache.org/jira/browse/CXF-1645
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1, 2.0.6, 2.1.1, 2.0.7
>            Reporter: Andreas Benneke
>            Assignee: Daniel Kulp
>             Fix For: 2.1.1, 2.0.7
>
>         Attachments: ResourceInjector.patch
>
>
> If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 
>   Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
>   targetMethod.invoke(getTarget(), resource);
> This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).
> This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)
> As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:
>   MethodInvoker targetInvoker = new MethodInvoker();
>   targetInvoker.setTargetObject(getTarget());
>   targetInvoker.setTargetMethod(method.getName());
>   targetInvoker.setArguments(new Object[]{resource});
>   targetInvoker.prepare();
>   targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

Posted by "Andreas Benneke (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-1645?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Benneke reopened CXF-1645:
----------------------------------


> ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
> --------------------------------------------------------------------------------------------------
>
>                 Key: CXF-1645
>                 URL: https://issues.apache.org/jira/browse/CXF-1645
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1, 2.0.6, 2.1.1, 2.0.7
>            Reporter: Andreas Benneke
>            Assignee: Daniel Kulp
>             Fix For: 2.1.1, 2.0.7
>
>         Attachments: ResourceInjector.patch
>
>
> If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 
>   Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
>   targetMethod.invoke(getTarget(), resource);
> This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).
> This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)
> As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:
>   MethodInvoker targetInvoker = new MethodInvoker();
>   targetInvoker.setTargetObject(getTarget());
>   targetInvoker.setTargetMethod(method.getName());
>   targetInvoker.setArguments(new Object[]{resource});
>   targetInvoker.prepare();
>   targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

Posted by "Andreas Benneke (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-1645?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12604443#action_12604443 ] 

Andreas Benneke commented on CXF-1645:
--------------------------------------

Perfect, thanks a lot for the quick response! :-D

> ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
> --------------------------------------------------------------------------------------------------
>
>                 Key: CXF-1645
>                 URL: https://issues.apache.org/jira/browse/CXF-1645
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1, 2.0.6, 2.1.1, 2.0.7
>            Reporter: Andreas Benneke
>            Assignee: Daniel Kulp
>             Fix For: 2.1.1, 2.0.7
>
>         Attachments: ResourceInjector.patch
>
>
> If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 
>   Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
>   targetMethod.invoke(getTarget(), resource);
> This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).
> This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)
> As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:
>   MethodInvoker targetInvoker = new MethodInvoker();
>   targetInvoker.setTargetObject(getTarget());
>   targetInvoker.setTargetMethod(method.getName());
>   targetInvoker.setArguments(new Object[]{resource});
>   targetInvoker.prepare();
>   targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-1645?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Kulp updated CXF-1645:
-----------------------------

    Assignee: Daniel Kulp


We cannot take a dependency on Spring at this level as this can be used in non-spring cases.

However, it's rather simple to get this to work as we only care about the public methods that have only a single parameter so something like:

           for (Method m : class1.getMethods()) {
                if (m.getName().equals(name)
                    && m.getParameterTypes().length == 1
                    && m.getParameterTypes()[0].isInstance(resource)) {
                    return m;
                }
            }

Should work.   I'll get this committed shortly.



> ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
> --------------------------------------------------------------------------------------------------
>
>                 Key: CXF-1645
>                 URL: https://issues.apache.org/jira/browse/CXF-1645
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1, 2.0.6, 2.1.1, 2.0.7
>            Reporter: Andreas Benneke
>            Assignee: Daniel Kulp
>         Attachments: ResourceInjector.patch
>
>
> If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 
>   Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
>   targetMethod.invoke(getTarget(), resource);
> This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).
> This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)
> As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:
>   MethodInvoker targetInvoker = new MethodInvoker();
>   targetInvoker.setTargetObject(getTarget());
>   targetInvoker.setTargetMethod(method.getName());
>   targetInvoker.setArguments(new Object[]{resource});
>   targetInvoker.prepare();
>   targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-1645?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Kulp resolved CXF-1645.
------------------------------

    Resolution: Fixed

> ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
> --------------------------------------------------------------------------------------------------
>
>                 Key: CXF-1645
>                 URL: https://issues.apache.org/jira/browse/CXF-1645
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1, 2.0.6, 2.1.1, 2.0.7
>            Reporter: Andreas Benneke
>            Assignee: Daniel Kulp
>             Fix For: 2.1.1, 2.0.7
>
>         Attachments: ResourceInjector.patch
>
>
> If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 
>   Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
>   targetMethod.invoke(getTarget(), resource);
> This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).
> This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)
> As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:
>   MethodInvoker targetInvoker = new MethodInvoker();
>   targetInvoker.setTargetObject(getTarget());
>   targetInvoker.setTargetMethod(method.getName());
>   targetInvoker.setArguments(new Object[]{resource});
>   targetInvoker.prepare();
>   targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-1645?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Kulp resolved CXF-1645.
------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0.7
                   2.1.1

> ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
> --------------------------------------------------------------------------------------------------
>
>                 Key: CXF-1645
>                 URL: https://issues.apache.org/jira/browse/CXF-1645
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1, 2.0.6, 2.1.1, 2.0.7
>            Reporter: Andreas Benneke
>            Assignee: Daniel Kulp
>             Fix For: 2.1.1, 2.0.7
>
>         Attachments: ResourceInjector.patch
>
>
> If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 
>   Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
>   targetMethod.invoke(getTarget(), resource);
> This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).
> This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)
> As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:
>   MethodInvoker targetInvoker = new MethodInvoker();
>   targetInvoker.setTargetObject(getTarget());
>   targetInvoker.setTargetMethod(method.getName());
>   targetInvoker.setArguments(new Object[]{resource});
>   targetInvoker.prepare();
>   targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-1645?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12604903#action_12604903 ] 

Daniel Kulp commented on CXF-1645:
----------------------------------


You're right.   That should work just as well without the loop.   I'll definitely change that.   Thanks!





> ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
> --------------------------------------------------------------------------------------------------
>
>                 Key: CXF-1645
>                 URL: https://issues.apache.org/jira/browse/CXF-1645
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1, 2.0.6, 2.1.1, 2.0.7
>            Reporter: Andreas Benneke
>            Assignee: Daniel Kulp
>             Fix For: 2.1.1, 2.0.7
>
>         Attachments: ResourceInjector.patch
>
>
> If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 
>   Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
>   targetMethod.invoke(getTarget(), resource);
> This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).
> This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)
> As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:
>   MethodInvoker targetInvoker = new MethodInvoker();
>   targetInvoker.setTargetObject(getTarget());
>   targetInvoker.setTargetMethod(method.getName());
>   targetInvoker.setArguments(new Object[]{resource});
>   targetInvoker.prepare();
>   targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CXF-1645) ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed

Posted by "Andreas Benneke (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-1645?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Benneke updated CXF-1645:
---------------------------------

    Attachment: ResourceInjector.patch

This patch adds the proposed change to the ResourceInjector and extends the unit test to cover the specified case .

(Note: the test fails with the unpatched ResourceInjector)

> ResourceInjector fails to inject into (Spring) proxies if resource to be in injected is subclassed
> --------------------------------------------------------------------------------------------------
>
>                 Key: CXF-1645
>                 URL: https://issues.apache.org/jira/browse/CXF-1645
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1, 2.0.6, 2.1.1, 2.0.7
>            Reporter: Andreas Benneke
>         Attachments: ResourceInjector.patch
>
>
> If the target is a proxy ResourceInjector tries to resolve an appropriate setter method for the resource using 
>   Method targetMethod = getTarget().getClass().getMethod(method.getName(), new Class[]{resource.getClass()});
>   targetMethod.invoke(getTarget(), resource);
> This fails if the resource has been subclassed because getMethod() (still) does only exact matches (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4287725).
> This is (for example) the reason why injecting the WebServiceContext into a (Spring) proxy does not work: The real implementation WebServiceContextImpl is always a subclass (see thread http://www.mail-archive.com/cxf-user@incubator.apache.org/msg03050.html)
> As a solutions, the ResourceInjector might implement it's own matching algorithm or e. g. use Spring's MethodInvoker instead which already contains such an algorithm:
>   MethodInvoker targetInvoker = new MethodInvoker();
>   targetInvoker.setTargetObject(getTarget());
>   targetInvoker.setTargetMethod(method.getName());
>   targetInvoker.setArguments(new Object[]{resource});
>   targetInvoker.prepare();
>   targetInvoker.invoke();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.