Handle Request Cancellation/ Terminate from Temporal UI

I have a single workflow which looks like this:

public class MyWorkFlowImpl implements MyWorkWorkFlow {
    Customer customer;
    private final ActivityOptions options =

    private final MyActivities activities =
            Workflow.newActivityStub(MyActivities.class, options);
    public void startWorkflow(Customer customer) {
        try {
            this.customer = customer;
        catch (ActivityFailure e) {


    public void cancelOrTerminateWorkflow() { // a signal method
// cancel when Request cancellation signal is sent from UI
// some logic to be performed
    public void setCustomer(Customer customer) { // signal
        this.customer = customer;

When I send a cancellation request from UI ( attached screenshot),

Doesn’t matter under which activity I’m in, I just want it to be redirected to a signal method “cancelWorkflow” or any method/activity if possible and execute the logic inside it.
Similarly something to be done for “terminate” signal from UI

Is there any example to handle these signals sent from UI inside a workflow using java sdk?

Terminate by definition kills workflow without giving it any chance to perform any cleanup.

Do you have any reason not to use the standard cancellation behavior and want to delegate it to a separate handler? It is possible, but I’m not sure if you fully understand the default cancellation logic.