Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Filters & Services live update(How is it possible to live update filters and/or services already configured at start time, properties.)
Filters & Services live update [message #1061687] Mon, 03 June 2013 13:43 Go to next message
Boy D'Poy is currently offline Boy D'Poy
Messages: 56
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
LogoutFilter#redirectUrl
and the
RemoteFileService#rootPath
that could be provided from a
IService
... 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
ServiceUtility
and
ConfigIniUtility
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 Go to previous messageGo to next message
Lukas Huser is currently offline 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 Smile 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 #1062845 is a reply to message #1062584] Tue, 11 June 2013 05:29 Go to previous messageGo to next message
Boy D'Poy is currently offline Boy D'Poy
Messages: 56
Registered: October 2011
Member
Ok,
I'll explore the suggested path!
Thank you!


Once You Go Scout, You Never Come Out!
Re: Filters & Services live update [message #1064079 is a reply to message #1062845] Mon, 17 June 2013 14:05 Go to previous messageGo to next message
Boy D'Poy is currently offline Boy D'Poy
Messages: 56
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!
Re: Filters & Services live update [message #1064170 is a reply to message #1064079] Tue, 18 June 2013 04:51 Go to previous messageGo to next message
Jeremie Bresson is currently online Jeremie Bresson
Messages: 772
Registered: October 2011
Senior Member
Hi,

Which Version are you using? Because of your post, Bug 410330 was created and fixed with Kepler 3.9.0 RC4. From what I understood, you should be able to use a custom logout filter with this version.

We also discussed this as general problem. The new guideline will be to do all the service and servlet filter in your application (Bug 410328 will remove service and servlet filter registrations from Scout RT -- This will be implemented with Luna)

Re: Filters & Services live update [message #1064333 is a reply to message #1064170] Tue, 18 June 2013 19:00 Go to previous message
Boy D'Poy is currently offline Boy D'Poy
Messages: 56
Registered: October 2011
Member
Ok!

I updated my SDK and it worked fine!

But could you have a look at this bug that was close to this one : http://www.eclipse.org/forums/index.php/m/1064326/

Thank you!


Once You Go Scout, You Never Come Out!
Previous Topic:Horizontal scroll
Next Topic:SWT application fails to start
Goto Forum:
  


Current Time: Sat Nov 01 10:38:28 GMT 2014

Powered by FUDForum. Page generated in 0.08835 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software