org.springframework.core.codec.Hints Java Examples

The following examples show how to use org.springframework.core.codec.Hints. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceHttpMessageWriter.java    From java-technology-stack with MIT License 6 votes vote down vote up
private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region,
		ReactiveHttpOutputMessage message, Map<String, Object> hints) {

	if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) {
		try {
			File file = resource.getFile();
			long pos = region != null ? region.getPosition() : 0;
			long count = region != null ? region.getCount() : file.length();
			if (logger.isDebugEnabled()) {
				String formatted = region != null ? "region " + pos + "-" + (count) + " of " : "";
				logger.debug(Hints.getLogPrefix(hints) + "Zero-copy " + formatted + "[" + resource + "]");
			}
			return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
		}
		catch (IOException ex) {
			// should not happen
		}
	}
	return Optional.empty();
}
 
Example #2
Source File: DefaultEntityResponseBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected Mono<Void> writeToInternal(ServerWebExchange exchange, Context context) {
	return inserter().insert(exchange.getResponse(), new BodyInserter.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return context.messageWriters();
		}
		@Override
		public Optional<ServerHttpRequest> serverRequest() {
			return Optional.of(exchange.getRequest());
		}
		@Override
		public Map<String, Object> hints() {
			hints.put(Hints.LOG_PREFIX_HINT, exchange.getLogPrefix());
			return hints;
		}
	});
}
 
Example #3
Source File: MultipartHttpMessageReader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Mono<MultiValueMap<String, Part>> readMono(ResolvableType elementType,
		ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {


	Map<String, Object> allHints = Hints.merge(hints, Hints.SUPPRESS_LOGGING_HINT, true);

	return this.partReader.read(elementType, inputMessage, allHints)
			.collectMultimap(Part::name)
			.doOnNext(map ->
				LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Parsed " +
						(isEnableLoggingRequestDetails() ?
								LogFormatUtils.formatValue(map, !traceOn) :
								"parts " + map.keySet() + " (content masked)"))
			)
			.map(this::toMultiValueMap);
}
 
Example #4
Source File: MultipartHttpMessageWriter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private Mono<Void> writeMultipart(
		MultiValueMap<String, ?> map, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) {

	byte[] boundary = generateMultipartBoundary();

	Map<String, String> params = new HashMap<>(2);
	params.put("boundary", new String(boundary, StandardCharsets.US_ASCII));
	params.put("charset", getCharset().name());

	outputMessage.getHeaders().setContentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params));

	LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Encoding " +
			(isEnableLoggingRequestDetails() ?
					LogFormatUtils.formatValue(map, !traceOn) :
					"parts " + map.keySet() + " (content masked)"));

	DataBufferFactory bufferFactory = outputMessage.bufferFactory();

	Flux<DataBuffer> body = Flux.fromIterable(map.entrySet())
			.concatMap(entry -> encodePartValues(boundary, entry.getKey(), entry.getValue(), bufferFactory))
			.concatWith(generateLastLine(boundary, bufferFactory))
			.doOnDiscard(PooledDataBuffer.class, PooledDataBuffer::release);

	return outputMessage.writeWith(body);
}
 
Example #5
Source File: DefaultServerRequestBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Mono<MultiValueMap<String, Part>> initMultipartData(ServerHttpRequest request,
		List<HttpMessageReader<?>> readers) {

	try {
		MediaType contentType = request.getHeaders().getContentType();
		if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
			return ((HttpMessageReader<MultiValueMap<String, Part>>) readers.stream()
					.filter(reader -> reader.canRead(MULTIPART_DATA_TYPE, MediaType.MULTIPART_FORM_DATA))
					.findFirst()
					.orElseThrow(() -> new IllegalStateException("No multipart HttpMessageReader.")))
					.readMono(MULTIPART_DATA_TYPE, request, Hints.none())
					.switchIfEmpty(EMPTY_MULTIPART_DATA)
					.cache();
		}
	}
	catch (InvalidMediaTypeException ex) {
		// Ignore
	}
	return EMPTY_MULTIPART_DATA;
}
 
