Skip to content

Commit 562c09c

Browse files
committed
Fix NPE
Signed-off-by: siri-varma <siri.varma@outlook.com> Signed-off-by: sirivarma <siri.varma@outlook.com>
1 parent e3f4224 commit 562c09c

File tree

3 files changed

+9
-30
lines changed

3 files changed

+9
-30
lines changed

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkerflowClient.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import io.dapr.workflows.client.DaprWorkflowClient;
1717
import io.dapr.workflows.client.WorkflowInstanceStatus;
1818

19-
import java.time.Duration;
2019
import java.util.concurrent.TimeoutException;
2120

2221
public class DemoChildWorkerflowClient {
@@ -28,20 +27,16 @@ public class DemoChildWorkerflowClient {
2827
*/
2928
public static void main(String[] args) {
3029
try (DaprWorkflowClient client = new DaprWorkflowClient()) {
31-
String instanceId = client.scheduleNewWorkflow(DemoChildWorkflow.class, "Hello Word");
30+
String instanceId = client.scheduleNewWorkflow(DemoWorkflow.class);
3231
System.out.printf("Started a new child-workflow model workflow with instance ID: %s%n", instanceId);
32+
WorkflowInstanceStatus workflowInstanceStatus =
33+
client.waitForInstanceCompletion(instanceId, null, true);
3334

34-
while (true) {
35-
try {
36-
Thread.sleep(10000);
37-
System.out.println(client.getInstanceState(instanceId, true).getRuntimeStatus());
38-
} catch (Exception ex) {
39-
System.out.println("exception");
40-
}
41-
}
35+
String result = workflowInstanceStatus.readOutputAs(String.class);
36+
System.out.printf("workflow instance with ID: %s completed with result: %s%n", instanceId, result);
4237

43-
} catch (InterruptedException e) {
38+
} catch (TimeoutException | InterruptedException e) {
4439
throw new RuntimeException(e);
4540
}
4641
}
47-
}
42+
}

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,7 @@ public WorkflowStub create() {
3838
ctx.getLogger().info("ChildWorkflow received input: " + childWorkflowInput);
3939

4040
ctx.getLogger().info("ChildWorkflow is calling Activity: " + ReverseActivity.class.getName());
41-
String result = new String("");
42-
43-
try {
44-
result = ctx.callActivity(ReverseActivity.class.getName(), childWorkflowInput, options, String.class).await();
45-
} catch (OrchestratorBlockedException ex) {
46-
throw ex;
47-
} catch (Exception ex) {
48-
System.out.println("EX:" + ex.getMessage());
49-
ctx.getLogger().warn("Ex is what instance of " + (ex.getMessage()));
50-
}
41+
String result = ctx.callActivity(ReverseActivity.class.getName(), childWorkflowInput, options, String.class).await();
5142

5243
ctx.getLogger().info("ChildWorkflow finished with: " + result);
5344
ctx.complete(result);

examples/src/main/java/io/dapr/examples/workflows/childworkflow/ReverseActivity.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ public Object run(WorkflowActivityContext ctx) {
3030
logger.info("Message Received from input: " + message);
3131
logger.info("Sending message to output: " + newMessage);
3232

33-
throw new RuntimeException("abcdef");
34-
}
35-
}
36-
37-
class MyCustomException extends RuntimeException {
38-
39-
public MyCustomException(String message) {
40-
super(message);
33+
return newMessage;
4134
}
4235
}

0 commit comments

Comments
 (0)