on 07-21-2008 1:58 PM
I wrote a Web Service to get the number of new tasks and the total number of tasks for a user like it is displayed in the UWL in the DefaultView.
The numbers are retrieved by the following code:
user = com.sap.security.api.UMFactory.getAuthenticator().getLoggedInUser();
// 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);
uwlService = (IUWLService) initialContext.lookup("/broker/services/" + IUWLService.ALIAS_KEY);
if (uwlService == null) {
throw new Exception("Cannot get UWL Service");
}
context = new UWLContext();
if (user == null) {
throw new Exception("No user");
}
context.setUser(user);
context.setLocale(user.getLocale());
session = uwlService.beginSession(context, 200);
context.setSession(session);
context.setAllowBackEndConnections(true);
itemManager = uwlService.getItemManager(context);
UWLView view = uwlService.getViewManager(context).getView("DefaultView", context);
if (view != null) {
QueryProperties properties = new QueryProperties();
properties.setMaxNumberOfItemsToFetch(0);
QueryResult result = itemManager.getItemsForView(context, view, properties, null);
totals = itemManager.getTotalAndEmphasizedItemCountForView(context, view, "", null);
}
In the first step I chose basic authentication. When debugging I see that the web service gets the information about the logged on user. The UWLService, item manager, session and view, all of them are determined resp. created.
But when calling getItems the UWL exception "Logged in users context or session doesn't exist" is thrown.
When calling the same functionality from Web Dynpro everything works fine.
Service and session are determined like this
uwlService = (IUWLService) WDPortalUtils.getServiceReference(IUWLService.ALIAS_KEY);
context = new UWLContext();
IUser user = WDClientUser.getLoggedInClientUser().getSAPUser();
wdContext.currentUIStateElement().setUserName(user.getFirstName() + " " + user.getLastName());
context.setUser(user);
context.setLocale(WDResourceHandler.getCurrentSessionLocale());
session = uwlService.getUwlSessionForWebDynproClient(context);
Does anyone know how to work with the UWL API in a web service context?
Thanks in advance
Antje
I found the solution by myself. Only calling UMFactory.getAuthenticator().getLoggedInUser without the request context is not enough.
The following code snippet determines first the WebService context from where I can get the request.
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Antje,
I have the same problem so I tried to use your code but I still have the message "(Default) Logged in users context or session doesn't exist" in the logs.
I tried different methods for my Web Service (from a Class, from a Java Bean, with/without Basic Auth...) but I can't get rid of this message.
Regards,
Pierre
Hi,
I am also facing the same error with the code you provided. When debugged, I found User is not returned for
user = UMFactory.getAuthenticator().getLoggedInUser(wsContext.getHttpServletRequest(), null);
line of code.
Could you please update this thread with a detailed solution (sample code).
Thanks
Hi Experts,
We are also facing the same issue as of Yomesh.
The strange part here is that, yesterday, the code was fetching the User and we were able to run the whole web service.
Suddenly, this doesnt seems to be working today. And after debugging, we found that, the User is not being returned with the below code:
user = UMFactory.getAuthenticator().getLoggedInUser(wsContext.getHttpServletRequest(), null);
Any help is highly appreciated.
Thanks in Advance!!
BR,
Uday
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.