You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "John Lindal (JIRA)" <ji...@apache.org> on 2007/10/10 23:46:38 UTC

[jira] Created: (WW-2244) Make it easier to use custom ActionConfig

Make it easier to use custom ActionConfig
-----------------------------------------

                 Key: WW-2244
                 URL: https://issues.apache.org/struts/browse/WW-2244
             Project: Struts 2
          Issue Type: Improvement
            Reporter: John Lindal
            Priority: Minor


The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!

This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,

protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);

Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42378 ] 

Don Brown commented on WW-2244:
-------------------------------

A couple other ways to do this:
* A custom interceptor, either configured once and used multiple times or configured per action.  If you only have a few common combinations, you could create an interceptor instance for each.  If you have many, maybe you'd want to configure the interceptor per action.  It would only be a couple more characters per action but would work today.
* A custom interceptor that reads a @AccessRestriction annotation on the Action.  In this way, the access information is kept close to the code, where you could use enums and constants to ensure type safety

The general strategy of Struts 2 is avoid XML configuration, so we've opted to not use struts.xml to store a lot of configuration information that existing in Struts 1.

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "John Lindal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42368 ] 

John Lindal commented on WW-2244:
---------------------------------

It would be great if there is already a clean way to accomplish our goal.  What we've done is to extend the struts DTD with additional elements within the action tag.  The only way we could find to store this information, which is associated with the action, not the request, was to extend StrutsAction.  The only way we could find to construct a derived class of StrutsAction was to override DefaultConfiguration and StrutsXmlConfigurationProvider.

Thanks for taking the time to help!

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "John Lindal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42481 ] 

John Lindal commented on WW-2244:
---------------------------------

So how do we resolve this?  Can I submit a patch so we can stop duplicating so much of the struts code in our own classes?  It won't work for us to collapse our configuration down to simple name,value pairs, because we have structured data.

Thanks!

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>             Fix For: 2.1.4
>
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42484 ] 

Don Brown commented on WW-2244:
-------------------------------

Perhaps the best approach would be to have your own package provider, which reads the extra xml and stores it somewhere the interceptor can access it, probably in another singleton bean that could even be managed by the framework's container (using the <bean> element).  To support custom subclasses of ActionConfig, we'd have to refactor all the code to use an ActionConfigFactory, and I'm not convinced it would be worth it, at this stage.  Could you try to above approach and see how it works out?

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>             Fix For: 2.1.4
>
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42369 ] 

Don Brown commented on WW-2244:
-------------------------------

The traditional Struts 2 way is to use the <param> element and have values injected into your Action object.  For example:
<action name="foo" class="Bar">
 <param name="someSetting">someValue</param>
</action>

Then, in your Action, you just define a setSomeSetting() method and Struts will inject it.  Will this do what you want?

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "John Lindal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42495 ] 

John Lindal commented on WW-2244:
---------------------------------

That makes sense.  So my only remaining question is, how do I convince Struts to use my custom StrutsConfigurationProvider?  I could only find struts.configuration in struts-default.properties, but that doesn't seem relevant.  (and I couldn't figure out where in the struts code this property is used, either)

I'll file a separate ticket for adding the name to ActionConfig.

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>             Fix For: 2.1.4
>
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "John Lindal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42493 ] 

John Lindal commented on WW-2244:
---------------------------------

That would work, except that ActionConfig doesn't store the name of the action, as assigned in struts.xml, so there is no natural way to match data structures from a different config file to actions in struts.xml :(

Would you accept a patch that refactors the code?

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>             Fix For: 2.1.4
>
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WW-2244) Make it easier to use custom ActionConfig

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Don Brown resolved WW-2244.
---------------------------

       Resolution: Implemented
    Fix Version/s:     (was: 2.1.4)
         Assignee: Don Brown

Closing as a workaround has been identified and alternate ticket has been created

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Assignee: Don Brown
>            Priority: Minor
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42494 ] 

Don Brown commented on WW-2244:
-------------------------------

What I'm saying is do this:
 * Extend the struts.xml file to include your special XML attributes and/or elements
 * Extend StrutsConfigurationProvider to also read your special information and store them in another singleton bean, keyed by namespace and action name
 * Write that singleton bean as a <bean> element to have Struts manage its lifecycle
 * Write an Interceptor that looks at the current ActionMapping (available in the context), which has the namespace and action name.  Use that data to call your bean and handle the request appropriately.

That would work without Struts changes.  That said, I do agree that ActionConfig should have the action name, so I'd like to see that as well, but maybe that should be a new ticket.

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>             Fix For: 2.1.4
>
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "John Lindal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42372 ] 

John Lindal commented on WW-2244:
---------------------------------

Yes, we could do it that way.  However, we have a very complex set of data that needs to be attached to the action (arbitrary boolean expression combining four different types of access restrictions, e.g., "(A & (B | C) & D) | E", and each restriction has its own set of parameters), so it would be ugly to have to flatten this out in the struts.xml file and then build a separate parser inside the execute() method.  That's why we thought it would be cleaner to extend the DTD, since it's easy to represent our access restrictions in XML.  Thanks!

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "John Lindal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42379 ] 

John Lindal commented on WW-2244:
---------------------------------

Yes, an interceptor would certainly be an alternative.  It would have to be configured per action.  But how would one configure it with a complex boolean expression without using XML?

We can't use annotations, because our security auditors want to look at a single file to see what restrictions are attached to each action.

Thanks!

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42367 ] 

Don Brown commented on WW-2244:
-------------------------------

I'm not so sure that you should need to create your own ActionConfig class.  Struts 2 has many ways to pass configuration information to your Action and it is designed such that you shouldn't need to know that ActionConfig doesn't even exist.  Could you describe why you think this feature is necessary?

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2244) Make it easier to use custom ActionConfig

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42496 ] 

Don Brown commented on WW-2244:
-------------------------------

If you are using Struts 2.0.x, specify your subclass in web.xml:
<init-param>
  <param-name>configProviders</param-name>
  <param-value>com.mycompany.MyConfigurationProvider</param-value>
</init-param>

See also http://struts.apache.org/2.x/docs/webxml.html

If using Struts 2.1.x, simply declare it in your struts.xml as a bean that implements PackageProvider and it will be picked up automatically.

Thanks for adding that ticket.  The lack of action name there has annoyed me as well.  When you are sure this solution we discussed works, please close this ticket.  Thanks.

> Make it easier to use custom ActionConfig
> -----------------------------------------
>
>                 Key: WW-2244
>                 URL: https://issues.apache.org/struts/browse/WW-2244
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: John Lindal
>            Priority: Minor
>             Fix For: 2.1.4
>
>
> The only way that I have found to instantiate a derived class of ActionConfig is to re-implement com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig().  Unfortunately, this is private, so I also have to copy buildRuntimeconfiguration() and the entire RuntimeConfigurationImpl class.  Copying code from the library into our own classes creates undesirable coupling!
> This would unnecessary if buildFullActionConfig() called a protected factory method to construct the ActionConfig object, e.g.,
> protected ActionConfig constructActionConfig(packageContext, baseConfig, params, results, interceptors, exceptionMappings);
> Of course, if I missed something, please let me know :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.