How can you handle a Cancellation request in Java?

If I do the following call:

   workflowClient
      .newUntypedWorkflowStub(workflowId)
      .cancel()

Is there a way to handle the cancellation for that type of workflow? (some kind of onCancel() or handleCancellation() ) or what is the suggested approach if I need to do some cleanup steps after cancelation?

The blocking operations like activity invocations or sleep will throw a CanceledException which the workflow can handle to perform any cleanup. See CancellationScope documentation for more detailed explanation of how cancellation is handled in Temporal Java SDK.