mirror of https://github.com/dapr/java-sdk.git
New overload in invokeBinding + allow null typeref. (#1158)
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
This commit is contained in:
parent
7798360cd8
commit
7805ea9121
|
@ -270,6 +270,14 @@ abstract class AbstractDaprClient implements DaprClient, DaprPreviewClient {
|
|||
return this.invokeBinding(bindingName, operation, data, metadata, TypeRef.get(clazz));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Mono<Void> invokeBinding(InvokeBindingRequest request) {
|
||||
return this.invokeBinding(request, TypeRef.VOID);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -314,6 +314,14 @@ public interface DaprClient extends AutoCloseable {
|
|||
<T> Mono<T> invokeBinding(String bindingName, String operation, Object data, Map<String, String> metadata,
|
||||
Class<T> clazz);
|
||||
|
||||
/**
|
||||
* Invokes a Binding operation.
|
||||
*
|
||||
* @param request The binding invocation request.
|
||||
* @return a Mono with void.
|
||||
*/
|
||||
Mono<Void> invokeBinding(InvokeBindingRequest request);
|
||||
|
||||
/**
|
||||
* Invokes a Binding operation.
|
||||
*
|
||||
|
|
|
@ -459,8 +459,10 @@ public class DaprClientImpl extends AbstractDaprClient {
|
|||
|
||||
try {
|
||||
CloudEvent<T> cloudEvent = new CloudEvent<>();
|
||||
var object =
|
||||
DaprClientImpl.this.objectSerializer.deserialize(message.getData().toByteArray(), type);
|
||||
T object = null;
|
||||
if (type != null) {
|
||||
object = DaprClientImpl.this.objectSerializer.deserialize(message.getData().toByteArray(), type);
|
||||
}
|
||||
cloudEvent.setData(object);
|
||||
cloudEvent.setDatacontenttype(message.getDataContentType());
|
||||
cloudEvent.setId(message.getId());
|
||||
|
@ -528,6 +530,10 @@ public class DaprClientImpl extends AbstractDaprClient {
|
|||
|
||||
private <T> Mono<T> getMonoForHttpResponse(TypeRef<T> type, DaprHttp.Response r) {
|
||||
try {
|
||||
if (type == null) {
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
T object = objectSerializer.deserialize(r.getBody(), type);
|
||||
if (object == null) {
|
||||
return Mono.empty();
|
||||
|
@ -585,6 +591,9 @@ public class DaprClientImpl extends AbstractDaprClient {
|
|||
}
|
||||
|
||||
try {
|
||||
if (type == null) {
|
||||
return Mono.empty();
|
||||
}
|
||||
return Mono.justOrEmpty(objectSerializer.deserialize(it.getData().toByteArray(), type));
|
||||
} catch (IOException e) {
|
||||
throw DaprException.propagate(e);
|
||||
|
@ -706,13 +715,18 @@ public class DaprClientImpl extends AbstractDaprClient {
|
|||
return new State<>(key, error);
|
||||
}
|
||||
|
||||
ByteString payload = item.getData();
|
||||
byte[] data = payload == null ? null : payload.toByteArray();
|
||||
T value = stateSerializer.deserialize(data, type);
|
||||
String etag = item.getEtag();
|
||||
if (etag.equals("")) {
|
||||
etag = null;
|
||||
}
|
||||
|
||||
T value = null;
|
||||
if (type != null) {
|
||||
ByteString payload = item.getData();
|
||||
byte[] data = payload == null ? null : payload.toByteArray();
|
||||
value = stateSerializer.deserialize(data, type);
|
||||
}
|
||||
|
||||
return new State<>(key, value, etag, item.getMetadataMap(), null);
|
||||
}
|
||||
|
||||
|
@ -723,7 +737,11 @@ public class DaprClientImpl extends AbstractDaprClient {
|
|||
TypeRef<T> type) throws IOException {
|
||||
ByteString payload = response.getData();
|
||||
byte[] data = payload == null ? null : payload.toByteArray();
|
||||
T value = stateSerializer.deserialize(data, type);
|
||||
T value = null;
|
||||
if (type != null) {
|
||||
value = stateSerializer.deserialize(data, type);
|
||||
}
|
||||
|
||||
String etag = response.getEtag();
|
||||
if (etag.equals("")) {
|
||||
etag = null;
|
||||
|
@ -1108,7 +1126,11 @@ public class DaprClientImpl extends AbstractDaprClient {
|
|||
}
|
||||
ByteString payload = item.getData();
|
||||
byte[] data = payload == null ? null : payload.toByteArray();
|
||||
T value = stateSerializer.deserialize(data, type);
|
||||
T value = null;
|
||||
if (type != null) {
|
||||
value = stateSerializer.deserialize(data, type);
|
||||
}
|
||||
|
||||
String etag = item.getEtag();
|
||||
if (etag.equals("")) {
|
||||
etag = null;
|
||||
|
|
|
@ -25,6 +25,7 @@ import io.dapr.client.domain.DeleteStateRequest;
|
|||
import io.dapr.client.domain.ExecuteStateTransactionRequest;
|
||||
import io.dapr.client.domain.GetBulkStateRequest;
|
||||
import io.dapr.client.domain.GetStateRequest;
|
||||
import io.dapr.client.domain.InvokeBindingRequest;
|
||||
import io.dapr.client.domain.PublishEventRequest;
|
||||
import io.dapr.client.domain.RuleMetadata;
|
||||
import io.dapr.client.domain.State;
|
||||
|
@ -327,7 +328,7 @@ public class DaprClientGrpcTest {
|
|||
@Test
|
||||
public void invokeBindingTest() throws IOException {
|
||||
DaprProtos.InvokeBindingResponse.Builder responseBuilder =
|
||||
DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK"));
|
||||
DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK"));
|
||||
doAnswer((Answer<Void>) invocation -> {
|
||||
StreamObserver<DaprProtos.InvokeBindingResponse> observer = (StreamObserver<DaprProtos.InvokeBindingResponse>) invocation.getArguments()[1];
|
||||
observer.onNext(responseBuilder.build());
|
||||
|
@ -339,6 +340,23 @@ public class DaprClientGrpcTest {
|
|||
result.block();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeBindingVoidReturnTest() throws IOException {
|
||||
DaprProtos.InvokeBindingResponse.Builder responseBuilder =
|
||||
DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK"));
|
||||
doAnswer((Answer<Void>) invocation -> {
|
||||
StreamObserver<DaprProtos.InvokeBindingResponse> observer = (StreamObserver<DaprProtos.InvokeBindingResponse>) invocation.getArguments()[1];
|
||||
observer.onNext(responseBuilder.build());
|
||||
observer.onCompleted();
|
||||
return null;
|
||||
}).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any());
|
||||
|
||||
var request = new InvokeBindingRequest("BindingName", "MyOperation");
|
||||
request.setData("request");
|
||||
Mono<Void> result = client.invokeBinding(request, null);
|
||||
result.block();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeBindingByteArrayTest() {
|
||||
DaprProtos.InvokeBindingResponse.Builder responseBuilder =
|
||||
|
|
Loading…
Reference in New Issue