GH-1228 Type resolvers cleanup

- moved OriginalContentTypeResolver to avro module
- removed StringConvertingContentTypeResolver as it is no longer referenced anywhere
- deprecated KryoMessageConverter

Resolves #1228
This commit is contained in:
Oleg Zhurakousky
2018-02-17 15:57:10 -05:00
parent 82cb15b709
commit 09f4c8118f
6 changed files with 6 additions and 70 deletions

View File

@@ -38,7 +38,6 @@ import org.apache.avro.specific.SpecificDatumReader;
import org.apache.avro.specific.SpecificDatumWriter;
import org.apache.avro.specific.SpecificRecord;
import org.springframework.cloud.stream.binder.OriginalContentTypeResolver;
import org.springframework.core.io.Resource;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2017-2018 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.cloud.stream.schema.avro;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.springframework.cloud.stream.binder.BinderHeaders;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.ContentTypeResolver;
import org.springframework.util.MimeType;
/**
* @author Vinicius Carvalho
*
* Resolves contentType looking for a originalContentType header first. If not found
* returns the contentType
*
*/
class OriginalContentTypeResolver implements ContentTypeResolver {
private ConcurrentMap<String, MimeType> mimeTypeCache = new ConcurrentHashMap<>();
@Override
public MimeType resolve(MessageHeaders headers) {
Object contentType = headers
.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE) != null
? headers.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)
: headers.get(MessageHeaders.CONTENT_TYPE);
MimeType mimeType = null;
if (contentType instanceof MimeType) {
mimeType = (MimeType) contentType;
}
else if (contentType instanceof String) {
mimeType = mimeTypeCache.get(contentType);
if (mimeType == null) {
String valueAsString = (String) contentType;
mimeType = MimeType.valueOf(valueAsString);
mimeTypeCache.put(valueAsString, mimeType);
}
}
return mimeType;
}
}