Ensure classpath checks can be evaluated at build-time
Closes gh-29352
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -105,9 +105,19 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
|
||||
*/
|
||||
public static final String X_PROTOBUF_MESSAGE_HEADER = "X-Protobuf-Message";
|
||||
|
||||
private static final boolean protobufFormatFactoryPresent;
|
||||
|
||||
private static final boolean protobufJsonFormatPresent;
|
||||
|
||||
private static final Map<Class<?>, Method> methodCache = new ConcurrentReferenceHashMap<>();
|
||||
|
||||
static {
|
||||
ClassLoader classLoader = ProtobufHttpMessageConverter.class.getClassLoader();
|
||||
protobufFormatFactoryPresent = ClassUtils.isPresent("com.googlecode.protobuf.format.FormatFactory", classLoader);
|
||||
protobufJsonFormatPresent = ClassUtils.isPresent("com.google.protobuf.util.JsonFormat", classLoader);
|
||||
}
|
||||
|
||||
|
||||
final ExtensionRegistry extensionRegistry;
|
||||
|
||||
@Nullable
|
||||
@@ -136,10 +146,10 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
|
||||
if (formatSupport != null) {
|
||||
this.protobufFormatSupport = formatSupport;
|
||||
}
|
||||
else if (ClassUtils.isPresent("com.googlecode.protobuf.format.FormatFactory", getClass().getClassLoader())) {
|
||||
else if (protobufFormatFactoryPresent) {
|
||||
this.protobufFormatSupport = new ProtobufJavaFormatSupport();
|
||||
}
|
||||
else if (ClassUtils.isPresent("com.google.protobuf.util.JsonFormat", getClass().getClassLoader())) {
|
||||
else if (protobufJsonFormatPresent) {
|
||||
this.protobufFormatSupport = new ProtobufJavaUtilSupport(null, null);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user