Example #6
Source File: DefaultServerWebExchange.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpRequest request,
		ServerCodecConfigurer configurer, String logPrefix) {

	try {
		MediaType contentType = request.getHeaders().getContentType();
		if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
			return ((HttpMessageReader<MultiValueMap<String, String>>) configurer.getReaders().stream()
					.filter(reader -> reader.canRead(FORM_DATA_TYPE, MediaType.APPLICATION_FORM_URLENCODED))
					.findFirst()
					.orElseThrow(() -> new IllegalStateException("No form data HttpMessageReader.")))
					.readMono(FORM_DATA_TYPE, request, Hints.from(Hints.LOG_PREFIX_HINT, logPrefix))
					.switchIfEmpty(EMPTY_FORM_DATA)
					.cache();
		}
	}
	catch (InvalidMediaTypeException ex) {
		// Ignore
	}
	return EMPTY_FORM_DATA;
}
 
Example #7
Source File: DefaultServerWebExchange.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Mono<MultiValueMap<String, Part>> initMultipartData(ServerHttpRequest request,
		ServerCodecConfigurer configurer, String logPrefix) {

	try {
		MediaType contentType = request.getHeaders().getContentType();
		if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
			return ((HttpMessageReader<MultiValueMap<String, Part>>) configurer.getReaders().stream()
					.filter(reader -> reader.canRead(MULTIPART_DATA_TYPE, MediaType.MULTIPART_FORM_DATA))
					.findFirst()
					.orElseThrow(() -> new IllegalStateException("No multipart HttpMessageReader.")))
					.readMono(MULTIPART_DATA_TYPE, request, Hints.from(Hints.LOG_PREFIX_HINT, logPrefix))
					.switchIfEmpty(EMPTY_MULTIPART_DATA)
					.cache();
		}
	}
	catch (InvalidMediaTypeException ex) {
		// Ignore
	}
	return EMPTY_MULTIPART_DATA;
}
 
Example #8
Source File: Jaxb2XmlDecoder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	Flux<XMLEvent> xmlEventFlux = this.xmlEventDecoder.decode(
			inputStream, ResolvableType.forClass(XMLEvent.class), mimeType, hints);

	Class<?> outputClass = elementType.toClass();
	QName typeName = toQName(outputClass);
	Flux<List<XMLEvent>> splitEvents = split(xmlEventFlux, typeName);

	return splitEvents.map(events -> {
		Object value = unmarshal(events, outputClass);
		LogFormatUtils.traceDebug(logger, traceOn -> {
			String formatted = LogFormatUtils.formatValue(value, !traceOn);
			return Hints.getLogPrefix(hints) + "Decoded [" + formatted + "]";
		});
		return value;
	});
}
 
Example #9
Source File: DefaultServerRequestBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpRequest request,
		List<HttpMessageReader<?>> readers) {

	try {
		MediaType contentType = request.getHeaders().getContentType();
		if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
			return ((HttpMessageReader<MultiValueMap<String, String>>) readers.stream()
					.filter(reader -> reader.canRead(FORM_DATA_TYPE, MediaType.APPLICATION_FORM_URLENCODED))
					.findFirst()
					.orElseThrow(() -> new IllegalStateException("No form data HttpMessageReader.")))
					.readMono(FORM_DATA_TYPE, request, Hints.none())
					.switchIfEmpty(EMPTY_FORM_DATA)
					.cache();
		}
	}
	catch (InvalidMediaTypeException ex) {
		// Ignore
	}
	return EMPTY_FORM_DATA;
}
 
Example #10
Source File: DefaultServerResponseBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected Mono<Void> writeToInternal(ServerWebExchange exchange, Context context) {
	return this.inserter.insert(exchange.getResponse(), new BodyInserter.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return context.messageWriters();
		}
		@Override
		public Optional<ServerHttpRequest> serverRequest() {
			return Optional.of(exchange.getRequest());
		}
		@Override
		public Map<String, Object> hints() {
			hints.put(Hints.LOG_PREFIX_HINT, exchange.getLogPrefix());
			return hints;
		}
	});
}
 
Example #11
Source File: DefaultClientResponse.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public <T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor) {
	return extractor.extract(this.response, new BodyExtractor.Context() {
		@Override
		public List<HttpMessageReader<?>> messageReaders() {
			return strategies.messageReaders();
		}
		@Override
		public Optional<ServerHttpResponse> serverResponse() {
			return Optional.empty();
		}
		@Override
		public Map<String, Object> hints() {
			return Hints.from(Hints.LOG_PREFIX_HINT, logPrefix);
		}
	});
}
 
