Issue Details (XML | Word | Printable)

Key: XW-122
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Mike Cannon-Brookes
Reporter: Ross Mason
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
XWork

Support for resolving component References in external IoC containers such as Spring

Created: 17/Nov/03 06:45 PM   Updated: 11/Feb/06 09:51 AM
Return to search
Component/s: Configuration, Interceptors
Affects Version/s: 1.0-beta2
Fix Version/s: 1.0

File Attachments: 1. Zip Archive SpringExternalResolver.zip (9 kB)
2. Text File SpringSupport.patch (18 kB)
3. Zip Archive SpringSupport.zip (26 kB)

Issue Links:
Related
 


 Description  « Hide
As per the discussion late last week, we have a patch for Xwork so that it can use an external container to resolve component references.
I've added a breakdown of the changes below, in summary, this is how it works-

You can configure a action to have external references in the xwork.xml using a new <external-ref> tag on the action

When the action is configured the external refs are stored on the action config.

When the action is invoked, there is a new interceptor that will resolve these references. It does this by using a new attribute on the package config called externalReferenceResolver i.e.

<package name="default" externalReferenceResolver="com.atlassian.xwork.ext.SpringServletContextReferenceResolver">

In this case, the SpringServletContextReferenceResolver implementation will handle the work of looking up and setting the references on the action.
Note, if a resolver is not found on the actions package, it will tranverse up the package heirarchy to find one.

We have an implementation for Spring, but I have not included it in this patch as it should probably go into an xwork-ext sub-project. Let me know what you want me to do with this...

Here are the changes and additions to the xwork codebase -

1. added 2 new config attributes -
 - a new element external-ref to the action element in the config.
 i.e <external-ref name="foo">Foo</external-ref>
 where name is the setter method name and Foo is the reference to lookup.
 - added an attribute to the package element called externalReferenceResolver which supplies a FQ classname to an ExternalReferenceResolver implementation.

2. Updated the xwork DTD accordingly.

3. Added 4 new classes -
 - External Reference - an encapsulation of the external-ref tag
 - ExternalReferenceResolver - an interface to provide implementations for resolving references from an external container
 - ExternalReferencesInterceptor - will resolve references on a given ActionInvocation
 - ReferenceResolverException - thrown by ExternalReferenceResolver

4. Added support for external references to the ActionConfig. I also added the attribute packageName to the ActionConfig, so that the Interceptor could determine which package the action belonged to in order to find the externalReferenceResolver.

5. Added support for the externalReferenceResolver attribute to the PackageConfig.

6. Added support for the extra configuration to the XMLConfigurationProvider and DefaultConfigurationProvider

7. Added tests in the org.opensymphony.xwork.config.ExternalReferenceResolverTest


I've attached a cvs patch with all the changes.

Cheers,

Ross

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Ross Mason added a comment - 17/Nov/03 06:47 PM
The CVS patch of these changes created against CVS HEAD source as of 18/11/2003

Ross Mason added a comment - 17/Nov/03 10:58 PM
Source for the changes. The I couldn't get the patch to work for these changes so had to resort to a zip...

Ross Mason added a comment - 18/Nov/03 01:30 AM
A sample Spring ExternalReferenceResolver and tests.

Ross Mason added a comment - 23/Nov/03 04:57 PM
Addes missing ServletContextAware interface and a 'sample' ResolverSetupServletContextListener

Mike Cannon-Brookes added a comment - 13/Jan/04 06:31 PM
Fixed and in CVS - woo!

Stefan Hoehn added a comment - 11/Feb/06 09:51 AM
Can this external resolving also be used to resolve interceptor classes like

   <package name="default" extends="webwork-default" externalReferenceResolver="com.opensymphony.xwork.spring.SpringExternalReferenceResolver">
            <interceptors>
               <!-- Interceptor to handle allowing only admins to certain actions -->
               <interceptor name="adminOnly" class="adminInterceptor"/>
            
               <!-- Interceptor to catch exceptions and display mapped exception result -->
               <interceptor name="exceptionHandler" class="exceptionInterceptor"/>

               ...

?
The class itself is defined in an application-context.xml (actually in action-servlet.xml), a spring-beans-xml that is - like

    <bean id="adminInterceptor" class="com.myapp.UserRoleAuthorizationInterceptor">
        <property name="authorizedRoles" value="admin"/>
    </bean>

This is a sample from the appfuse project, which I am currently trying to migrate to webwork 2.2.1, which requires the Spring-Context-Resolver as webwork's one has become deprecated. The reason I am asking that I tried it and ObjectFactory throws a CNFE.

cheers
Stefan