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;
}
SharedObjectWebAppTwo.zip (19.6 KB)
#webMethods#webMethods-BPMS#MWS-CAF-Task-Engine