Example #12
Source File: DefaultServerWebExchange.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Mono<MultiValueMap<String, Part>> initMultipartData(ServerHttpRequest request,
		ServerCodecConfigurer configurer, String logPrefix) {

	try {
		MediaType contentType = request.getHeaders().getContentType();
		if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
			return ((HttpMessageReader<MultiValueMap<String, Part>>) configurer.getReaders().stream()
					.filter(reader -> reader.canRead(MULTIPART_DATA_TYPE, MediaType.MULTIPART_FORM_DATA))
					.findFirst()
					.orElseThrow(() -> new IllegalStateException("No multipart HttpMessageReader.")))
					.readMono(MULTIPART_DATA_TYPE, request, Hints.from(Hints.LOG_PREFIX_HINT, logPrefix))
					.switchIfEmpty(EMPTY_MULTIPART_DATA)
					.cache();
		}
	}
	catch (InvalidMediaTypeException ex) {
		// Ignore
	}
	return EMPTY_MULTIPART_DATA;
}
 
Example #13
Source File: MultipartHttpMessageWriter.java    From java-technology-stack with MIT License 6 votes vote down vote up
private Mono<Void> writeMultipart(
		MultiValueMap<String, ?> map, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) {

	byte[] boundary = generateMultipartBoundary();

	Map<String, String> params = new HashMap<>(2);
	params.put("boundary", new String(boundary, StandardCharsets.US_ASCII));
	params.put("charset", getCharset().name());

	outputMessage.getHeaders().setContentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params));

	LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Encoding " +
			(isEnableLoggingRequestDetails() ?
					LogFormatUtils.formatValue(map, !traceOn) :
					"parts " + map.keySet() + " (content masked)"));

	Flux<DataBuffer> body = Flux.fromIterable(map.entrySet())
			.concatMap(entry -> encodePartValues(boundary, entry.getKey(), entry.getValue()))
			.concatWith(Mono.just(generateLastLine(boundary)));

	return outputMessage.writeWith(body);
}
 
Example #14
Source File: Jaxb2XmlDecoder.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	Flux<XMLEvent> xmlEventFlux = this.xmlEventDecoder.decode(
			inputStream, ResolvableType.forClass(XMLEvent.class), mimeType, hints);

	Class<?> outputClass = elementType.toClass();
	QName typeName = toQName(outputClass);
	Flux<List<XMLEvent>> splitEvents = split(xmlEventFlux, typeName);

	return splitEvents.map(events -> {
		Object value = unmarshal(events, outputClass);
		LogFormatUtils.traceDebug(logger, traceOn -> {
			String formatted = LogFormatUtils.formatValue(value, !traceOn);
			return Hints.getLogPrefix(hints) + "Decoded [" + formatted + "]";
		});
		return value;
	});
}
 
Example #15
Source File: ResourceHttpMessageWriter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region,
		ReactiveHttpOutputMessage message, Map<String, Object> hints) {

	if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) {
		try {
			File file = resource.getFile();
			long pos = region != null ? region.getPosition() : 0;
			long count = region != null ? region.getCount() : file.length();
			if (logger.isDebugEnabled()) {
				String formatted = region != null ? "region " + pos + "-" + (count) + " of " : "";
				logger.debug(Hints.getLogPrefix(hints) + "Zero-copy " + formatted + "[" + resource + "]");
			}
			return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
		}
		catch (IOException ex) {
			// should not happen
		}
	}
	return Optional.empty();
}
 
Example #16
Source File: DefaultServerResponseBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected Mono<Void> writeToInternal(ServerWebExchange exchange, Context context) {
	return this.inserter.insert(exchange.getResponse(), new BodyInserter.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return context.messageWriters();
		}
		@Override
		public Optional<ServerHttpRequest> serverRequest() {
			return Optional.of(exchange.getRequest());
		}
		@Override
		public Map<String, Object> hints() {
			hints.put(Hints.LOG_PREFIX_HINT, exchange.getLogPrefix());
			return hints;
		}
	});
}
 
Example #17
Source File: DefaultServerRequestBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpRequest request,
		List<HttpMessageReader<?>> readers) {

	try {
		MediaType contentType = request.getHeaders().getContentType();
		if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
			return ((HttpMessageReader<MultiValueMap<String, String>>) readers.stream()
					.filter(reader -> reader.canRead(FORM_DATA_TYPE, MediaType.APPLICATION_FORM_URLENCODED))
					.findFirst()
					.orElseThrow(() -> new IllegalStateException("No form data HttpMessageReader.")))
					.readMono(FORM_DATA_TYPE, request, Hints.none())
					.switchIfEmpty(EMPTY_FORM_DATA)
					.cache();
		}
	}
	catch (InvalidMediaTypeException ex) {
		// Ignore
	}
	return EMPTY_FORM_DATA;
}
 
