Creating mixin fails if target has no default constructor
Hello,
Is it true that the target object of a mixin has to have a default constructor? I'm using cglib 2.1_2 and spring 1.2.1. I've got following code to create a mixin:
Code:
Exception e = ...
String stackTrace = ...
ProxyFactory factory = new ProxyFactory();
factory.setProxyTargetClass(true); // Enforce CGLIB usage
factory.setTarget(e); // Exception which has to be wrapped
MockControl stControl
= MockControl.createControl(ServerSideStackTrace.class);
ServerSideStackTrace st
= (ServerSideStackTrace) stControl.getMock();
st.getServiceSideStackTrace();
stControl.setReturnValue(stackTrace, 0, Integer.MAX_VALUE);
stControl.replay();
factory.addAdvisor(0, new DefaultIntroductionAdvisor(
new DelegatingIntroductionInterceptor(st),
ServerSideStackTrace.class));
Exception wrappedException
= (Exception) factory.getProxy();
stControl.verify();
return wrappedException;
I've got the interface ServerSideStackTrace which has a method getServiceSideStackTrace to return a string. If the given exception e has a default constructor this code works. If not factory.getProxy() throws following exception:
Code:
java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:712)
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)
at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:194)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:150)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:67)
at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.DefaultHandler.enrichExceptionWithStackTrace(DefaultHandler.java:291)
at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.DefaultHandler.translateToBusinessException(DefaultHandler.java:196)
at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.SoapExceptionManager.translateToBusinessException(SoapExceptionManager.java:179)
at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.ClientSoapInvocationHandler.findAndTranslateAxisFault(ClientSoapInvocationHandler.java:96)
at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.ClientSoapInvocationHandler.findAndTranslateAxisFault(ClientSoapInvocationHandler.java:98)
at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.ClientSoapInvocationHandler.invoke(ClientSoapInvocationHandler.java:75)
at $Proxy2.throwMeASpecialException(Unknown Source)
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:324)
at ch.elca.leaf3.services.remoting.ClientContextInvocationHandler.invoke(ClientContextInvocationHandler.java:126)
at $Proxy3.throwMeASpecialException(Unknown Source)
at ch.elca.leaf3.tests.remoting.CalculatorSoapTest.testSpecialExceptionBehaviour(CalculatorSoapTest.java:93)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Does anybody see what I'm doing wrong?
Thanks for your help!
Cheers,
Martin