Product/components used and version/fix level:
Cumulocity IoT Microservice SDK
Detailed explanation of the problem:
I see that service user context (TenantScope) is the default when using the Microservice SDK. I would like to switch this behaviour to user context (UserScope).
- Can I achieve this using a configuration or do I have to manually create the related bean like suggested here: https://cumulocity.com/guides/microservice-sdk/java/#context-support?
- Is there a way to switch between contexts easily. For example, few calls we want to make in user context and few using tenant context?
- I tried the following and couldn’t get the context to work as expected. Kindly help me with a reference I can follow to get this working.
@UserScope
public InventoryApi inventoryApi (Platform platform) throws SDKException{
return platform.getInventoryApi();
}
public ManagedObjectRepresentation createMO(ManagedObjectRepresentation mor, UserCredentials uc) {
return userContextService.callWithinContext(uc, new Callable<ManagedObjectRepresentation>() {
public ManagedObjectRepresentation call() {
return inventoryApi.create(mor);
}
});
Error messages / full error message screenshot / log file:
Question related to a free trial, or to a production (customer) instance?
Development