Browse Source
Support for flushing in EncoderHttpMessageWriter is now driven from a configurable list of "streaming" media types with the list including "application/stream+json" by default. As a result Jackson2ServerHttpMessageWriter is no longer needed.pull/1363/head
5 changed files with 38 additions and 93 deletions
@ -1,77 +0,0 @@
@@ -1,77 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2016 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.http.codec; |
||||
|
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import org.reactivestreams.Publisher; |
||||
import reactor.core.publisher.Mono; |
||||
|
||||
import org.springframework.core.ResolvableType; |
||||
import org.springframework.core.codec.AbstractEncoder; |
||||
import org.springframework.core.codec.Encoder; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.http.ReactiveHttpOutputMessage; |
||||
import org.springframework.http.server.reactive.ServerHttpRequest; |
||||
import org.springframework.http.server.reactive.ServerHttpResponse; |
||||
|
||||
import static org.springframework.core.codec.AbstractEncoder.FLUSHING_STRATEGY_HINT; |
||||
import static org.springframework.core.codec.AbstractEncoder.FlushingStrategy.AFTER_EACH_ELEMENT; |
||||
|
||||
/** |
||||
* Jackson {@link ServerHttpMessageWriter} that resolves {@code @JsonView} annotated handler |
||||
* method and deals with {@link AbstractEncoder#FLUSHING_STRATEGY_HINT}. |
||||
* |
||||
* @author Sebastien Deleuze |
||||
* @since 5.0 |
||||
* @see com.fasterxml.jackson.annotation.JsonView |
||||
*/ |
||||
public class Jackson2ServerHttpMessageWriter extends EncoderHttpMessageWriter<Object> { |
||||
|
||||
|
||||
public Jackson2ServerHttpMessageWriter(Encoder<Object> encoder) { |
||||
super(encoder); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Mono<Void> write(Publisher<?> inputStream, ResolvableType elementType, MediaType mediaType, |
||||
ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) { |
||||
|
||||
if ((mediaType != null) && mediaType.isCompatibleWith(MediaType.APPLICATION_STREAM_JSON)) { |
||||
Map<String, Object> hintsWithFlush = new HashMap<>(hints); |
||||
hintsWithFlush.put(FLUSHING_STRATEGY_HINT, AFTER_EACH_ELEMENT); |
||||
return super.write(inputStream, elementType, mediaType, outputMessage, hintsWithFlush); |
||||
} |
||||
return super.write(inputStream, elementType, mediaType, outputMessage, hints); |
||||
} |
||||
|
||||
@Override |
||||
public Mono<Void> write(Publisher<?> inputStream, ResolvableType streamType, ResolvableType elementType, |
||||
MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) { |
||||
|
||||
if ((mediaType != null) && mediaType.isCompatibleWith(MediaType.APPLICATION_STREAM_JSON)) { |
||||
Map<String, Object> hintsWithFlush = new HashMap<>(hints); |
||||
hintsWithFlush.put(FLUSHING_STRATEGY_HINT, AFTER_EACH_ELEMENT); |
||||
return super.write(inputStream, streamType, elementType, mediaType, request, response, hintsWithFlush); |
||||
} |
||||
return super.write(inputStream, streamType, elementType, mediaType, request, response, hints); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue