PDA

View Full Version : Reading request params in scoped-proxy


insane
Apr 25th, 2007, 09:09 AM
Hi,
I'm using scoped-proxy "configuration" object in my application. It is created by ConfigurationFactory and this factory needs access to request parameters. And here's my problem - I don't know how to do it. I was trying this way:
public Configuration fetchConfiguration() {
RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
String id = (String) attrs.getAttribute("id", RequestAttributes.SCOPE_REQUEST);

if (id != null && id.length() > 0) {
Configuration configuration = null;
configuration = configurations.get(id);
if (configuration != null)
return configuration;
}

return null;
}
but it doesn't work. "configurations" is a map with stored configurations and "id" is passed in request from other application.

Can anyone help? I will be very thankful.

Jörg Heinicke
Apr 25th, 2007, 12:10 PM
You wrote in the originating thread (http://forum.springframework.org/showthread.php?t=37797):

Each user in it's request should contain data necessary to download proper xml file with configuration to it's FTP (in this configuration there should be also more data that is not important here). Because different customers may use different web applications, as a key for each configuration file will be used user's application's session id. So when some user sends a request, he attaches his session id and if my application properly downloaded configuration file, this configuration is stored in "configurations" under session key.

I wonder why you store the configuration in an extra map and not directly in the session? Maybe it's because of some instantiation of the configuration object which I have not seen yet. From what I get you might not need the ConfigurationFactory at all.

Jörg

insane
Apr 26th, 2007, 02:26 AM
Well, there is much to explain. Everything is so because many different applications and users will have access to my application and what's most important there will be two steps in authorization proces:
1. Some application (let's say App-A) will be used by some customer (Cus-A). Cus-A requests access to my application. App-A sends to my application (using POST form hidden from Cus-A) data necessary to grant access to XML file with configuration for FTP that Cus-A should have access to. If everything is OK this configuration file is stored in this map under the key that is Cus-A session id (in App-A). My application sends response to App-A that so far, all data was correct. If not, proper errors are send.
2. Now, App-A knows that Cus-A should have access to my application and redirects him to it - in this request is also send Cus-A session id. Now, when Cus-A gets access to my application and he "logs-in" using proper session id (this is still session id from other application), my application starts for him new session with configuration taken from the map. And know, this configuration is stored in my application session (which is indeed Cus-A session).

I hope know everything will be understandable :).

So... How to access request parameters from ConfigurationFactory?

insane
Apr 26th, 2007, 04:07 AM
Ok, I found a solution. It's available in spring 2.0.4 (I don't know what about previous versions - in 2.0.1 it wasn't available - method was protected). It's very easy:
String id = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRe quest().getParameter("id");
Thanks for interest...