Changing the processing mode using the Java SDK

Product/components used and version/fix level: Java SDK 10.15

Detailed explanation of the problem: I need to use the “transient” mode to send data to the platform from my Java microservice, however that doesn’t seem to be possible without implementing my own REST client. There is a ProcessingMode enum, but it doesn’t seem to be used anywhere. Can this be done with the SDK or should I use my own REST client as I suspect?

Error messages / full error message screenshot / log file: N/A

Question related to a free trial, or to a production (customer) instance? Prod

Processing mode is set by adding the X-Cumulocity-Processing-Mode header to any request. The intended way of accessing headers in cumulocity java client is through interceptors.

You can register an interceptor on your desired Platform bean using the registerInterceptor() method. You can instantiate a separate Platform bean for this purpose or try to modify the ones provided by the SDK.

see: cumulocity-clients-java/java-client/src/main/java/com/cumulocity/sdk/client/PlatformParameters.java at develop · SoftwareAG/cumulocity-clients-java · GitHub

1 Like

Ok thanks, just understood that I had to explicitely cast the Platform bean to PlatformImpl. Not nice, but that does the job.

@Cyril_Poder Would it be possible to post a code example how you finally achieved changing the processing mode?

Yep, basically you first inject the platform bean in you class, like:

private final Platform platform;

given that you’re using Lombok with @RequiredArgsConstructor annotation.
Then you’d have something like:

            ((PlatformImpl)platform).registerInterceptor((new HttpClientInterceptor() {
               @Override
               public Invocation.Builder apply(Invocation.Builder builder) {
                   return builder.header("X-Cumulocity-Processing-Mode", "TRANSIENT");
               } 
            }));

The imports, in case you’re wondering, for Platform and Invocation.Builder are:

import com.cumulocity.sdk.client.Platform;
import com.cumulocity.sdk.client.PlatformImpl;
import javax.ws.rs.client.Invocation;

Of course this is not how one should implement it, as doing this you definately change the processing mode, so you’d rather either unregister the interceptor after your call or handle the value of the processing mode centrally, but that’s up to what you need to achieve.

2 Likes