use object of a custom class across multiple CAF Packages

hi All,

Could you please suggest if there is any way to achieve following functinality:

Funtionality: Re use an object of custom defined class across multiple CAF projects.

More description: I have defined a custom class in one of my CAF projects. At runtime, I want to put this object into session and want to utilize this object in
another page bean which is defined in another CAF project.

For example:
I defined an objecet for class Map and put into session from one of my CAF projects at runtime and the same Map obect can be retrieved from session
and the contents of this Map object can be used in a potlet which is defined in another CAF project.

I am looking for a solution to use an object of a custom defined Class in the same way as I use Map object above.

Kind regards,
Raja sekhar Kintali

I’ve attached a sample consisting of three simple projects.

The general concept is:

  • Use a shared library that is in the MWS class path
  • Each Web Application accesses the MWS specific Context object for sharing session data

The first project is a simple Java Project called: SharedObjectProject. This will be the ‘library’ that contains your custom class. In order to use this at design time, you should modify the build properties of other projects to reference this project.

At runtime, in order of the other web applications to use the classes exposed in the library, you’ll need to:

  • build a jar file
  • copy it in the MWS/updates folder
  • run mws.bat|sh update in order to add it to the MWS classpath

The other two projects are identical just to prove that they have access to the same object shared over the user’s MWS session.

The key to each portlet is how it accesses the shared instance of the object:

	public MySampleData getSampleData() throws Exception {
		if (sampleData == null) {
			//get MWS session
			IContext context = ContextFactory.acquireContext(false);
			if (context == null) {
				throw new Exception("Unable to find context");
			//get the object from the session if it exists
			sampleData = (MySampleData)context.getAttribute("sampleData", IContext.SCOPE_SESSION);
			if (sampleData == null) {
				sampleData = new MySampleData();
				//write back to the session
				context.setAttribute("sampleData", sampleData, IContext.SCOPE_SESSION);
        //not totally necessary, just boilerplate code
	    resolveDataBinding(SAMPLEDATA_PROPERTY_BINDINGS, sampleData, "sampleData", false, false);
		return sampleData;
	} (19.6 KB)

hi Mark,

Thank you for your response with sample projects and detailed explanation.

Tried in our envrionment where only 1 MWS node is present. It is working as expected.

  1. Could you please suggest it’s behavior in Cluster environment where more than 2 MWS nodes are present?

(sorry for asking this question - instead of checking at my end in cluster environment, but I couldn’t check this fix in cluster environment because of some other complexities).

  1. Could you also suggest the procedure to remove this jar file from classpath?

Kind regards,
Raja sekhar Kintali

  1. Regarding a cluster environment. This means that you are looking to use a distributed cache. That’s not a current feature of MWS. You’ll have to use your own tools. You might look at many of the quality open source caches like memcache.

  2. To remove a jar from the classpath (that you had in the updates folder), just re-run|bat update.


hi Mark,

If the session is ‘sticky bit session’ in Cluster environment, then user will be sticked to only 1 MWS node all along his session duration.

In this case, even in cluster envrionment, I think we can share an object for a custom class across multiple CAF pacakages, in session during run time.

may I know your comments?

Kind regards,
Raja sekhar Kintali

The data should be available as long as the session is active and only on the VM that the data was created/stored.

Hi Guys,

Is this feature (shared custom library in cluster environment) available in webMethods 9.8 suite?

Kind regards,