<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Rob Harrop's Blog</title>
	<link>http://blog.springframework.com/rob</link>
	<description>Core Purge</description>
	<pubDate>Sat, 17 Dec 2005 13:08:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>
	<language>en</language>
			<item>
		<title>[TSE] Slides for Advanced MVC, Scheduling and JMX Presentations</title>
		<link>http://blog.springframework.com/rob/archives/2005/12/17/tse-slides-for-advanced-mvc-scheduling-and-jmx-presentations/</link>
		<comments>http://blog.springframework.com/rob/archives/2005/12/17/tse-slides-for-advanced-mvc-scheduling-and-jmx-presentations/#comments</comments>
		<pubDate>Sat, 17 Dec 2005 13:07:40 +0000</pubDate>
		<dc:creator>Rob Harrop</dc:creator>
		
	<category>Spring</category>
		<guid isPermaLink="false">http://blog.springframework.com/rob/?p=6</guid>
		<description><![CDATA[
Well, I&#8217;m finally back from my conference tour and feeling human again. As promised to all the attendees at TSE, here are the presentations for MVC, scheduling and JMX that I gave at TSE along with the code for the sample application and the demos.

Presentations:
Advanced Spring MVC
Enterprise Management with Spring and JMX
Scheduling and Task Execution


Code:
DVD [...]]]></description>
			<content:encoded><![CDATA[<p>
Well, I&#8217;m finally back from my conference tour and feeling human again. As promised to all the attendees at TSE, here are the presentations for MVC, scheduling and JMX that I gave at TSE along with the code for the sample application and the demos.</p>
<p>
<strong>Presentations:</strong><br />
<a href='/rob/wp-content/advancedspringmvc.pdf' title='Advanced Spring MVC'>Advanced Spring MVC</a><br />
<a href='/rob/wp-content/enterprisemanagement.pdf' title='Enterprise Management with Spring and JMX'>Enterprise Management with Spring and JMX</a><br />
<a href='/rob/wp-content/scheduling.pdf' title='Scheduling and Task Execution'>Scheduling and Task Execution</a>
</p>
<p>
<strong>Code:</strong><br />
<a href='/rob/wp-content/dvdcentral.zip' title='DVD Central Sample Application'>DVD Central Sample Application</a><br />
<a href='/rob/wp-content/jmxsamples.zip' title='JMX Samples'>JMX Samples</a><br />
<a href='/rob/wp-content/schedulingexamples.zip' title='Scheduling Examples'>Scheduling Examples</a>
</p>
<p>
The sample application was written for <a href="http://commerce.bea.com/index.jsp" target="_blank">WebLogic Server 9</a> and <a href="http://www.oracle.com/technology/software/products/database/oracle10g/index.html" target="_blank">Oracle 10g</a>, but it should be easy to port most functionality to other app servers/databases. The CommonJ scheduling functionality will only work on WebLogic Server 9 or on WebSphere 6.</p>
<p>
<strong>All code requires Spring 2.0 M1 or above. This is planned for release on Monday but you can obtain the latest nightly snapshot at <a href="http://oldwww.springframework.org/downloads/nightly/">springframework.org</a>.</strong></p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.springframework.com/rob/archives/2005/12/17/tse-slides-for-advanced-mvc-scheduling-and-jmx-presentations/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Controlling MBean Registration Behavior in Spring</title>
		<link>http://blog.springframework.com/rob/archives/2005/10/14/controlling-mbean-registration-behavior-in-spring/</link>
		<comments>http://blog.springframework.com/rob/archives/2005/10/14/controlling-mbean-registration-behavior-in-spring/#comments</comments>
		<pubDate>Fri, 14 Oct 2005 08:52:32 +0000</pubDate>
		<dc:creator>Rob Harrop</dc:creator>
		
	<category>Spring</category>
		<guid isPermaLink="false">http://blog.springframework.com/rob/?p=5</guid>
		<description><![CDATA[Until quite recently, the JMX support in Spring gave you little control over the registration of MBeans that may already exist. This caused problems in applications that wanted to share MBeans with other applications, or in scenarios where MBean cleanup isn't guaranteed. As of Spring 1.2.5 we introduced a new feature to allow for much better control of MBean registration behaviour.]]></description>
			<content:encoded><![CDATA[<p>In Spring 1.2.5 I modified the <code>MBeanExporter</code> to provide users with more control over MBean registration. Previously, the <code>MBeanExporter</code> would attempt to register an MBean and fail if that MBean already existed. In many cases this is the desired behavior; however there are two particular cases where this behavior is not desirable:</p>
<ol>
<li>You have many applications sharing an MBean - perhaps as a mechanism for sharing data</li>
<li>You have a situation whereby an MBean may not be unregistered when redeploying the application</li>
</ol>
<p>In the first situation, you are deloying multiple applications each of which wants to register and access the same MBean say, for example, <code>spring:type=Shared</code>. Previously in Spring, the first application you deployed would deploy successfully and all others would fail when trying to register the shared MBean. As of Spring 1.2.5, you can get around this by setting the <code>registrationBehaviorName</code> property of the <code>MBeanExporter</code> to <code>REGISTRATION_IGNORE_EXISTING</code>, instructing <code>MBeanExporter</code> to attempt to register the MBean and continue happily along if it finds that MBean is already registered. So in the scenario I highlighted, the first application would go ahead and register the MBean <code>spring:type=Shared</code> and each subsequent application would simply detect that this MBean already existed and continue through the registration process.</p>
<pre>
&lt;bean id=&quot;exporter&quot; class=&quot;org.springframework.jmx.export.MBeanExporter&quot;&gt;
        ...
	&lt;property name=&quot;registrationBehaviorName&quot; value=&quot;REGISTRATION_IGNORE_EXISTING&quot;/&gt;
	...
&lt;/bean&gt;
</pre>
<p>In the second scenario, you are deploying the same application again and again, perhaps in a development environment, but application server is not correctly signalling the application shutdown to Spring. As such, the <code>MBeanExporter</code> is unaware that it should be unregistering its MBeans and the MBeans are left registered when you come to redeploy the application. In this case, you can set the registrationBehavior property to <code>REGISTRATION_REPLACE_EXISTING</code> and have the <code>MBeanExporter</code> simply unregister the residual MBean and replace it with the new one.</p>
<pre>
&lt;bean id=&quot;exporter&quot; class=&quot;org.springframework.jmx.export.MBeanExporter&quot;&gt;
        ...
	&lt;property name=&quot;registrationBehaviorName&quot; value=&quot;REGISTRATION_REPLACE_EXISTING&quot;/&gt;
	...
&lt;/bean&gt;
</pre>
<p>This is just the first of many new JMX-related features coming to Spring in the coming months. In the 1.3 release we will have support for JMX notifications, enabling you to configure notification listeners using Spring and to access notification publication infrastructure. We are introducing a new <code>MBeanInfoAssembler</code>, which allows you to define MBean interfaces using an XML descriptor, plus we will be improving the <code>MBeanExporter</code> itself to allow you to register your own MBeans at runtime using Spring&#8217;s management interface generation capabilities. In the longer term we will be adding JMX management capabilities to Spring itself allowing you to control and monitor aspects of framework. In particular, we will be focusing on adding monitoring capabilties to the JDBC and MVC components of the framework.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.springframework.com/rob/archives/2005/10/14/controlling-mbean-registration-behavior-in-spring/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Caveats with Class Proxying in Spring</title>
		<link>http://blog.springframework.com/rob/archives/2005/08/18/caveats-with-class-proxying-in-spring/</link>
		<comments>http://blog.springframework.com/rob/archives/2005/08/18/caveats-with-class-proxying-in-spring/#comments</comments>
		<pubDate>Thu, 18 Aug 2005 12:39:17 +0000</pubDate>
		<dc:creator>Rob Harrop</dc:creator>
		
	<category>Spring</category>
		<guid isPermaLink="false">http://blog.springframework.com/rob/?p=4</guid>
		<description><![CDATA[Recently, Jieba Wu posted an interesting bug report on the Spring JIRA detailing a  problem he was having when proxying Spring MVC Controllers using CGLIB proxies. Essentially, he would create his target Controller object, pass in some dependency using Spring IoC and then proxy the Controller. At runtime, all invocations were sent directly to [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, Jieba Wu posted an interesting <a href="http://opensource.atlassian.com/projects/spring/browse/SPR-1211">bug report</a> on the Spring JIRA detailing a  problem he was having when proxying Spring MVC <code>Controllers</code> using CGLIB proxies. Essentially, he would create his target <code>Controller</code> object, pass in some dependency using Spring IoC and then proxy the <code>Controller</code>. At runtime, all invocations were sent directly to the proxy and not to the target. As a result he was seeing <code>NullPointerExceptions</code> because state from the <strong>target</strong> is not copied to the <strong>proxy</strong> when creating a class proxy. </p>
<p>After many back and forth exchanges we managed to determine that Jieba was actually extending Spring&#8217;s <code>AbstractCommandController</code> which declares the <code>handleRequest() </code>method as final. This causes an issue when CGLIB proxies, because CGLIB cannot override that method (just like any Java code) and it will not be proxied. The result at runtime is that, although we have a proxy object, calls to the <code>final</code> methods are not intercepted and redirected through the advice chain to the target, instead they are sent directly to the proxy instance which is not configured with the correct state.</p>
<p>So what does this mean in real terms? Well, consider the class below:</p>
<pre>
public class MyBean {
	private String name;

	public final String getName() {
		return name;
	}

	public final void setName(String name) {
		this.name = name;
	}
}
</pre>
<p>Here you can see a simple bean with a single <code>private</code> field and two <code>public final</code> methods. Now consider this unit test:</p>
<pre>
public void testProxyClassWithFinalMethods() throws Exception {

	MyBean bean = new MyBean();
	bean.setName(&quot;Rob Harrop&quot;);

	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.addAdvice(new NopInterceptor());
	proxyFactory.setTarget(bean);
	proxyFactory.setProxyTargetClass(true);

	MyBean proxy = (MyBean)proxyFactory.getProxy();

	// name on target should still be not null
	assertNotNull(bean.getName());

	// getName() is final so cant intercept - method call goes directly to
	// the proxy and will not have access to a valid name field
	assertNull(proxy.getName());
}
</pre>
<p>What we are going to see here is that we first create the target object which is an instance of <code>MyBean</code>, then we create a proxy for the target adding in a <code>NopInterceptor</code>. When CGLIB comes to create the proxy it will take all non-final methods and give Spring a chance to define how that method should be proxied. Note the disclaimer from that sentence - only non-final methods are proxied. Of course, if you think about it, since CGLIB is creating a dynamic subclass of your target class, then there is no real way around this. </p>
<p>At runtime what will happen when you invoke one of the <code>final</code> methods on the proxy is that the invocation will <strong>not</strong> be intercepted and, instead, it will be sent directly to the proxy object. This essentially presents two problems: firstly, your advice chain won&#8217;t be invoked, potentially causing havoc in your application, and secondly the invocation may die when it try to access state that will not be initialized in the proxy.</p>
<p>The moral of this story is that you need to be extra careful when creating your Spring AOP proxies using CGLIB because things like <code>final</code> methods will cause problems. Interestingly, in the case cited in the bug report, the <code>final</code> method in question was actually defined on the <code>Controller</code> interface and as such this kind of proxy will work perfectly fine when using JDK proxies in Spring. </p>
<p>My recommendation? Use JDK proxies unless you have real issues with performance or you are dealing with legacy code that doesn&#8217;t implement the interfaces you need for JDK proxies.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.springframework.com/rob/archives/2005/08/18/caveats-with-class-proxying-in-spring/feed/</wfw:commentRSS>
		</item>
	</channel>
</rss>
