Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ public class OperationTokenUtil {
/**
* Load a workflow run operation token from an operation token.
*
* @throws FallbackToWorkflowIdException if the operation token is not a workflow run token
* @throws IllegalArgumentException if the operation token is invalid
*/
public static WorkflowRunOperationToken loadWorkflowRunOperationToken(String operationToken)
throws FallbackToWorkflowIdException {
public static WorkflowRunOperationToken loadWorkflowRunOperationToken(String operationToken) {
WorkflowRunOperationToken token;
try {
JavaType reference = mapper.getTypeFactory().constructType(WorkflowRunOperationToken.class);
token = mapper.readValue(decoder.decode(operationToken), reference);
} catch (Exception e) {
throw new FallbackToWorkflowIdException("Failed to parse operation token: " + e.getMessage());
throw new IllegalArgumentException("Failed to parse operation token: " + e.getMessage());
}
if (!token.getType().equals(OperationTokenType.WORKFLOW_RUN)) {
throw new IllegalArgumentException(
Expand All @@ -68,16 +66,7 @@ public static WorkflowRunOperationToken loadWorkflowRunOperationToken(String ope
* @throws IllegalArgumentException if the operation token is invalid
*/
public static String loadWorkflowIdFromOperationToken(String operationToken) {
try {
WorkflowRunOperationToken token = loadWorkflowRunOperationToken(operationToken);
return token.getWorkflowId();
} catch (OperationTokenUtil.FallbackToWorkflowIdException e) {
// Previous versions of the SDK simply used the workflow ID as the operation token
// This fallback is provided for backwards compatibility for those cases.
// This fallback will be removed in a future release.
// See: https://github.com/temporalio/sdk-java/issues/2423
return operationToken;
}
return loadWorkflowRunOperationToken(operationToken).getWorkflowId();
}

/** Generate a workflow run operation token from a workflow ID and namespace. */
Expand All @@ -87,11 +76,5 @@ public static String generateWorkflowRunOperationToken(String workflowId, String
return encoder.encodeToString(json.getBytes());
}

public static class FallbackToWorkflowIdException extends RuntimeException {
public FallbackToWorkflowIdException(String message) {
super(message);
}
}

private OperationTokenUtil() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ public void deserializeWorkflowRunToken() throws IOException {
}

@Test
public void loadOldWorkflowRunToken() {
public void failLoadOldWorkflowRunToken() {
String operationToken = "AAAAA-BBBBB-CCCCC";
Assert.assertEquals(
operationToken, OperationTokenUtil.loadWorkflowIdFromOperationToken(operationToken));
Assert.assertThrows(
IllegalArgumentException.class,
() -> OperationTokenUtil.loadWorkflowIdFromOperationToken(operationToken));
}

@Test
Expand Down
Loading