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]