-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content-Type mismatch in publishEvent call #779
Comments
This should be fixed. Probably without "unescaping" the String but by correctly handling the datacontenttype attribute. |
One of the issues is that Java sdk has overloaded publishEvent methods that do not require content type as a parameter. IMO this should be deprecated in favor or requiring content type as a parameter in the overloaded functions also. |
If the user passes a String, we should skip serialization and pass it as-is and use text as content-type. |
@artursouza Based on the offline discussion that we had:
All the contentType changes will only be done if the contentType is not given. @artursouza Though there is an issue with respect to XML data. Any thoughts on how that can be resolved? |
This is the code snippet from AbstractDaprClient.java. /**
* {@inheritDoc}
*/
@Override
public Mono<Void> publishEvent(String pubsubName, String topicName, Object data) {
return this.publishEvent(pubsubName, topicName, data, null);
}
/**
* {@inheritDoc}
*/
@Override
public Mono<Void> publishEvent(String pubsubName, String topicName, Object data, Map<String, String> metadata) {
PublishEventRequest req = new PublishEventRequest(pubsubName, topicName, data)
.setMetadata(metadata);
return this.publishEvent(req).then();
} It shows that no matter which function is called, it ends up using the same function. In DaprClientHttp.java it implements public Mono<Void> publishEvent(PublishEventRequest request) {
...
Object data = request.getData();
Map<String, String> metadata = request.getMetadata();
byte[] serializedEvent = objectSerializer.serialize(data);
// Content-type can be overwritten on a per-request basis.
// It allows CloudEvents to be handled differently, for example.
String contentType = request.getContentType();
if (contentType == null || contentType.isEmpty()) {
contentType = objectSerializer.getContentType();
}
Map<String, String> headers = Collections.singletonMap("content-type", contentType);
...
} So the trigger for this bug is whether users set the contenttype manually and correctly. Maybe we clould add a judgment before serialize in @artursouza @mukundansundar What are your opnions? I can help to fix this. |
I have raised related issue #6448 in dapr/dapr. Maybe we need more discussion about whether dapr runtime should be responsible for this bug. |
Expected Behavior
Content-Type mismatch in publishEvent call.
When a string event is published, using the
What is seen in the broker for publish using gRPC protocol is:
Here because the data is not given in the
client.publishEvent
call, it is being inferred by the default serializer asapplication/json
and that is thedatacontenttype
field that is set in the cloudEvent in broker.On subscription, the subscriber correctly reads the value and users see something like
But when we publish the same data
This is message #0
with the publishEvent call with the content type correctly setThe data seen in the broker is such:
and the subscriber actually gets
Subscriber got: "This is message #0"
With the right content type given, the serialization is escaping the quotes. But when no content type is given, a wrong content type is assumed.
Actual Behavior
Proper match should be there between datacontenttype field and the actually data field when saved as cloudEvent.
Steps to Reproduce the Problem
send with the overloaded method of
publishEvent(pubsub, topic, data)
andpublishEvent(publishEventReq)
and set proper metadata for the full request.Release Note
RELEASE NOTE:
The text was updated successfully, but these errors were encountered: