IllegalArgumentException while invoking method on injected proxy object (object 
is not an instance of declaring class)
----------------------------------------------------------------------------------------------------------------------

                 Key: WICKET-1848
                 URL: https://issues.apache.org/jira/browse/WICKET-1848
             Project: Wicket
          Issue Type: Bug
          Components: wicket, wicket-extensions
    Affects Versions: 1.4-M3
            Reporter: Maarten Billemont


The problem description:

I have some EJB service beans which I'd like to use in my wicket application.  
The service beans implement @Local interfaces which all have a public static 
final String BINDING field that contains the JNDI binding of the bean that 
implements them.  I use this BINDING field to lookup the bean and inject it 
into my Wicket pages using the JavaEEComponentInjector.

The problem, however, occurs when accessing methods of these injected bean 
proxy objects.  I'm not entirely sure what the cause is and I've noticed the 
issue to be rather unpredictable - probably due to the fact that I really don't 
get what's going wrong.

In any case; for some reason when I invoke methods on my proxy objects, 
Wicket's proxy object's reflection seems unable to actually perform the call on 
the target object.  I know far too little of how proxy objects work internally 
to understand what exactly is going on and what exactly might be failing to 
give any more details than this.

I'm not sure whether this is an issue in wicket-ioc or wicket-contrib-javaee 
though seeing as the exception originates from within LazyInitProxyFactory I'm 
betting on wicket-ioc (which isn't in the list of components of this JIRA?)


The exception:

org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface 
org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component 
[Marku
    at 
org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:193)
    at 
org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
    at 
org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
    at 
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1188)
    at org.apache.wicket.RequestCycle.step(RequestCycle.java:1265)
    at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1366)
    at org.apache.wicket.RequestCycle.request(RequestCycle.java:499)
    at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:387)
    at 
org.apache.wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:145)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at 
net.link.safeonline.sdk.auth.filter.ContainerLoginFilter.doFilter(ContainerLoginFilter.java:70)
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at 
net.link.safeonline.sdk.auth.filter.JAASLoginFilter.doFilter(JAASLoginFilter.java:93)
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at 
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at 
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
    at 
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
    at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at 
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
    at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
    at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
    at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at 
org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
    ... 34 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of 
declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at 
org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:416)
    at org.apache.wicket.proxy.$Proxy1013.createAccount(Unknown Source)
    at 
net.link.safeonline.demo.bank.webapp.NewAccountPage$AccountForm.onSubmit(NewAccountPage.java:74)
    at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1347)
    at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:797)
    ... 39 more


The (relevant) Wicket code:

public class AccountApplication extends WebApplication {

    @Override
    protected void init() {

        addComponentInstantiationListener(new JavaEEComponentInjector(this,
                new IJndiNamingStrategy() {

                    private final StandardJndiNamingStrategy defaultStrategy  = 
new StandardJndiNamingStrategy();


                    @SuppressWarnings("unchecked")
                    public String calculateName(String ejbName, Class ejbType) {

                        try {
                            Field bindingField = 
ejbType.getDeclaredField("BINDING");
                            Object binding = bindingField.get(null);

                            if (binding != null)
                                return binding.toString();
                        } catch (Exception e) {
                            ...
                        }

                        return this.defaultStrategy.calculateName(ejbName, 
ejbType);
                    }
                }));
    }
...
}

public abstract class LayoutPage extends WebPage {

    @EJB
    transient AccountService     accountService;
...
}

public class NewAccountPage extends LayoutPage {
...

    class AccountForm extends Form<String> {
...
        @Override
        protected void onSubmit() {

            accountService.createAccount(...);
        }
}

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

Reply via email to