Example #18
Source File: DefaultServerRequestBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Mono<MultiValueMap<String, Part>> initMultipartData(ServerHttpRequest request,
		List<HttpMessageReader<?>> readers) {

	try {
		MediaType contentType = request.getHeaders().getContentType();
		if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
			return ((HttpMessageReader<MultiValueMap<String, Part>>) readers.stream()
					.filter(reader -> reader.canRead(MULTIPART_DATA_TYPE, MediaType.MULTIPART_FORM_DATA))
					.findFirst()
					.orElseThrow(() -> new IllegalStateException("No multipart HttpMessageReader.")))
					.readMono(MULTIPART_DATA_TYPE, request, Hints.none())
					.switchIfEmpty(EMPTY_MULTIPART_DATA)
					.cache();
		}
	}
	catch (InvalidMediaTypeException ex) {
		// Ignore
	}
	return EMPTY_MULTIPART_DATA;
}
 
Example #19
Source File: DefaultEntityResponseBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected Mono<Void> writeToInternal(ServerWebExchange exchange, Context context) {
	return inserter().insert(exchange.getResponse(), new BodyInserter.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return context.messageWriters();
		}
		@Override
		public Optional<ServerHttpRequest> serverRequest() {
			return Optional.of(exchange.getRequest());
		}
		@Override
		public Map<String, Object> hints() {
			hints.put(Hints.LOG_PREFIX_HINT, exchange.getLogPrefix());
			return hints;
		}
	});
}
 
Example #20
Source File: MultipartHttpMessageReader.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Mono<MultiValueMap<String, Part>> readMono(ResolvableType elementType,
		ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {


	Map<String, Object> allHints = Hints.merge(hints, Hints.SUPPRESS_LOGGING_HINT, true);

	return this.partReader.read(elementType, inputMessage, allHints)
			.collectMultimap(Part::name)
			.doOnNext(map -> {
				LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Parsed " +
						(isEnableLoggingRequestDetails() ?
								LogFormatUtils.formatValue(map, !traceOn) :
								"parts " + map.keySet() + " (content masked)"));
			})
			.map(this::toMultiValueMap);
}
 
Example #21
Source File: DefaultServerWebExchange.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpRequest request,
		ServerCodecConfigurer configurer, String logPrefix) {

	try {
		MediaType contentType = request.getHeaders().getContentType();
		if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
			return ((HttpMessageReader<MultiValueMap<String, String>>) configurer.getReaders().stream()
					.filter(reader -> reader.canRead(FORM_DATA_TYPE, MediaType.APPLICATION_FORM_URLENCODED))
					.findFirst()
					.orElseThrow(() -> new IllegalStateException("No form data HttpMessageReader.")))
					.readMono(FORM_DATA_TYPE, request, Hints.from(Hints.LOG_PREFIX_HINT, logPrefix))
					.switchIfEmpty(EMPTY_FORM_DATA)
					.cache();
		}
	}
	catch (InvalidMediaTypeException ex) {
		// Ignore
	}
	return EMPTY_FORM_DATA;
}
 
Example #22
Source File: DefaultClientRequestBuilder.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Mono<Void> writeTo(ClientHttpRequest request, ExchangeStrategies strategies) {
	HttpHeaders requestHeaders = request.getHeaders();
	if (!this.headers.isEmpty()) {
		this.headers.entrySet().stream()
				.filter(entry -> !requestHeaders.containsKey(entry.getKey()))
				.forEach(entry -> requestHeaders
						.put(entry.getKey(), entry.getValue()));
	}

	MultiValueMap<String, HttpCookie> requestCookies = request.getCookies();
	if (!this.cookies.isEmpty()) {
		this.cookies.forEach((name, values) -> values.forEach(value -> {
			HttpCookie cookie = new HttpCookie(name, value);
			requestCookies.add(name, cookie);
		}));
	}

	return this.body.insert(request, new BodyInserter.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return strategies.messageWriters();
		}
		@Override
		public Optional<ServerHttpRequest> serverRequest() {
			return Optional.empty();
		}
		@Override
		public Map<String, Object> hints() {
			return Hints.from(Hints.LOG_PREFIX_HINT, logPrefix());
		}
	});
}
 
