Using Salve to solve serialization issues (in Wicket)

162 views
Skip to first unread message

alecswan

unread,
Mar 21, 2010, 10:18:28 PM3/21/10
to Salve
I have a test which instantiates a ScheduleTestPanelSource object
which needs to be serialized. Here is the structure of the class:

public class SchedulePanelSource implements TestPanelSource {
@Dependency
private IMockScheduleService mockScheduleService;

public Panel getTestPanel(String panelId) { .. some code in
here .. }
}

I was getting serialization exceptions because mockScheduleService is
a non-serializable mock object. I decided to use Salve's @Dependency
annotation to fix this.

At this point I configured my application to use Salve and the
breakpoint in
SalveConfigurator.setApplicationContext(ApplicationContext context)
gets hit. However, SpringBeanLocator.locate(Key key) is never called
and mockScheduleService is never injected.

How can I fix this?

Thanks.

Igor Vaynberg

unread,
Mar 22, 2010, 1:38:07 AM3/22/10
to salve...@googlegroups.com
salve is a bytecode instrumentor. make sure that the instrumentors run
either as an ide plugin (eclipse/ide) or as a maven2 plugin

-igor

> --
> You received this message because you are subscribed to the Google Groups "Salve" group.
> To post to this group, send email to salve...@googlegroups.com.
> To unsubscribe from this group, send email to salve-disc+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/salve-disc?hl=en.
>
>

alecswan

unread,
Mar 22, 2010, 1:46:56 AM3/22/10
to Salve
I am pretty sure I configured -javaagent:C:/lib/salve/salve-2.x/salve-
agent-2.1-SNAPSHOT.jar correctly because JVM won't start with the
wrong java agent path. FYI, I am using NetBeans for development.

Any other ideas?

Thanks.

On Mar 21, 11:38 pm, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> salve is a bytecode instrumentor. make sure that the instrumentors run
> either as an ide plugin (eclipse/ide) or as a maven2 plugin
>
> -igor
>

Igor Vaynberg

unread,
Mar 22, 2010, 3:07:32 AM3/22/10
to salve...@googlegroups.com
there is an easy way to check if the classes are being instrumented,
make a method that tries to retrieve the @dependency field via
reflection. if the field is still there the class is not instrumented.
make sure salve2.xml is configured properly, see examples in the wiki.

-igor

alecswan

unread,
Mar 22, 2010, 11:44:50 AM3/22/10
to Salve
I made sure that META-INF/salve2.xml is on the classpath. BTW, you may
want to update http://code.google.com/p/salve/wiki/ConfiguringInstrumentation2
to say salve2.xml instead of salve.xml.

I also put the following Salve libraries on the classpath: salve-
agent-2.1-SNAPSHOT.jar, salve-depend-2.1-SNAPSHOT.jar, salve-depend-
inst-2.1-SNAPSHOT.jar, salve-depend-spring-2.1-SNAPSHOT.jar, salve-
inst-2.1-SNAPSHOT.jar and salve-depend-spring-inst-2.1-SNAPSHOT.jar.

I added the following code to extract field value using reflection and
it prints out null for the field value.

public class SchedulePanelSource implements TestPanelSource
{

private final Schedule schedule;

@Dependency
private IMockScheduleService mockScheduleService;

@Override
public Panel getTestPanel(String panelId) {
Field[] fieldlist = getClass().getDeclaredFields();
for (Field field : fieldlist) {
try {
final Object fieldValue = field.get(this);

Logger.getLogger(this.getClass().getName()).info(field.getName() + " =
" + fieldValue); // THIS PRINTS NULL FOR fieldValue
} catch (IllegalArgumentException ex) {

Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null,
ex);
} catch (IllegalAccessException ex) {

Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null,
ex);
}
}

return new SchedulePanel(panelId);
}
}

On Mar 22, 1:07 am, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> there is an easy way to check if the classes are being instrumented,
> make a method that tries to retrieve the @dependency field via
> reflection. if the field is still there the class is not instrumented.
> make sure salve2.xml is configured properly, see examples in the wiki.
>
> -igor
>

Igor Vaynberg

unread,
Mar 23, 2010, 1:20:02 AM3/23/10
to salve...@googlegroups.com
the fact that the field is still there means salve instrumentors did
not instrument your class. so it is either that salve2.xml does not
have the right package and is skipping your classes, or the jvm agent
is not running for the classloader

-igor

alecswan

unread,
Mar 23, 2010, 11:33:48 AM3/23/10
to Salve
Both META-INF/salve2.xml and javaagent settings look good.

I noticed that no errors are logged or exceptions thrown if I delete
salve2.xml altogether. Does Salve java agent log anything if it's
unable to find salve2.xml? If so, how can I enable that logging?

Thanks,

Alec


On Mar 22, 11:20 pm, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> the fact that the field is still there means salve instrumentors did
> not instrument your class. so it is either that salve2.xml does not
> have the right package and is skipping your classes, or the jvm agent
> is not running for the classloader
>
> -igor
>

> On Mon, Mar 22, 2010 at 8:44 AM, alecswan <alecs...@gmail.com> wrote:
> > I made sure that META-INF/salve2.xml is on the classpath. BTW, you may

> > want to updatehttp://code.google.com/p/salve/wiki/ConfiguringInstrumentation2

Igor Vaynberg

unread,
Mar 23, 2010, 11:35:55 AM3/23/10
to salve...@googlegroups.com
can you try instrumenting using maven or an ide plugin to make sure
your configuration is correct.

-igor

alecswan

unread,
Mar 23, 2010, 12:12:11 PM3/23/10
to Salve
This is an Ant-based project, so I am not sure how to instrument
classes using maven. Are you talking about compile-time or run-time
instrumentation?

NetBeans does not seem to have a separate instrumenting plugin, but it
does allow me to specify VM options used when running "main classes
and unit tests".

@Dependency annotation doesn't seem to work for me when running the
web app in Tomcat after adding -javaagent VM option to Tomcat startup
parameters.

Alec

On Mar 23, 9:35 am, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> can you try instrumenting using maven or an ide plugin to make sure
> your configuration is correct.
>
> -igor
>

alecswan

unread,
Mar 23, 2010, 4:27:02 PM3/23/10
to Salve
I put a breakpoint in salve.agent.Transformer.mergeConfigs(..) and was
able to verify that META-INF/salve2.xml is picked up correctly.
The content of salve2.xml is as follows:
<config>
<packages>
<package>
<name>com.galecsy.lrm</name>
<instrumentors>
<salve.depend.DependencyInstrumentor/>
</instrumentors>
</package>
</packages>
</config>

The classes that have @Dependency-annotated fields are in sub-packages
of com.galecsy.lrm.

Could you confirm that I am not missing any Salve libraries on the


classpath: salve-
agent-2.1-SNAPSHOT.jar, salve-depend-2.1-SNAPSHOT.jar, salve-depend-
inst-2.1-SNAPSHOT.jar, salve-depend-spring-2.1-SNAPSHOT.jar, salve-
inst-2.1-SNAPSHOT.jar and salve-depend-spring-inst-2.1-SNAPSHOT.jar

By the way, I am using @Dependency annotation as suggested by your
code on this page http://wicketinaction.com/2008/09/building-a-smart-entitymodel/

Any ideas on how to troubleshoot this further?

Thanks,

Alec

alecswan

unread,
Mar 23, 2010, 6:55:49 PM3/23/10
to Salve
I think I figured it out. I had to add salve-asm and salve-config jars
to the classpath to get the code instrumented correctly. I should have
checked Maven dependencies carefully. What a pain!

Now I am trying to deploy the web app in Tomcat and getting
java.lang.NoClassDefFoundError: salve/InstrumentationException.

I tried copying some Salve jars (including salve-inst) to TOMCAT/lib
and TOMCAT/common/lib, but that didn't fix the problem. Is there a
wiki page which explains where to put Salve jars in Tomcat?

Thanks,

Alec


On Mar 23, 2:27 pm, alecswan <alecs...@gmail.com> wrote:
> I put a breakpoint in salve.agent.Transformer.mergeConfigs(..) and was
> able to verify that META-INF/salve2.xml is picked up correctly.
> The content of salve2.xml is as follows:
> <config>
>   <packages>
>     <package>
>       <name>com.galecsy.lrm</name>
>       <instrumentors>
>         <salve.depend.DependencyInstrumentor/>
>       </instrumentors>
>     </package>
>   </packages>
> </config>
>
> The classes that have @Dependency-annotated fields are in sub-packages
> of com.galecsy.lrm.
>
> Could you confirm that I am not missing any Salve libraries on the
> classpath: salve-
> agent-2.1-SNAPSHOT.jar, salve-depend-2.1-SNAPSHOT.jar, salve-depend-
> inst-2.1-SNAPSHOT.jar, salve-depend-spring-2.1-SNAPSHOT.jar, salve-
> inst-2.1-SNAPSHOT.jar and salve-depend-spring-inst-2.1-SNAPSHOT.jar
>
> By the way, I am using @Dependency annotation as suggested by your

> code on this pagehttp://wicketinaction.com/2008/09/building-a-smart-entitymodel/

alecswan

unread,
Mar 24, 2010, 8:35:36 PM3/24/10
to Salve
I got my tests to work with Salve, but I cannot get the webapp to work
in Tomcat. All Salve JARs are in CATALINA/lib.

Any ideas? Thanks.

Using CATALINA_BASE: C:\Program Files\Apache Software Foundation
\apache-tomcat-6.0.20
Using CATALINA_HOME: C:\Program Files\Apache Software Foundation
\apache-tomcat-6.0.20
Using CATALINA_TMPDIR: C:\Program Files\Apache Software Foundation
\apache-tomcat-6.0.20\temp
Using JRE_HOME: C:\Program Files\Java\jdk1.6.0_11
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:597)
at
sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:
323)
at
sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:
338)
FATAL ERROR in native method: processing of -javaagent failed
Caused by: java.lang.NoClassDefFoundError: salve/
InstrumentationException
at salve.agent.Agent.newTransformer(Agent.java:36)
at salve.agent.Agent.premain(Agent.java:43)
... 6 more
Caused by: java.lang.ClassNotFoundException:
salve.InstrumentationException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
320)
... 8 more
Exception in thread "main"

Igor Vaynberg

unread,
Mar 24, 2010, 10:57:51 PM3/24/10
to salve...@googlegroups.com
make sure salve-inst.jar is also available inside the war, maybe that
will help. i havent tried tomcat with java agent myself.

-igor

alecswan

unread,
Mar 24, 2010, 11:20:04 PM3/24/10
to Salve
All Salve jars are in WEB-INF/lib as well as CATALINA/lib.

In one of the messages on the Wicket mailing list it sounded like you
were using Salve in your webapp. How did you configure it?

Thanks.

Igor Vaynberg

unread,
Mar 24, 2010, 11:50:50 PM3/24/10
to salve...@googlegroups.com
i use it on quiet a few projects, but i do not use the jvm agent. i
instrument the code at build time and include the jars in web-inf/lib.
never had a problem like this. dont see why tomcat would not be able
to find the jar. maybe try also putting them into tomcat/endorsed?

-igor

alecswan

unread,
Mar 25, 2010, 11:26:21 AM3/25/10
to Salve
Putting JARs in tomcat/endorsed helped solve the previous problem.
However, now I am getting a different exception shown below. It seems
like it now chokes on <bean
class="salve.depend.spring.SalveConfigurator" /> element in the Spring
application context. Any ideas?

Could you also explain how you instrument your WAR files and compile
time? Is there an Ant task I can use for this?

Thanks


Mar 25, 2010 9:16:43 AM org.apache.catalina.core.StandardContext
listenerStart
SEVERE: Exception sending context initialized event to listener
instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Error
loading class [salve.depend.spring.SalveConfigurator] for bean with
name 'salve.depend.spring.SalveConfigurator#0' defined in
ServletContext resource [/WEB-INF/config/lrm-service.xml]: problem
with class file or dependent class; nested exception is
java.lang.NoClassDefFoundError: org/springframework/context/
ApplicationContextAware
at
org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:
1144)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:
524)
at
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:
1177)
at
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:
758)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:
422)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:
728)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:
380)
at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:
255)
at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:
199)
at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:
45)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:
3934)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:
4429)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:
791)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:
771)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:
630)
at
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:514)
at
org.apache.catalina.startup.HostConfig.check(HostConfig.java:1288)


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)

Mar 25, 2010 9:16:43 AM org.apache.catalina.core.StandardContext
listenerStart
SEVERE: Exception sending context initialized event to listener
instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Error
loading class [salve.depend.spring.SalveConfigurator] for bean with
name 'salve.depend.spring.SalveConfigurator#0' defined in
ServletContext resource [/WEB-INF/config/lrm-service.xml]: problem
with class file or dependent class; nested exception is
java.lang.NoClassDefFoundError: org/springframework/context/
ApplicationContextAware
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:
1144)
at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:
297)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:
524)
at
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:
1177)
at
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:
758)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:
836)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at
org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:
1473)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:
422)
at
org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:
824)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:
728)
at
org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:
350)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
617)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:
380)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
717)
at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:
255)
at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:
199)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290)
at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:
45)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:
3934)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:
4429)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
191)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:
791)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:
525)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:
771)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
293)
at
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:
630)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
849)
at
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:514)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:583)
at
org.apache.catalina.startup.HostConfig.check(HostConfig.java:1288)
at org.apache.tomcat.util.net.JIoEndpoint
$Worker.run(JIoEndpoint.java:454)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.Thread.run(Thread.java:619)


On Mar 24, 9:50 pm, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> i use it on quiet a few projects, but i do not use the jvm agent. i
> instrument the code at build time and include the jars in web-inf/lib.
> never had a problem like this. dont see why tomcat would not be able
> to find the jar. maybe try also putting them into tomcat/endorsed?
>
> -igor
>

> On Wed, Mar 24, 2010 at 8:20 PM, alecswan <alecs...@gmail.com> wrote:
> > All Salve jars are in WEB-INF/lib as well as CATALINA/lib.
>
> > In one of the messages on the Wicket mailing list it sounded like you
> > were using Salve in your webapp. How did you configure it?
>
> > Thanks.
>
> > Igor Vaynberg wrote:
> >> make sure salve-inst.jar is also available inside the war, maybe that
> >> will help. i havent tried tomcat with java agent myself.
>
> >> -igor
>

> ...
>
> read more »

Igor Vaynberg

unread,
Mar 25, 2010, 11:34:36 AM3/25/10
to salve...@googlegroups.com
looks like it cannot see your spring jar

java.lang.NoClassDefFoundError: org/springframework/context/
ApplicationContextAware

i use maven2 plugin to instrument at compile time, and eclipse plugin
to do it when im developing.

-igor

alecswan

unread,
Mar 25, 2010, 11:53:46 AM3/25/10
to Salve
All application dependencies, including Spring jars are in WEB-INF/
lib. The application can run if I comment out <bean
class="salve.depend.spring.SalveConfigurator" /> in Spring app
context. Any ideas?

Which maven target does Salve instrumentation?

As a side note, I think it is important to figure out runtime
instrumentation in Tomcat, because it will slow down Salve adoption
otherwise.

Thanks,

Alec

On Mar 25, 9:34 am, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> looks like it cannot see your spring jar
>
> java.lang.NoClassDefFoundError: org/springframework/context/
> ApplicationContextAware
>
> i use maven2 plugin to instrument at compile time, and eclipse plugin
> to do it when im developing.
>
> -igor
>

> ...
>
> read more »

Igor Vaynberg

unread,
Mar 25, 2010, 12:18:13 PM3/25/10
to salve...@googlegroups.com
i think the problem you are hitting is this:

since salve's loader is loaded using tomcat's classloader and not the
one used for your war file none of those classes can see the classes
inside your war. im not really sure what to do about this, i did test
the jvm agent with tomcat a while back, but i dont remember hitting
any of these issues. try with salve 1.1 and see if you hit the same
problem.

there are examples on how to configure the maven plugin on the wiki, i
dont remember the exact phase it kicks in.

-igor

alecswan

unread,
Mar 25, 2010, 2:37:12 PM3/25/10
to Salve
Glassbox uses webapp bytecode instrumentation and requires the
following Tomcat VM options:
-javaagent:'${tomcat_common_lib}\aspectjweaver.jar' -
Dglassbox.install.dir='${tomcat_common_lib}\glassbox'

I think glassbox.install.dir is required in order to avoid problems
with loading classes I am running into with Salve. Do you have
anything like this in Salve?

Thanks.

Alec

On Mar 25, 10:18 am, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> i think the problem you are hitting is this:
>
> since salve's loader is loaded using tomcat's classloader and not the
> one used for your war file none of those classes can see the classes
> inside your war. im not really sure what to do about this, i did test
> the jvm agent with tomcat a while back, but i dont remember hitting
> any of these issues. try with salve 1.1 and see if you hit the same
> problem.
>
> there are examples on how to configure the maven plugin on the wiki, i
> dont remember the exact phase it kicks in.
>
> -igor
>

> ...
>
> read more »

Igor Vaynberg

unread,
Mar 25, 2010, 5:00:18 PM3/25/10
to salve...@googlegroups.com
no, like i said when i tried it i didnt run into the problems you
mention. have you tried with 1.1 yet?

-igor

alecswan

unread,
Mar 25, 2010, 9:35:44 PM3/25/10
to Salve
Are you saying that some time ago you were able to get runtime
instrumentation to work in Tomcat using javaagent VM option? If so,
then I will try Salve 1.1.

On Mar 25, 3:00 pm, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> no, like i said when i tried it i didnt run into the problems you
> mention. have you tried with 1.1 yet?
>
> -igor
>

> ...
>
> read more »

Igor Vaynberg

unread,
Mar 25, 2010, 10:40:57 PM3/25/10
to salve...@googlegroups.com
yes.

-igor

alecswan

unread,
Mar 26, 2010, 3:10:28 PM3/26/10
to Salve
I downloaded and tested with Salve-1.x. I also created salve.xml and
verified that my integration tests that rely on Salve are still
passing.

This is what I tried next:

1. Put all Salve-1.x jars in WEB-INF/lib and pointed javaagent to
salve-agent-1.2-SNAPSHOT.jar. The following exception was thrown:
Exception in thread "main" java.lang.reflect.InvocationTargetException


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces

sorImpl.java:25)


at java.lang.reflect.Method.invoke(Method.java:597)
at
sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Instrumenta
tionImpl.java:323)
at
sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Instrument
ationImpl.java:338)

Caused by: java.lang.NoClassDefFoundError: salve/
InstrumentationException
at salve.agent.Agent.newTransformer(Agent.java:36)
at salve.agent.Agent.premain(Agent.java:43)
... 6 more
Caused by: java.lang.ClassNotFoundException:
salve.InstrumentationException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
320)
... 8 more
FATAL ERROR in native method: processing of -javaagent failed

2. Copied salve-inst-1.2-SNAPSHOT.jar jars in tomcat/endorsed.
Application started up, but no instrumentation was done.

3. Copied all Salve-1.x in tomcat/endorsed.

4. I realized that Salve may not be finding salve.xml and put it in
tomcat/lib/web-inf. This caused the code to get instrumented, but I
got the following error when accessing a Wicket page that used
@Dependency annotation.

Caused by: java.lang.NoClassDefFoundError: org/springframework/context/
ApplicationContext
at
salve.depend.spring.SpringBeanLocator.locate(SpringBeanLocator.java:
68)
at salve.depend.DependencyLibrary.locate(DependencyLibrary.java:99)

5. I realized that I get the above exception because salve-depend-
spring-XXX jars are loaded as a part of the endorsed libraries and
Spring is bundled in my WAR and hence are not visible to salve-depend-
spring-XXX jars. So, I moved salve-depend-spring-XXX jars from
endorsed to my WEB-INF/lib and I was able to access the Wicket page.

Sorry for such a detailed description, I just wasn't sure if I will
get it to work or not.

So, here is the final Tomcat configuration:
1. JAVA_OPTS="-javaagent:C:\lib\salve-agent-1.2-SNAPSHOT.jar"
2. Tomcat/endorsed contains all Salve jars except salve-depend-spring-
XXX jars.
3. Tomcat/lib/META-INF contains salve.xml.
4. WEB-INF/lib contains salve-depend-spring-XXX jars and other Salve
jars, which is probably redundant.

I am sure I could move some jars around to achieve a minimal
configuration. Maybe later.

So, now I will try to switch back to Salve-2.x.

Thanks,

Alec

On Mar 25, 8:40 pm, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> yes.
>
> -igor
>

> ...
>
> read more »

Igor Vaynberg

unread,
Mar 26, 2010, 7:37:59 PM3/26/10
to salve...@googlegroups.com
nice, let me know how it goes

-igor

alecswan

unread,
Mar 27, 2010, 10:48:08 AM3/27/10
to Salve
I got Salve-2.x to work the same way I did Salve-1.x to work.

I am not very happy with the setup complexity involved in deployment
time instrumentation and would like to try and instrument my classes
at compile time.

I am using NetBeans and Ant. Could you provide any guidelines on how
to get it to work with Ant?

Thanks.

On Mar 26, 5:37 pm, Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
> nice, let me know how it goes
>
> -igor
>

> ...
>
> read more »

Igor Vaynberg

unread,
Mar 27, 2010, 12:09:21 PM3/27/10
to salve...@googlegroups.com
take a look at the salve-maven2 plugin source, most of the code to do
the instrumentation is factored out. you can write an ant task to call
out to salve and do the instrumentation.

-igor

Alec Swan

unread,
Mar 30, 2010, 10:49:19 PM3/30/10
to salve...@googlegroups.com
Hi Igor,

I got Spring compile-time instrumentation to work by pointing my iajc Ant target to srping-aspects.jar which contains meta-int/aop.xml.

Could you provide aop.xml that weaves Salve aspects or a list of Salve aspects that need to be weaved?

Thanks,

Alec

Igor Vaynberg

unread,
Mar 30, 2010, 11:21:53 PM3/30/10
to salve...@googlegroups.com
you will have to use a salve snapshot from trunk. there is a
salve.depend.DependencyAspect you have to use for injection. you dont
need the transactional aspect anymore because spring comes with one.

-igor

Alec Swan

unread,
Mar 31, 2010, 6:26:44 PM3/31/10
to salve...@googlegroups.com
I noticed that some of the modules, such as Salve XML Configuration Builder, are missing from 3.0. Do I need to copy them from 2.0? If so, which ones do I need to copy?

Thanks.

Alec Swan

unread,
Mar 31, 2010, 6:27:58 PM3/31/10
to salve...@googlegroups.com
Also, how do I configure Salve 3.0? Do I need to have META-INF/salve3.xml on the classpath?

Igor Vaynberg

unread,
Mar 31, 2010, 6:59:18 PM3/31/10
to salve...@googlegroups.com
salve 3 is based on aspectj, there is no longer a custom config file
because it piggy-backs on aspectj configuration mechanism. that is why
some modules are missing - they are no longer needed.

-igor

Alec Swan

unread,
Mar 31, 2010, 11:43:24 PM3/31/10
to salve...@googlegroups.com
Hi Igor,

I got Salve 3.0 compile-time instrumentation to work with my production code and all but one test. I have the following class with a @Dependency on a field. When the field is private, Salve 3.0 advice does not get applied. This is strange, because it works with my production classes with @Dependency annotations on private fields.

Why can the field not be private?

When I make the field anything but private, then I get a runtime exception shown below.

This exception is actually coming from the following Wicket 1.4.5 code:
type.isAssignableFrom(entry.getValue().getClass())

Note that entry.getValue() can be null if the value of a bean is null.

