cancel
Showing results for 
Search instead for 
Did you mean: 

Using UWL service in Webservice context

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Here is the code I use to create a task. I hope it could help you or help other users trying to do the same thing.

IUWLService uwlService = (IUWLService)PortalRuntime.getRuntimeResources().getService(IUWLService.ALIAS_KEY);	 

 UWLContext uwlContext = new UWLContext();

IProviderConnector pc = uwlService.getRegisterProviderConnector(IProviderConnector.ADHOC_WORKFLOW_CONNECTOR_ID);


Item item1 = new Item(
	IProviderConnector.ADHOC_WORKFLOW_CONNECTOR_ID,
	"system",
	"id1",
	uwlContext.getUserId(),
	-1,
	new java.util.Date(),
	"lkjh",
	null,
	"request1",
	"uwl.task",
	"uwl.task",
	PriorityEnum.NORMAL,
	StatusEnum.NEW,
	"Super Test"
	);

item1.setShared();
Set users=new HashSet();
		
IUserContext userContext = ((IPortalComponentRequest)getRequest()).getUser();
users.add(userContext.getUniqueID());
	
IUWLItemManager itemManager = uwlService.getItemManager(uwlContext);
uwlService.getPushChannel().pushSharedItem(pc,item1,users);

Regards,

Renaud

Answers (0)