Example #23
Source File: DefaultClientRequestBuilder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Mono<Void> writeTo(ClientHttpRequest request, ExchangeStrategies strategies) {
	HttpHeaders requestHeaders = request.getHeaders();
	if (!this.headers.isEmpty()) {
		this.headers.entrySet().stream()
				.filter(entry -> !requestHeaders.containsKey(entry.getKey()))
				.forEach(entry -> requestHeaders
						.put(entry.getKey(), entry.getValue()));
	}

	MultiValueMap<String, HttpCookie> requestCookies = request.getCookies();
	if (!this.cookies.isEmpty()) {
		this.cookies.forEach((name, values) -> values.forEach(value -> {
			HttpCookie cookie = new HttpCookie(name, value);
			requestCookies.add(name, cookie);
		}));
	}

	return this.body.insert(request, new BodyInserter.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return strategies.messageWriters();
		}
		@Override
		public Optional<ServerHttpRequest> serverRequest() {
			return Optional.empty();
		}
		@Override
		public Map<String, Object> hints() {
			return Hints.from(Hints.LOG_PREFIX_HINT, logPrefix());
		}
	});
}
 
Example #24
Source File: ByteBufEncoder.java    From alibaba-rsocket-broker with Apache License 2.0 5 votes vote down vote up
public DataBuffer encodeValue(ByteBuf byteBuf, DataBufferFactory bufferFactory, ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
    DataBuffer dataBuffer = ((NettyDataBufferFactory) bufferFactory).wrap(byteBuf);
    if (this.logger.isDebugEnabled() && !Hints.isLoggingSuppressed(hints)) {
        String logPrefix = Hints.getLogPrefix(hints);
        this.logger.debug(logPrefix + "Writing " + dataBuffer.readableByteCount() + " bytes");
    }
    return dataBuffer;
}
 
Example #25
Source File: Jackson2CodecSupport.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected Map<String, Object> getHints(ResolvableType resolvableType) {
	MethodParameter param = getParameter(resolvableType);
	if (param != null) {
		JsonView annotation = getAnnotation(param, JsonView.class);
		if (annotation != null) {
			Class<?>[] classes = annotation.value();
			Assert.isTrue(classes.length == 1, JSON_VIEW_HINT_ERROR + param);
			return Hints.from(JSON_VIEW_HINT, classes[0]);
		}
	}
	return Hints.none();
}
 
Example #26
Source File: ResourceHttpMessageWriter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static MediaType getResourceMediaType(
		@Nullable MediaType mediaType, Resource resource, Map<String, Object> hints) {

	if (mediaType != null && mediaType.isConcrete() && !mediaType.equals(MediaType.APPLICATION_OCTET_STREAM)) {
		return mediaType;
	}
	mediaType = MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM);
	if (logger.isDebugEnabled() && !Hints.isLoggingSuppressed(hints)) {
		logger.debug(Hints.getLogPrefix(hints) + "Resource associated with '" + mediaType + "'");
	}
	return mediaType;
}
 
Example #27
Source File: ServerSentEventHttpMessageWriter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Mono<Void> write(Publisher<?> input, ResolvableType actualType, ResolvableType elementType,
		@Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response,
		Map<String, Object> hints) {

	Map<String, Object> allHints = Hints.merge(hints,
			getEncodeHints(actualType, elementType, mediaType, request, response));

	return write(input, elementType, mediaType, response, allHints);
}
 
Example #28
Source File: SynchronossPartHttpMessageReader.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Flux<Part> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
	return Flux.create(new SynchronossPartGenerator(message, this.bufferFactory, this.streamStorageFactory))
			.doOnNext(part -> {
				if (!Hints.isLoggingSuppressed(hints)) {
					LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Parsed " +
							(isEnableLoggingRequestDetails() ?
									LogFormatUtils.formatValue(part, !traceOn) :
									"parts '" + part.name() + "' (content masked)"));
				}
			});
}
 
Example #29
Source File: DecoderHttpMessageReader.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Mono<T> readMono(ResolvableType actualType, ResolvableType elementType,
		ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) {

	Map<String, Object> allHints = Hints.merge(hints,
			getReadHints(actualType, elementType, request, response));

	return readMono(elementType, request, allHints);
}
 
Example #30
Source File: DecoderHttpMessageReader.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Flux<T> read(ResolvableType actualType, ResolvableType elementType,
		ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) {

	Map<String, Object> allHints = Hints.merge(hints,
			getReadHints(actualType, elementType, request, response));

	return read(elementType, request, allHints);
}