Caused by: java.lang.reflect.InvocationTargetException
        at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at salve.depend.DependencyAspect.handleRead(DependencyAspect.aj:59)
        at salve.depend.DependencyAspect.ajc$inlineAccessMethod$salve_depend_DependencyAspect$salve_depend_DependencyAspect$handleRead(DependencyAspect.aj:1)
        at com.galecsy.lrm.wicket.coolutil.sources.SchedulePanelSource$1.mockScheduleService_aroundBody1$advice(SchedulePanelSource.java:25)
        at com.galecsy.lrm.wicket.coolutil.sources.SchedulePanelSource$1.saveSchedule(SchedulePanelSource.java:37)
        at com.galecsy.lrm.web.wicket.offer.delivery.scheduling.SchedulePanel$1.onSubmit(SchedulePanel.java:83)
        at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1536)
        at org.apache.wicket.markup.html.form.Form.process(Form.java:925)
        at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:887)
Caused by: java.lang.NullPointerException
        at org.apache.wicket.spring.test.ApplicationContextMock.getBeansOfType(ApplicationContextMock.java:121)

        at salve.depend.spring.SpringBeanLocator.locate(SpringBeanLocator.java:68)
        at salve.depend.DependencyLibrary.locate(DependencyLibrary.java:99)
        at salve.depend.DependencyAspect.handleRead(DependencyAspect.aj:52)

Igor Vaynberg

unread,
Apr 1, 2010, 12:17:41 AM4/1/10
to salve...@googlegroups.com
can you show me a bit more code?

the one area where salve 2.0 is better then 3.0 is that you can access
private fields of outer class from an inner class. in salve 3.0 this
access is not instrumented because aspectj does not instrument
synthetic methods and this is what the compiler uses to create a
getter for the private field that the inner class uses to get the
value.

if you can create a testcase that reproduces your problem that is even
better. keep in mind that while i think everything in 3.0 works i
havent had a chance to use it in production yet (still on 2.0). but
there are plenty of unit tests there.

-igor

Alec Swan

unread,
Apr 3, 2010, 2:46:04 AM4/3/10
to salve...@googlegroups.com
Hi Igor,

As I continue using your article on building smarter entity models and Salve I ran into another problem with lazily loaded collections on such entity models.

Suppose that in your example EntityModel<Person> the Person class has a lazily loaded collection Set<addresses>. The first Wicket page loads EntityModel<Person> and displays user's first and last name and closes the Hibernate session. The second page which displays person addresses throws an exception because the session that the person is associated with has already been closed.

Can you think of a clean way to solve this problem with the proposed EntityModel pattern?

Thanks,

Alec

Igor Vaynberg

unread,
Apr 3, 2010, 2:58:26 AM4/3/10
to salve...@googlegroups.com
why would you keep the Person instance across sessions in your model?
my model would detach it and reload it in the next request.

-igor

alec...@gmail.com

unread,
Apr 3, 2010, 3:09:09 AM4/3/10
to salve...@googlegroups.com
Actually what happens in my case is that I have a wicket page with a form on it. The Person model is a property of the page. The form is an inner class of the page class. The form.onSubmit() method calls getAddresses() method on the person model property of the outer page class and throws an exception because the person was loaded by a different hibernate session when the page was rendered.

Sent via BlackBerry from T-Mobile

Alec Swan

unread,
Apr 3, 2010, 3:20:40 AM4/3/10
to salve...@googlegroups.com
Maybe it's because I am not setting the person's model as the page's model and instead keep it around as another page property.

Alec Swan

unread,
Apr 3, 2010, 3:28:04 AM4/3/10
to salve...@googlegroups.com
Nope, I am still getting the following exception when submitting delete address form.

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: Person.addresses, no session or session was closed

Alec Swan

unread,
Apr 3, 2010, 3:40:09 AM4/3/10
to salve...@googlegroups.com
Hi Igor,

It is getting kind of late here and I just noticed that I was not passing the model to the form constructor as you showed in your example.

It works now.

Thanks,

Alec
Reply all
Reply to author
Forward
0 new messages