New: Changing the processing mode using the Java SDK

Hi,

I looked at the following for changing the processing mode.

My implementation is as follows:

    private synchronized void initializeTransientApis() {
        if (!transientApisInitialized) {
            try {
                if (transientPlatform instanceof PlatformImpl) {

                    // Register the transient interceptor
                    ((PlatformImpl) transientPlatform).registerInterceptor(new HttpClientInterceptor() {
                        @Override
                        public Invocation.Builder apply(Invocation.Builder builder) {
                            return builder.header("X-Cumulocity-Processing-Mode", "TRANSIENT");
                        }
                    });

                    // Initialize transient APIs
                    measurementApiTransient = transientPlatform.getMeasurementApi();

                    transientApisInitialized = true;
                    log.info("Transient APIs initialized successfully");
                } else {
                    log.warn("Platform is not PlatformImpl, falling back to header-based approach");
                }
            } catch (Exception e) {
                log.warn("Could not initialize transient APIs: ", e);
            }
        }
    }

When I run the code I get the message:

Platform is not PlatformImpl, falling back to header-based approach

How can I register the interceptor?

Regards Christof

1 Like

Can you change the check and the cast from PlatformImpl to PlatformParameters? This is the base class actually implementing registerInterceptor.

The injected platform is a Spring-generated proxy with multiple layers of enhancement.

I can’t cast to neither PlatformImpl nor PlatformParameters.

The described approach seems to only work for standalone client not injected by Spring.

I found a solution: ProcessingModeService.

It uses a RestConnector and then registers an interceptor.

3 Likes