Example: Java API Context
Draft comment:
This topic was viewed 31 times since its publication
With the correct context, a This topic was viewed 31 times since its publication
UserContext can
be established in the calling thread before calling IBM® Case Manager Java™ API methods or directly calling Content Platform Engine Java API methods.
The general structure necessary to call the Content Platform Engine
Java API includes establishing both a
UserContext and a CaseMgmtContext. The
UserContext is established by using the Content Platform Engine
Java API, and the CaseMgmtContext is
established by using the workflow Java API. For example, in a
stand-alone environment, the overall structure might look
like: P8ConnectionCache connCache = new SimpleP8ConnectionCache();
Connection conn = connCache.getP8Connection(CE_URI);
Subject subject =
UserContext.createSubject(conn, USER_NAME,
PASSWORD, "FileNetP8WSI");
UserContext uc = UserContext.get();
uc.pushSubject(subject);
Locale origLocale = uc.getLocale();
uc.setLocale(1);
CaseMgmtContext origCmctx =
CaseMgmtContext.set(
new CaseMgmtContext(
new SimpleVWSessionCache(), connCache()
)
);
try {
// Code that calls the Case Java API or
// directly calls the CE Java API
...
}
finally {
CaseMgmtContext.set(origCmctx);
uc.setLocale(origLocale);
uc.popSubject();
}If the application is running as an WebSphere® Application
Server (WAS)
application, so that the user is already authenticated by the application server, the code might
look like:
HttpServletRequest request;
P8ConnectionCache connCache =
new HttpP8ConnectionCache(request);
VWSessionCache vwSessCache =
new HttpVWSessionCache(request);
UserContext origUc = UserContext.get();
UserContext uc = new UserContext();
uc.setLocale(request.getLocale());
UserContext.set(uc);
CaseMgmtContext origCmctx =
CaseMgmtContext.set(
new CaseMgmtContext(vwSessCache, connCache)
);
try {
// Code that calls the Case Java API or
// directly calls the CE Java API
...
}
finally {
CaseMgmtContext.set(origCmctx);
UserContext.set(origUc);
}
public class HttpP8ConnectionCache
implements P8ConnectionCache {
// A custom implementation of P8ConnectionCache
// that caches Connection objects
// in the HttpSession of the HttpServletRequest
}
public class HttpVWSessionCache implements VWSessionCache {
// A custom implementation of VWSessionCache
// that caches VWSession objects in the HttpSession
// of the HttpServletRequest
}
This topic is shared by BAW, CP4BA. Last updated on 2025-03-13 12:15