Filters & Services live update [message #1061687] |
Mon, 03 June 2013 13:43 |
Boy D'Poy Messages: 67 Registered: October 2011 |
Member |
|
|
How is it possible to live update filters and/or services already configured at start time, properties?
Let suppose that one have a RAP config.ini file with these lines:
### Logout landing page
org.eclipse.scout.rt.ui.rap.servletfilter.LogoutFilter#redirectUrl=res/logout.html
### Authentication
org.eclipse.scout.http.servletfilter.security.AnonymousSecurityFilter#active=true
org.eclipse.scout.http.servletfilter.security.BasicSecurityFilter#active=false
org.eclipse.scout.http.servletfilter.security.BasicSecurityFilter#realm=application Development
org.eclipse.scout.http.servletfilter.security.BasicSecurityFilter#users=admin\=manager,allen\=allen,blake\=blake
and the Server file having these ones:
### Service Runtime Configuration
org.eclipse.scout.rt.server.services.common.file.RemoteFileService#rootPath=/home/bdp/
But depending on the use [connected user's preferences, connection time, location ....], we'like to set the and the RemoteFileService#rootPath that could be provided from a ... for example.
Since these properties are hardcoded in the *.ini files and need the servers to be restarded at each change (what's in this case prohibited), how could one achieve this goal?
[I looked around and with no way of solution]
Thank you
Once You Go Scout, You Never Come Out!
|
|
|
Re: Filters & Services live update [message #1062584 is a reply to message #1061687] |
Sun, 09 June 2013 13:36 |
Lukas Huser Messages: 42 Registered: March 2010 |
Member |
|
|
Hi Boy
Scout Services
To dynamically change properties of Scout services you can simply retrieve the service object (by calling SERVICES.getService(MyService.class)) and update the property through the setter method.
Or in other words: a property of a Scout service is just a setter method. Whenever you define a setter method on a service class, you will be able to initialize the value in the config.ini file. Internally Scout will use the classes mentioned by you (ServiceUtility and ConfigIniUtility) to read the config.ini file and then simply invoke the appropriate setter method on the service object.
Nothing prevents you from calling the setter method at a later time to dynamically update the service property.
However, parameters defined in the config.ini file are usually rather static and will not change after an application has been started. But they give you the flexibility to provide different values for different installation types (e.g. test instances versus productive instances of the same application etc.). Or use it for configuraton parameters that you simply don't want to have hardcoded in your java classes. Typical examples for config.ini parameters are api keys, file system paths, service URLs of consumed services, database connection strings etc.
In your specific case of the RemoteFileService, the setter method for the root path is not available on the interface (IRemoteFileService), but only on the implementing class. Even though the setter method is a public method on the implementing class, you should consider it an implementation detail of this specific implementation of the general interface. While it is technically possible to retrieve the implementing class through SERVICES.getService(RemoteFileService.class), and calling the setter method, this is strongly discouraged. You should always access a service through its interface, such that you have the flexibility to exchange the actual implementing class at any time.
So, the root path property of the RemoteFileService is simply not meant to be updated dynamically But I guess this is not a real limitation: A RemoteFile allows you to define an arbitrary path (which is relative to the root path).
For example, if you want to store files for each user in a different (sub-)directory, you could define a new service interface, say IUserStorageService, with methods getFileForUser(String userName, RemoteFile file) and putFileForUser(String userName, RemoteFile file). You could then use the existing IRemoteFileService to implement these methods. You would define the (static) root path for the RemoteFileService in the config.ini file, which is then the common parent folder for all user specific sub-folders. You then could dynamically create the full path for a RemoteFile consisting of the user name and the actual file path in your service implementation. (Don't forget to register your new service in the plugin.xml file in the appropriate bundles!)
Servlet Filters
Similar to Scout services, you can define initialization parameters for servlet filters in the config.ini file. But I think this really is a one-time initialization, you won't be able to dynamically change these initialization parameters at a later time.
If you need more flexibility than a static redirect URL during logout, you probably need to come up with your own implementation of a logout filter. You then need to disable the default LogoutFilter (e.g. by setting it to inactive in the config.ini file) and register your own filter. You can register your filter in the plugin.xml file of the *.ui.rap bundle of your application for extension point org.eclipse.scout.http.servletfilter.filters.
Hope this helps!
Lukas
|
|
|
|
Re: Filters & Services live update [message #1064079 is a reply to message #1062845] |
Mon, 17 June 2013 14:05 |
Boy D'Poy Messages: 67 Registered: October 2011 |
Member |
|
|
Hi Lukas!
The trick seems to not work well for a custom implementation of the LogoutFilter.
In fact as suggested, I created for a simple test a LogoutFilterEx like this: (overriding org.eclipse.scout.rt.ui.rap.servletfilter.LogoutFilter causing LogoutFilterEx to be inactive when I set LogoutFilter#active=true)
package my.simple.test.ui.rap;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.eclipse.scout.commons.StringUtility;
import org.eclipse.scout.http.servletfilter.FilterConfigInjection;
public class LogoutFilterEx implements Filter {
public final static String REDIR_INIT_PARAM = "redirectUrl";
public final static String LOGOUT_PARAM = "doLogout";
private FilterConfigInjection injection;
@Override
public void destroy() {
this.injection = null;
}
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final FilterConfigInjection.FilterConfig config = this.injection.getConfig(request);
if (!config.isActive()) {
chain.doFilter(request, response);
return;
}
final String logoutParam = request.getParameter(LogoutFilterEx.LOGOUT_PARAM);
if (logoutParam == null) {
chain.doFilter(request, response);
return;
}
final HttpServletRequest httpRequest = (HttpServletRequest) request;
final HttpSession session = httpRequest.getSession(false);
if (session == null) {
chain.doFilter(request, response);
return;
}
session.invalidate();
final HttpServletResponse httpResponse = (HttpServletResponse) response;
// THIS IS JUST FOR TEST PURPOSE!!!
String redirPath = "http://www.eclipse.org";
httpResponse.sendRedirect(httpResponse.encodeRedirectURL(redirPath));
}
@Override
public void init(final FilterConfig config) throws ServletException {
this.injection = new FilterConfigInjection(config, this.getClass());
}
protected String getRedirectUrl(final HttpServletRequest httpRequest) {
String servletPath = httpRequest.getServletPath();
if ((servletPath.length() > 0) && ('/' == servletPath.charAt(0))) {
servletPath = servletPath.substring(1);
}
return servletPath;
}
}
and got my config.ini file under the rap plugin as this:
#
org.eclipse.scout.rt.ui.rap.servletfilter.LogoutFilter#active=false
org.eclipse.scout.rt.ui.rap.servletfilter.LogoutFilter#failover=true
#
my.simple.test.ui.rap.LogoutFilterEx#active=true
and finally the plugin.xml file as this:
<extension point="org.eclipse.scout.http.servletfilter.filters">
<filter aliases="/web /mobile /tablet" class="my.simple.test.ui.rap.LogoutFilterEx">
</filter>
</extension>
.
But at runtime, this line :
final String logoutParam = request.getParameter(LogoutFilterEx.LOGOUT_PARAM);
returns null, causing the filter tu return.
What's wrong? otherwise, how should I properly, supplly a different LougoutFilter?
Thank you!
Once You Go Scout, You Never Come Out!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04075 seconds