-
Notifications
You must be signed in to change notification settings - Fork 478
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
What is a proper response when an unregistered media type is request? #1073
Comments
I’m not sure what the proper response here is. Is the idea is to throw an exception when asking for a hypermedia type not registered but to fallback to that catchall handler? Maybe HATEOAS needs a handler registered after all others that if it gets hit and the requested type is hypermedia mediatype it throw an exception. But if the requested mediatype is NOT one of ours it lets it go. Not sure if any of this is blocking for 1.0 GA. |
I'm not sure if it is either. My concern is that, depending on what the answer is, breaking changes may be required to implement it. It feels like the sort of thing that should be resolved before the restrictions of reaching 1.0 come into play. |
When I register this private static class NonEncoder implements Encoder<Object> {
private final List<MimeType> hypermediaMediaTypes;
public NonEncoder(List<MimeType> hypermediaMediaTypes) {
this.hypermediaMediaTypes = hypermediaMediaTypes;
}
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
return mimeType == null
|| hypermediaMediaTypes.stream().anyMatch(mediaType -> mediaType.isCompatibleWith(mimeType));
}
@Override
public Flux<DataBuffer> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory,
ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
return Flux.error(new MediaTypeNotSupportedStatusException(mimeType + " support was never registered!"));
}
@Override
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String, Object> hints) {
throw new MediaTypeNotSupportedStatusException(mimeType + " support was never registered!");
}
@Override
public List<MimeType> getEncodableMimeTypes() {
return hypermediaMediaTypes;
}
} |
The javadoc for |
I want it to match if the MimeType is one of our hypermedia mime types. But then blow up on encoding. This is the one after the “real” handlers. Hence, if you register UBER and then request HAL, it is skipped by UBER but picked up by this one, and generates the exception. Probably need a better name to communicate it’s purpose. And need a decoder equivalent. And probably an MVC equivalent. |
If you ask for something else like Actuator’s MimeType, that should bypass this extra encoder too. |
I understand the purpose, but it feels like an abuse of the Have you talked to anyone on the Framework team about this? I know that @bclozel was interested in the use case, for example. |
No i haven’t chatted with them directly. If it’s this risky I doubt the ability to add this to 1.0. |
In general, Spring Framework with the following rules:
I agree that the registered In any case, if a client asks for |
Based on all comments I’m closing this as works as designed. |
If only
HAL
is registered via@EnableHypermediaSupport
, and the client requestsCollection+JSON
via anAccept
header, Spring Framework will fall back to it's handler forapplication/*-json
.Is this proper behavior? If not, what is?
This is a continuation of the discussion from #1064.
The text was updated successfully, but these errors were encountered: