Skip to content

Commit 526f36d

Browse files
committed
[FAB-13802] Return types update
Change-Id: Ib4be076c2bc31a363485eb8080c4501a0fb106f2 Signed-off-by: Matthew B. White <[email protected]>
1 parent 8d34b20 commit 526f36d

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/ContextFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static class ContextInvocationHandler implements InvocationHandler {
4545

4646
@Override
4747
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
48-
Method m = stub.getClass().getMethod(method.getName(), method.getParameterTypes());
48+
Method m = ChaincodeStub.class.getMethod(method.getName(), method.getParameterTypes());
4949
return m.invoke(stub, args);
5050
}
5151
}

fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/execution/impl/ContractExecutionService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.HashMap;
3030
import java.util.List;
3131
import java.util.Map;
32+
import static java.nio.charset.StandardCharsets.UTF_8;
3233

3334
public class ContractExecutionService implements ExecutionService {
3435

@@ -54,7 +55,13 @@ public Chaincode.Response executeRequest(Routing rd, InvocationRequest req, Chai
5455

5556
Chaincode.Response response;
5657
try {
57-
response = (Chaincode.Response)rd.getMethod().invoke(proxyObject, args.toArray());
58+
Object value = rd.getMethod().invoke(proxyObject, args.toArray());
59+
if (value==null){
60+
response = ResponseUtils.newSuccessResponse();
61+
} else {
62+
String str = value.toString();
63+
response = ResponseUtils.newSuccessResponse(str.getBytes(UTF_8));
64+
}
5865
} catch (IllegalAccessException|InvocationTargetException e) {
5966
logger.warn("Error during contract method invocation", e);
6067
response = ResponseUtils.newErrorResponse(e);

fabric-chaincode-shim/src/test/java/contract/SampleContract.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ public class SampleContract implements ContractInterface {
3030
static public int i1Invoked = 0;
3131

3232
@Init
33-
public Chaincode.Response i1() {
33+
public String i1() {
3434
i1Invoked++;
35-
return ResponseUtils.newSuccessResponse("Init done");
35+
return "Init done";
3636
}
3737

3838
@Transaction
39-
public Chaincode.Response t1(String arg1) {
39+
public String t1(String arg1) {
4040
t1Invoked++;
4141
Context context = getContext();
4242
List<String> args = context.getStringArgs();
4343
doSomeWork();
44-
return ResponseUtils.newSuccessResponse(args.get(1));
44+
return args.get(1);
4545
}
4646

4747
@Override

fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/contract/ContractRouterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import static org.hamcrest.Matchers.*;
2424
import static org.junit.Assert.*;
2525

26-
26+
import static java.nio.charset.StandardCharsets.UTF_8;
2727
public class ContractRouterTest {
2828
@Rule
2929
public ExpectedException thrown = ExpectedException.none();
@@ -81,7 +81,7 @@ public void testInit() {
8181
SampleContract.i1Invoked = 0;
8282
Chaincode.Response response = r.init(s);
8383
assertThat(response, is(notNullValue()));
84-
assertThat(response.getMessage(), is(equalTo("Init done")));
84+
assertThat(response.getStringPayload(), is(equalTo("Init done")));
8585
assertThat(SampleContract.beforeInvoked, is(1));
8686
assertThat(SampleContract.afterInvoked, is(1));
8787
assertThat(SampleContract.i1Invoked, is(1));
@@ -118,7 +118,7 @@ public void testInvoke() {
118118

119119
Chaincode.Response response = r.invoke(s);
120120
assertThat(response, is(notNullValue()));
121-
assertThat(response.getMessage(), is(equalTo("asdf")));
121+
assertThat(response.getStringPayload(), is(equalTo("asdf")));
122122
assertThat(SampleContract.beforeInvoked, is(1));
123123
assertThat(SampleContract.afterInvoked, is(1));
124124
assertThat(SampleContract.doWorkInvoked, is(1));

0 commit comments

Comments
 (0)