Hrmm.

I fear I have sent you on a wild goose chase. After further exploration, I can't see how you can get core app-configuration properties through the RuntimeConfiguration.

It looks like there are really two sets of configuration data in S2, config data for executing the actions (actions, interceptors, results, etc.) and config data for internal Struts state (like the extension mapping suffix).

I can only hope the following serves as an acceptable apology for said goose chase...

What I didn't realize is that struts (xwork, actually) is using annotation-based IOC/DI. As far as I can tell it has en embedded version of Guice. And the IOC/DI container knows about the configuration data and can inject it into your objects. I just tried this in an action and it worked great...

    List extensions = new ArrayList();
        
    @Inject(StrutsConstants.STRUTS_ACTION_EXTENSION)
    public void setExtensions(String extensions) {
        if (!"".equals(extensions)) {
            this.extensions = Arrays.asList(extensions.split(","));
        } else {
            this.extensions = null;
        }
    }

Presumably, you can use the @Inject annotation in other s2 object-types, not just actions (this should work in interceptors, custom results, etc.)

Note my previous warning, the "extensions" value can be a comma separated list, not just a single value, so handle that case.

Also note: I just verified that S2 does *NOT* slave or synchronize its action extension to the filter-mapping url defined in web.xml.

When you grab the "extensions" value using the above technique you're getting the value defined in struts' built-in "default.properties" or your own overrides in "struts.properties". You are not getting the filter's url-mappings defined in web.xml.

For practical purposes it doesn't matter, it would be a configuration error (in most cases) if web.xml's filter mappings differed from Struts internal notion of the extension. But just FYI on that.

Sorry for the goose chase.

- Gary

Gary Affonso wrote:
I knew I had interacted with the runtime configuration before. Just found the code...

RuntimeConfiguration runtimeConfiguration = ConfigurationManager.getConfiguration().getRuntimeConfiguration();

ActionConfig actionConfig = runtimeConfiguration.getActionConfig("", actionInvocation.getInvocationContext().getName());

ResultConfig resultConfig = (ResultConfig) actionConfig.getResults().get(result);

The purpose of the above code (which was run in an interceptor) was to get the result configuration data for the currently executing action (in our case, defined in "xwork.xml").

That's not applicable to what you want, but hopefully the above points you in the right direction.

Oh, and this is code running under WebWork (2.x), might be a bit different under S2.

Good Luck,

- Gary

Gary Affonso wrote:
Pablo Vázquez Blázquez wrote:
Hello,

How can I red my application name and the actions' extension?

For example: http://localhost:8080/scheduler-admintool-1.0/Workspace.do

I'd need a code to get "scheduler-admintool-1.0" and "do" from the context.

The first part ("scheduler-admintool-1.0") should be your context root. As Wes said, getContextPath() should give you that. Or at least something you can parse for what you need.

The second item ("do") is defined in web.xml when you specify the url-pattern of the filter mapping for the S2 filter.

I don't know how to retrieve filter-mapping configuration data (defined in web.xml) from within a servlet (or an Action, Interceptor, etc). As far as I know, it can't be done easily (without doing something like finding and parsing web.xml by hand).

If you're willing to dig a bit, the S2 (and Xwork source code) imply that this information is also available in the S2 configuration data. Here's the configuration key that will lookup the "extensions" that Struts 2 knows about...

  StrutsConstants.STRUTS_ACTION_EXTENSION

Your next questions will be:

"how do I get the central Struts 2 Configuration object?"
"how do I lookup a configuration value from this object using the key?"

I don't have answers for those but maybe somebody else here can help with that.

I vaguely recall that I've looked up config data on-the-fly (from within an Action) in WebWork at some distant point in the past. I think it's possible just can't remember how it got done.

- Gary

P.S.  Two things to be careful of:

1) The "extensions" that get returned from the Configuration object are a comma separated list. Often its just one extension but sometimes it's more than one. So handle that case.

2) I have no clue how Struts 2 gather the "extensions" for its configuration. I would think it would have to ensure they were the same as the url-pattern defined for the filter in web.xml.

But there's some suspicious hardcoding of ".action" in the source code that makes me a little, well, suspicious. So just be sure to double-check that the extension data you manage to get back from Configuration is properly slaved to the web.xml Struts filter's url-pattern.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to