Hi Experts,
I am trying to create a WebService which can create a UWL task in Portal.
1. I created a Portal service and created a method called createTask in it.
The code for creating a task is as below, I am not able to get a valid UWL session with this code. IN default trace it says Classcast Exception.
Please let me know if you have a sample code to use UWL API in webservice context.
IUser user = null;
Properties p = new Properties();
p.put("domain", "true");
ApplicationWebServiceContext wsContext = (ApplicationWebServiceContext) new InitialContext(p).lookup("/wsContext/" + ApplicationWebServiceContext.APPLICATION_WSCONTEXT);
if (wsContext != null) {
user = UMFactory.getAuthenticator().getLoggedInUser(wsContext.getHttpServletRequest(), null);
}
//JNDI lookup for getting the service because we are not in the PRT container
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sapportals.portal.prt.registry.PortalRegistryFactory");
InitialContext initialContext = new InitialContext(env);
IUWLService uwlService = (IUWLService) initialContext.lookup("/broker/services/" + IUWLService.ALIAS_KEY);
if (uwlService == null) {
throw new Exception("Cannot get UWL Service");
}
UWLContext context = new UWLContext();
if (user == null) {
throw new Exception("No user");
}
context.setUser(user);
context.setLocale(user.getLocale());
IUWLSession session = uwlService.beginSession(context, 200);
context.setSession(session);
context.setAllowBackEndConnections(true);
IUWLItemManager itemManager = uwlService.getItemManager(context);
IPushChannel push = uwlService.getPushChannel();
IProviderConnector procon = uwlService.getRegisterProviderConnector(IProviderConnector.ADHOC_WORKFLOW_CONNECTOR_ID);
Item item = new Item(IProviderConnector.ADHOC_WORKFLOW_CONNECTOR_ID,IProviderConnector.ADHOC_WORKFLOW_SYSTEM,"" + new java.util.Date().getTime(),"USER.CORP_LDAP.nbk94cn");
item.setUser("USER.CORP_LDAP.nbk94cn");
item.setSubject("Test EJB 123");
item.setDescription("Test EJB 123");
item.setItemType(ItemType.UWL_ITEM_TASK_APPROVAL);
item.setCreatedDate(new java.util.Date());
item.setDueDate(new Date());
item.setCreatorId("XXX");
item.setRequiredAction(true);
item.setStatus(StatusEnum.NEW);
// External Type is used to filter the notifications according to application
item.setExternalType("ADHoc Task");
Set users = new HashSet();
users.add("XXX");
push.pushSharedItem(procon, item, users);
uwlService.endSession(context);
Thanks,
Yomesh.