tidied MyFirstFlow classes

This commit is contained in:
mattbradburyr3 2023-01-29 21:14:06 +00:00
parent de9f94e9b2
commit 50c613ad9f
4 changed files with 18 additions and 22 deletions

View File

@ -7,6 +7,10 @@ import net.corda.v5.base.types.MemberX500Name;
// send it from one virtual node to another.
@CordaSerializable
public class Message {
private MemberX500Name sender;
private String message;
public Message(MemberX500Name sender, String message) {
this.sender = sender;
this.message = message;
@ -20,6 +24,5 @@ public class Message {
return message;
}
public MemberX500Name sender;
public String message;
}

View File

@ -58,7 +58,7 @@ public class MyFirstFlow implements RPCStartableFlow {
MyFirstFlowStartArgs flowArgs = requestBody.getRequestBodyAs(jsonMarshallingService, MyFirstFlowStartArgs.class);
// Obtain the MemberX500Name of the counterparty.
MemberX500Name otherMember = flowArgs.otherMember;
MemberX500Name otherMember = flowArgs.getOtherMember();
// Get our identity from the MemberLookup service.
MemberX500Name ourIdentity = memberLookup.myInfo().getName();
@ -67,7 +67,7 @@ public class MyFirstFlow implements RPCStartableFlow {
Message message = new Message(otherMember, "Hello from " + ourIdentity + ".");
// Log the message to be sent.
log.info("MFF: message.message: " + message.message);
log.info("MFF: message.message: " + message.getMessage());
// Start a flow session with the otherMember using the FlowMessaging service.
// The otherMember's virtual node will run the corresponding MyFirstFlowResponder responder flow.
@ -82,16 +82,15 @@ public class MyFirstFlow implements RPCStartableFlow {
// The return value of a RPCStartableFlow must always be a String. This will be passed
// back as the REST RPC response when the status of the flow is queried on Corda, or as the return
// value from the flow when testing using the simulator.
return response.message;
return response.getMessage();
}
}
/*
RequestBody for triggering the flow via http-rpc:
{
"clientRequestId": "r1",
"flowClassName": "com.r3.developers.csdetemplate.workflows.MyFirstFlow",
"flowClassName": "com.r3.developers.csdetemplate.flowexample.workflows.MyFirstFlow",
"requestData": {
"otherMember":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB"
}

View File

@ -44,7 +44,7 @@ public class MyFirstFlowResponder implements ResponderFlow {
Message receivedMessage = session.receive(Message.class);
// Log the message as a proxy for performing some useful operation on it.
log.info("MFF: Message received from " + receivedMessage.sender + ":" + receivedMessage.message);
log.info("MFF: Message received from " + receivedMessage.getSender() + ":" + receivedMessage.getMessage());
// Get our identity from the MemberLookup service.
MemberX500Name ourIdentity = memberLookup.myInfo().getName();
@ -54,19 +54,9 @@ public class MyFirstFlowResponder implements ResponderFlow {
"Hello " + session.getCounterparty().getCommonName() + ", best wishes from " + ourIdentity.getCommonName());
// Log the response to be sent.
log.info("MFF: response.message: " + response.message);
log.info("MFF: response.message: " + response.getMessage());
// Send the response via the send method on the flow session
session.send(response);
}
}
/*
RequestBody for triggering the flow via http-rpc:
{
"clientRequestId": "r1",
"flowClassName": "com.r3.developers.csdetemplate.MyFirstFlow",
"requestData": {
"otherMember":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB"
}
}
*/

View File

@ -4,12 +4,16 @@ import net.corda.v5.base.types.MemberX500Name;
// A class to hold the arguments required to start the flow
public class MyFirstFlowStartArgs {
public MemberX500Name otherMember;
private MemberX500Name otherMember;
// The JSON Marshalling Service, which handles serialisation, needs this constructor.
public MyFirstFlowStartArgs() {}
public MyFirstFlowStartArgs(MemberX500Name otherMember) {
this.otherMember = otherMember;
}
// The JSON Marshalling Service, which handles serialisation, needs this constructor.
public MyFirstFlowStartArgs() {}
public MemberX500Name getOtherMember() {
return otherMember;
}
}