Skip to content
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

Incorrect content-type header for binary alias return type #1099

Closed
dsd987 opened this issue Oct 2, 2020 · 1 comment
Closed

Incorrect content-type header for binary alias return type #1099

dsd987 opened this issue Oct 2, 2020 · 1 comment

Comments

@dsd987
Copy link
Contributor

dsd987 commented Oct 2, 2020

What happened?

When using the Undertow service generator, using a return type that is an alias of binary type results in an incorrect content-type header being added to the response. In this situation we'd expect to receive the content-type of application/octet-stream but instead receive application/json which results in errors in the conjure client like the following:

Unsupported Content-Type: {received=application/json, supportedEncodings=[EncodingDeserializerContainer{encoding=BinaryEncoding{application/octet-stream}, deserializer=InputStreamDeserializer{}}]}
com.palantir.logsafe.exceptions.SafeRuntimeException: Unsupported Content-Type: {received=application/json, supportedEncodings=[EncodingDeserializerContainer{encoding=BinaryEncoding{application/octet-stream}, deserializer=InputStreamDeserializer{}}]}
	at com.palantir.conjure.java.dialogue.serde.ConjureBodySerDe$EncodingDeserializerRegistry$1.deserialize(ConjureBodySerDe.java:298)
	at com.palantir.conjure.java.dialogue.serde.ConjureBodySerDe$EncodingDeserializerRegistry.deserialize(ConjureBodySerDe.java:257)
	at com.palantir.dialogue.futures.DialogueDirectTransformationFuture.onSuccess(DialogueDirectTransformationFuture.java:103)

For other service generators, like Dialogue and Jersey, it looks like binary alias return types are de-aliased during interface generation so that we don't end up using the binary alias type at all for return types and don't run into this issue. However, for the Undertow interfaces, we end up using the binary alias return type and I'm guessing we end up falling back to the default application/json in https://github.com/palantir/conjure-java/blob/develop/conjure-java-undertow-runtime/src/main/java/com/palantir/conjure/java/undertow/runtime/ConjureBodySerDe.java#L119-L137.

What did you want to happen?

In this situation, I'd want/expect the content-type to be appropriately set to application/octet-stream when using an endpoint return type of a binary alias.

Just thinking out loud, there are probably a few different ways to go about this. We would de-alias binary alias return types in the Undertow interfaces to be consistent with the other generators, though that could cause compile breaks in consumers. Additionally, I'm guessing we could add additional logic into the ConjureBodySerDe class to detect and handle this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants