General code cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 the original author or authors.
|
* Copyright 2019-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -548,19 +548,4 @@ public final class FunctionTypeUtils {
|
|||||||
}
|
}
|
||||||
return functionDefinition;
|
return functionDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isFunctional(Type type) {
|
|
||||||
if (type instanceof ParameterizedType) {
|
|
||||||
type = ((ParameterizedType) type).getRawType();
|
|
||||||
Assert.isTrue(type instanceof Class<?>, "Must be one of Supplier, Function, Consumer"
|
|
||||||
+ " or FunctionRegistration. Was " + type);
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> candidateType = (Class<?>) type;
|
|
||||||
return Supplier.class.isAssignableFrom(candidateType)
|
|
||||||
|| Function.class.isAssignableFrom(candidateType)
|
|
||||||
|| Consumer.class.isAssignableFrom(candidateType)
|
|
||||||
|| BiFunction.class.isAssignableFrom(candidateType)
|
|
||||||
|| BiConsumer.class.isAssignableFrom(candidateType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -445,6 +445,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
|||||||
this.propagateInputHeaders = function.propagateInputHeaders;
|
this.propagateInputHeaders = function.propagateInputHeaders;
|
||||||
this.composed = function.composed;
|
this.composed = function.composed;
|
||||||
this.inputType = function.inputType;
|
this.inputType = function.inputType;
|
||||||
|
this.composed = function.composed;
|
||||||
this.outputType = function.outputType;
|
this.outputType = function.outputType;
|
||||||
this.functionDefinition = function.functionDefinition;
|
this.functionDefinition = function.functionDefinition;
|
||||||
this.message = this.inputType != null && FunctionTypeUtils.isMessage(this.inputType);
|
this.message = this.inputType != null && FunctionTypeUtils.isMessage(this.inputType);
|
||||||
@@ -1134,6 +1135,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
|||||||
* This is an optional conversion which would only happen if `expected-content-type` is
|
* This is an optional conversion which would only happen if `expected-content-type` is
|
||||||
* set as a header in a message or explicitly provided as part of the lookup.
|
* set as a header in a message or explicitly provided as part of the lookup.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private Object convertOutputIfNecessary(Object output, Type type, String[] contentType) {
|
private Object convertOutputIfNecessary(Object output, Type type, String[] contentType) {
|
||||||
if (output instanceof Message && ((Message) output).getPayload() instanceof byte[]) {
|
if (output instanceof Message && ((Message) output).getPayload() instanceof byte[]) {
|
||||||
return output;
|
return output;
|
||||||
|
|||||||
@@ -16,12 +16,9 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.function.context.config;
|
package org.springframework.cloud.function.context.config;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -113,30 +110,8 @@ public abstract class FunctionContextUtils {
|
|||||||
|
|
||||||
private static Method[] getCandidateMethods(final Class<?> factoryClass,
|
private static Method[] getCandidateMethods(final Class<?> factoryClass,
|
||||||
final RootBeanDefinition mbd) {
|
final RootBeanDefinition mbd) {
|
||||||
if (System.getSecurityManager() != null) {
|
return (mbd.isNonPublicAccessAllowed()
|
||||||
return AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
|
? ReflectionUtils.getAllDeclaredMethods(factoryClass)
|
||||||
@Override
|
: factoryClass.getMethods());
|
||||||
public Method[] run() {
|
|
||||||
return (mbd.isNonPublicAccessAllowed()
|
|
||||||
? ReflectionUtils.getAllDeclaredMethods(factoryClass)
|
|
||||||
: factoryClass.getMethods());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return (mbd.isNonPublicAccessAllowed()
|
|
||||||
? ReflectionUtils.getAllDeclaredMethods(factoryClass)
|
|
||||||
: factoryClass.getMethods());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object getField(Object target, String name) {
|
|
||||||
Field field = ReflectionUtils.findField(target.getClass(), name);
|
|
||||||
if (field == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ReflectionUtils.makeAccessible(field);
|
|
||||||
return ReflectionUtils.getField(field, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user