Calling a cumulocity's user defined micro service from another microservice without user Credentials

What product/components do you use and which version/fix level are you on?

Cumulocity

Is your question related to the free trail, or to a production (customer) instance?

Customer license

What are you trying to achieve? Please describe in detail.

I am trying to call a user defined micro service from my new micro service without using Java RestTemplate and without passing or exposing the User Credentials.

Do you get any error messages? Please provide a full error message screenshot and log file.

None.

Have you installed all the latest fixes of the products and systems you are using?

All requests to microservices hosted in Cumulocity including those originating from other microservices must go through Cumulocity core and thus have to be authenticated with valid Cumulocity user credentials. If you use our microservice SDK then all requests towards the platform will be executed with the respective tenant and microservice’s service user by default. This way no user credentials are exposed.

Thanks Philipp for clarifying, Will there be any examples of such microservice sdk’s to call another micro service available in our softwareag github? If so kindly help by sharing any such link.

thanks

I’m not aware of a public example in one of our open source repositories. Here is a very basic example:

@Component
@RequiredArgsConstructor
public class CustomMicroserviceApi {
    private final RestConnector restConnector;

    public ManagedObjectRepresentation post(String applicationContextPath, ManagedObjectRepresentation managedObject) {
        String path = "/service" + applicationContextPath;
        return restConnector.post(path, InventoryMediaType.MANAGED_OBJECT, InventoryMediaType.MANAGED_OBJECT, managedObject, ManagedObjectRepresentation.class);
    }
}

Thank you Philipp.

Hi Philipp,

can you confirm that this works with the restConnector and relative path, so that the “external” hostname is not needed?
In this case restConnector would use the cumulocity:8181 domain, correct?
This was the pitfall in this topic:

Regards Kai

My example works with the latest versions of the SDK. I didn’t catch that the question was for 10.10. In fact this part was recently changed. In older versions you’ll have to inject a bean of type PlatformParameters and get the host from it using the getHost() method. Then building the path should look like this:

        String path = platformParameters.getHost() + "service" + applicationContextPath;

Both approaches will use the platform URL injected into the environment automatically.

1 Like

Hi @Philipp_Emmel,

could it be that the external FQDN is required when calling other microservices?
E.g. calling Cumulocity DataHub does not work when using PlatformParameters: http://cumulocity:8111/service/datahub/sql?version=v1

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.