struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andriy Pererva <andronix1...@gmail.com>
Subject Re: Struts 2 custom ClassLoader
Date Thu, 24 Sep 2009 12:58:15 GMT
Thank you so much, guys!
I created the custom ObjectFactory, override the only method -
getClassInstance() in order to enforce Struts to use my custom
ClassLoader, so now all the action classes load from the "right
place".
Now just one problem remained. Some of my struts.xml's parts should
also stay in the custom location (not under classpath, as regular
struts.xml). How can I enforce Struts to use my custom classloader's
getResource()/getResourceAsStream() methods to load these
configuration file parts?
According to the book "Struts 2 in Action", the ObjectFactory
considered an "official" extension point for plug-ins (pages 320 -
321), but I haven't seen any extension points for configuration
providers. What class/method should I override and how can I wire this
class with Struts in plug-in-like way, i.e. without tampering in the
struts core libs?
Thank you in advance for any useful answer!

With best regards,
Andriy


On Wed, Sep 9, 2009 at 4:41 PM, Wes Wannemacher<wesw@wantii.com> wrote:
> I don't know if I would override the class loader (did I suggest that
> earlier, if so, sorry :( ). I would take a look at overriding the
> buildBean methods. Use your custom classloader to build the 'beans'
> but do it in a way that tries your classloader first, then falls
> through to the super class... For instance, the key lines in xwork's
> SpringObjectFactory (which is where the meat of the spring-plugin is
> located) looks like this -
>
>            if (appContext.containsBean(className)) {
>                clazz = appContext.getBean(className).getClass();
>            } else {
>                clazz = super.getClassInstance(className);
>            }
>
> The SpringObjectFactory is a bit large-ish because we added some
> helpful spring integration (supporting autowiring, etc.), but IMO it
> is still the best example for you to get what you want. I don't think
> our fisheye instance at opensymphony is working, so the best thing to
> do is either check out xwork from svn -
>
> svn co http://svn.opensymphony.com/svn/xwork/trunk
>
> And you'll find SpringObjectFactory.java in there under
> trunk/core/src/main/java/com/opensymphony/xwork2/spring
>
> Or if you're not into svn, then you can probably just download the
> file by hitting the following URL in your browser -
>
> http://svn.opensymphony.com/svn/xwork/trunk/core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java
>
> -Wes
>
> On Wed, Sep 9, 2009 at 6:25 AM, Andriy Pererva <andronix1983@gmail.com> wrote:
>> Hello, Wes!
>> Thank you for your quick help! I did exactly what you advised me, but
>> something still doesn't work. Here are my steps:
>> 1) Created CustomObjectFactory which extends StrutsObjectFactory, with
>> only one method overriden - setClassLoader(). Inside this method I
>> simply pass my custom classloader to super.setClassLoader().
>> 2) Inserted in my struts.xml (right after struts-default.xml
>> inclusion) next strings:
>>  <bean type="com.opensymphony.xwork2.ObjectFactory"
>> name="customFactory"
>> class="efi.base.web.framework.CustomObjectFactory" />
>>  <constant name="struts.objectFactory" value="customFactory"/>
>> After that I tried to debug my CustomObjectFactory in Eclipse, but my
>> overriden method setClassLoader() hasn't been invoked during struts
>> initialization.
>> Currently we are using Struts 2.0.11.
>> Please, tell me what I'm doing wrong? What is the most neat way to
>> intelligently pass my classloader to Struts?
>> Again, thank you in advance for you answer!
>>
>>
>> With best regards,
>> Andriy
>>
>>
>>
>> On Thu, Sep 3, 2009 at 4:39 PM, Wes Wannemacher<wesw@wantii.com> wrote:
>>> I would suggest creating your own plugin... If the custom classes are
>>> actions, validators, interceptors and type converters then just take a
>>> look at the spring plugin for an example. You will want to write your
>>> own implementation of the ObjectFactory, the ObjectFactory is in
>>> charge of creating the struts2 app's actions, validators,
>>> interceptors, type converters and beans.
>>>
>>> As far as enhancing the functionality of struts.xml processing, I
>>> would first suggest you see if you can retrofit your application to
>>> work with one of the existing plugins like 'conventions'. I only say
>>> this because enhancing the XmlConfigurationProvider is quite a bit
>>> more daunting than extending the ObjectFactory. If you really can't
>>> adopt an existing plugin for configuration, then create an
>>> implementation of ConfigurationProvider and take a look at the
>>> StrutsXmlConfigurationProvider and see if you can get the dispatcher
>>> to honor your new ConfigurationProvider.
>>>
>>> -Wes
>>>
>>> On Thu, Sep 3, 2009 at 9:33 AM, Andriy Pererva<andronix1983@gmail.com>
wrote:
>>>> Hi, all!
>>>> I'm working on a big java web project, which is based on Struts 2
>>>> framework. Now we are going to do some refactoring and split the
>>>> project up in some parts: core and other auxillary functionality
>>>> modules. Core classes located under classpath, but all the auxillary
>>>> functionality classes will be moved to database and loaded via our
>>>> custom ClassLoader. Among these classes there are some Stuts actions
>>>> and part of the struts.xml file with appropriate mapping.
>>>> How can I make Struts 2 aware of my custom ClassLoader in order to
>>>> load these auxillary action classes from DB. Currently Struts cannot
>>>> find and instantinate any of them
>>>> Any suggestions would be very appreciated!
>>>>
>>>> Thank you in advance for any useful answer.
>>>>
>>>> With best regards,
>>>> Andriy.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Wes Wannemacher
>>>
>>> Head Engineer, WanTii, Inc.
>>> Need Training? Struts, Spring, Maven, Tomcat...
>>> Ask me for a quote!
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message