Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By default Struts 1.3 (latest 1.3.x) put action classes in cache to optimize performance (restarting deployment purge the cache). That was the cause of the exception because my modified classes are loaded by a different classloader from the previous one which was in cache.</p> <p>This exception occurs during the step of retrieving the action instance (which starts here in the stacktrace).</p> <pre><code>at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) </code></pre> <p><a href="http://wiki.apache.org/struts/ComposableRequestProcessor" rel="nofollow">By default this version of Struts implements the chain of responsability pattern</a> (using an xml configuration file chain-config.xml). Thus the <a href="http://struts.apache.org/1.3.10/apidocs/org/apache/struts/chain/ComposableRequestProcessor.html" rel="nofollow">request processor mentioned above</a> delegates action instance retrieving (or instantiation) to a <a href="http://struts.apache.org/1.3.10/apidocs/org/apache/struts/chain/commands/servlet/CreateAction.html" rel="nofollow">CreationAction</a> implementation (which is showed here in the stactrace) :</p> <pre><code>at org.apache.struts.chain.commands.servlet.CreateAction.getAction(CreateAction.java:65) </code></pre> <p>Following are solutions to avoid ClassCastException when making changes and donnot want to restart deployment.</p> <p>Solution 1 :</p> <ul> <li><p>Extend CreateAction with a custom class and redefine its getAction() method</p></li> <li><p>In getAction() : If the <strong>super.getAction().getClass()</strong> has not the same classloader than the new one then make it return a new instance by calling <strong>super.createAction()</strong> <em>(That means that I should know the qualified class name of my Action class when comparing using the == operator otherwise I should not compare and always load a new action class with createAction)</em></p></li> <li><p><a href="http://struts.apache.org/1.3.10/faqs/newbie.html#chain" rel="nofollow">Use a custom chain-config.xml</a> to specify to use the custom <a href="http://struts.apache.org/1.3.10/apidocs/org/apache/struts/chain/commands/servlet/CreateAction.html" rel="nofollow">CreationAction</a> instead of the default one</p></li> </ul> <p>Solution 2 : Extend <a href="http://struts.apache.org/1.3.10/apidocs/org/apache/struts/action/RequestProcessor.html" rel="nofollow">RequestProcessor</a> with a custom class and use it instead of the default one (i.e update parameters in struts-config.xml)</p> <p>I think doing these should only be done when in development stage (to save some testing time) and should be avoid when in production stage for performance (and security) reasons.</p> <p>I couldn't have free time to add more detailled example code, config files, etc... I'll try to do it one day (somewhere else). But for sure I test these and it worked for my purpose :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload