mirror of https://github.com/dapr/java-sdk.git
Added Headers passed through metadata (#770)
* Added Headers passed through metadata Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com> * trigger pr check Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com> Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
This commit is contained in:
parent
866b166e11
commit
997c86d526
|
@ -115,7 +115,8 @@ abstract class AbstractDaprClient implements DaprClient, DaprPreviewClient {
|
|||
InvokeMethodRequest req = new InvokeMethodRequest(appId, methodName)
|
||||
.setBody(data)
|
||||
.setHttpExtension(httpExtension)
|
||||
.setContentType(objectSerializer.getContentType());
|
||||
.setContentType(objectSerializer.getContentType())
|
||||
.setMetadata(metadata);
|
||||
|
||||
return this.invokeMethod(req, type);
|
||||
}
|
||||
|
|
|
@ -185,6 +185,8 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
final Object request = invokeMethodRequest.getBody();
|
||||
final HttpExtension httpExtension = invokeMethodRequest.getHttpExtension();
|
||||
final String contentType = invokeMethodRequest.getContentType();
|
||||
final Map<String, String> metadata = invokeMethodRequest.getMetadata();
|
||||
|
||||
if (httpExtension == null) {
|
||||
throw new IllegalArgumentException("HttpExtension cannot be null. Use HttpExtension.NONE instead.");
|
||||
}
|
||||
|
@ -203,12 +205,15 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
List<String> pathSegments = new ArrayList<>(Arrays.asList(DaprHttp.API_VERSION, "invoke", appId, "method"));
|
||||
pathSegments.addAll(Arrays.asList(methodSegments));
|
||||
|
||||
byte[] serializedRequestBody = objectSerializer.serialize(request);
|
||||
final Map<String, String> headers = new HashMap<>();
|
||||
if (contentType != null && !contentType.isEmpty()) {
|
||||
headers.put("content-type", contentType);
|
||||
}
|
||||
headers.putAll(httpExtension.getHeaders());
|
||||
if (metadata != null) {
|
||||
headers.putAll(metadata);
|
||||
}
|
||||
byte[] serializedRequestBody = objectSerializer.serialize(request);
|
||||
Mono<DaprHttp.Response> response = Mono.subscriberContext().flatMap(
|
||||
context -> this.client.invokeApi(httpMethod, pathSegments.toArray(new String[0]),
|
||||
httpExtension.getQueryParams(), serializedRequestBody, headers, context)
|
||||
|
|
|
@ -13,6 +13,9 @@ limitations under the License.
|
|||
|
||||
package io.dapr.client.domain;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A request to invoke a service.
|
||||
*/
|
||||
|
@ -28,6 +31,8 @@ public class InvokeMethodRequest {
|
|||
|
||||
private String contentType;
|
||||
|
||||
private Map<String, String> metadata;
|
||||
|
||||
/**
|
||||
* Constructor for InvokeMethodRequest.
|
||||
*
|
||||
|
@ -73,4 +78,13 @@ public class InvokeMethodRequest {
|
|||
this.contentType = contentType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public InvokeMethodRequest setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue