Accessing current process instance ID

Hi,

We call several rest services from our process instances and have the requirement to send the id of the current executed process instance in a http header field. Therefore I would like to use a common jax-rs ClientRequestFilter like this:

public class CommonHeadersInjector implements ClientRequestFilter {

@Override
public void filter(ClientRequestContext requestContext) throws IOException {
    requestContext.getHeaders().putSingle("processInstance, <PROCESS_INSTANCE_ID>);
}

}

Is there any possibility to access the current executed process instance (e.g. via an ThreadLocal or any other static reference)?

I know, that for example the current authentication can be read from the session or via Authentications.getCurrent().

Is there anything for the processinstance?

Thanks
Wolfgang

@wherr From process instance if you’re making rest service calls means it would be from either Delegates/Listeners.

So it could be pretty much straightforward way to retrieve the process instance id from the delegate task or delegate execution.

execution.getProcessInstanceId()

or from DelegateTask would be like:

delegateTask.getProcessInstanceId()

@aravindhrs
Hi,

No I am not necessarily in a delegate task or execution, but for sure, there is a process instance running. As I’ve posted above, I would like to do it with a http filter (in this case a ClientRequestFilter) or any other generic solution, independent from a JavaDelegate.

Thanks so far.
Wolfgang

@wherr one way you could access that from a thread that has the context is this static chain that uses the ThreadLocal Context:

Context.getBpmnExecutionContext().getProcessInstance().getProcessInstanceId();

Note that the Context can be empty (null), so you might have to be defensive for that. Does that help?

2 Likes

Exactly what I am was looking for!

Thank You

1 Like