'Oracle ADF - programmatically updating ApplicationModule properties

I want to set the application module configuration property(jbo.ampool.timetolive) value from a managed bean on a button click from the adf page, I have tried with following code but the property value is not getting set.

public Object getInfo(String string, Object environment) {
    Hashtable envHashtable = (Hashtable)environment;      
    envHashtable.put(ApplicationModule.PROPERTY_LABEL.equals("jbo.ampool.timetolive"),"7200000");
    return null;
}

kindly help me out on this



Solution 1:[1]

OK, that's tricky stuff, but here is what I would try:

In your configurations (bc4j.xcfg file), set the jbo.ampool.sessioncookiefactoryclass to point to a class that you will provide (let's call it MySessionCookieFactory)

<BC4JConfig ...>
   <AppModuleConfigBag ...>
      <AppModuleConfig ...>
         <AM-Pooling jbo.ampool.sessioncookiefactoryclass="mypackage.MySessionCookieFactory"/>

That class, MySessionCookieFactory must extend oracle.jbo.common.ampool.SessionCookieFactory and override createSessionCookie to pass back a custom EnvInfoProvider.

public SessionCookie createSessionCookie(String applicationId, String sessionId, ApplicationPool pool,
                                         Properties properties) {
    final SessionCookie cookie = mFactory.createSessionCookie(applicationId, sessionId, pool, properties);
    final EnvInfoProvider provider = new MyEnvInfoProvider();
    cookie.setEnvInfoProvider(provider);
    return cookie;
}

MyEnvInfoProvider must extend oracle.jbo.common.ampool.EnvInfoProvider and override getInfo() to pass back and environment that has the value of jbo.ampool.timetolive that you want.

So, in MyEnvInfoProvider...

@Override
public Object getInfo(String infoType,
                       Object configurationEnvironmentObject) {
    // NOTE: Watch logging in this method.  It gets called for *every request* and it can really clutter up a log.
    // Cast the configuration environment passed in to it's correct type.  It's really lame that Oracle's signatures include Object types
    // instead of the correct classes or interfaces.
    final Hashtable<String, String> configurationEnvironmentHashtable =
                                     (Hashtable<String, String>) configurationEnvironmentObject;

//        if (EnvInfoProvider.INFO_TYPE_SESSION_ENVIRONMENT.equals(infoType)) {
        configurationEnvironmentHashtable.put(PropertyConstants.ENV_AMPOOL_TIME_TO_LIVE, (String) MyClass.getTTL());
//        }
    return configurationEnvironmentHashtable;
}

So, if you do all that, you'll control jbo.ampool.timetolive to be whatever gets returned by MyClass.getTTL(). So, all you need to do is update a variable that MyClass.getTTL() and it will get used as jbo.ampool.timetolive.

I have done this approach environment settings, but not with jbo.ampool.timetolive in particular, so I can't guarantee this will work for you.

Also, why do you need to set this dynamically? Why not just put 720000 in your bc4j.xcfg file and be done with it?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matthew McPeak