|
| 1 | +/* |
| 2 | + * Copyright 2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.integration.aot; |
| 18 | + |
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.Date; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.Hashtable; |
| 23 | +import java.util.Properties; |
| 24 | +import java.util.UUID; |
| 25 | +import java.util.function.Function; |
| 26 | +import java.util.function.Supplier; |
| 27 | +import java.util.stream.Stream; |
| 28 | + |
| 29 | +import org.springframework.aop.SpringProxy; |
| 30 | +import org.springframework.aop.framework.Advised; |
| 31 | +import org.springframework.aot.hint.MemberCategory; |
| 32 | +import org.springframework.aot.hint.ProxyHints; |
| 33 | +import org.springframework.aot.hint.ReflectionHints; |
| 34 | +import org.springframework.aot.hint.RuntimeHints; |
| 35 | +import org.springframework.aot.hint.RuntimeHintsRegistrar; |
| 36 | +import org.springframework.aot.hint.SerializationHints; |
| 37 | +import org.springframework.aot.hint.TypeReference; |
| 38 | +import org.springframework.beans.factory.config.BeanExpressionContext; |
| 39 | +import org.springframework.context.SmartLifecycle; |
| 40 | +import org.springframework.core.DecoratingProxy; |
| 41 | +import org.springframework.integration.context.IntegrationContextUtils; |
| 42 | +import org.springframework.integration.core.GenericSelector; |
| 43 | +import org.springframework.integration.core.Pausable; |
| 44 | +import org.springframework.integration.dsl.IntegrationFlow; |
| 45 | +import org.springframework.integration.gateway.MethodArgsHolder; |
| 46 | +import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; |
| 47 | +import org.springframework.integration.handler.DelayHandler; |
| 48 | +import org.springframework.integration.handler.GenericHandler; |
| 49 | +import org.springframework.integration.history.MessageHistory; |
| 50 | +import org.springframework.integration.json.JsonPathUtils; |
| 51 | +import org.springframework.integration.message.AdviceMessage; |
| 52 | +import org.springframework.integration.routingslip.ExpressionEvaluatingRoutingSlipRouteStrategy; |
| 53 | +import org.springframework.integration.store.MessageGroupMetadata; |
| 54 | +import org.springframework.integration.store.MessageHolder; |
| 55 | +import org.springframework.integration.store.MessageMetadata; |
| 56 | +import org.springframework.integration.support.MutableMessage; |
| 57 | +import org.springframework.integration.support.MutableMessageHeaders; |
| 58 | +import org.springframework.integration.support.management.ManageableSmartLifecycle; |
| 59 | +import org.springframework.integration.transformer.GenericTransformer; |
| 60 | +import org.springframework.messaging.MessageHeaders; |
| 61 | +import org.springframework.messaging.support.ErrorMessage; |
| 62 | +import org.springframework.messaging.support.GenericMessage; |
| 63 | + |
| 64 | +/** |
| 65 | + * {@link RuntimeHintsRegistrar} for Spring Integration core module. |
| 66 | + * |
| 67 | + * @author Artem Bilan |
| 68 | + * |
| 69 | + * @since 6.0 |
| 70 | + */ |
| 71 | +class CoreRuntimeHints implements RuntimeHintsRegistrar { |
| 72 | + |
| 73 | + @Override |
| 74 | + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { |
| 75 | + ReflectionHints reflectionHints = hints.reflection(); |
| 76 | + Stream.of( |
| 77 | + GenericSelector.class, |
| 78 | + GenericTransformer.class, |
| 79 | + GenericHandler.class, |
| 80 | + Function.class, |
| 81 | + Supplier.class, |
| 82 | + BeanExpressionContext.class, |
| 83 | + IntegrationContextUtils.class, |
| 84 | + MethodArgsHolder.class, |
| 85 | + AbstractReplyProducingMessageHandler.RequestHandler.class, |
| 86 | + ExpressionEvaluatingRoutingSlipRouteStrategy.RequestAndReply.class, |
| 87 | + Pausable.class, |
| 88 | + ManageableSmartLifecycle.class) |
| 89 | + .forEach(type -> |
| 90 | + reflectionHints.registerType(type, |
| 91 | + builder -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS))); |
| 92 | + |
| 93 | + reflectionHints.registerType(JsonPathUtils.class, |
| 94 | + builder -> |
| 95 | + builder.onReachableType(TypeReference.of("com.jayway.jsonpath.JsonPath")) |
| 96 | + .withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)); |
| 97 | + |
| 98 | + // For #xpath() SpEL function |
| 99 | + reflectionHints.registerTypeIfPresent(classLoader, "org.springframework.integration.xml.xpath.XPathUtils", |
| 100 | + builder -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)); |
| 101 | + |
| 102 | + Stream.of( |
| 103 | + "kotlin.jvm.functions.Function0", |
| 104 | + "kotlin.jvm.functions.Function1", |
| 105 | + "kotlin.Unit") |
| 106 | + .forEach(type -> |
| 107 | + reflectionHints.registerTypeIfPresent(classLoader, type, |
| 108 | + builder -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS))); |
| 109 | + |
| 110 | + hints.resources().registerPattern("META-INF/spring.integration.properties"); |
| 111 | + |
| 112 | + SerializationHints serializationHints = hints.serialization(); |
| 113 | + Stream.of( |
| 114 | + String.class, |
| 115 | + Number.class, |
| 116 | + Long.class, |
| 117 | + Date.class, |
| 118 | + ArrayList.class, |
| 119 | + HashMap.class, |
| 120 | + Properties.class, |
| 121 | + Hashtable.class, |
| 122 | + Exception.class, |
| 123 | + UUID.class, |
| 124 | + GenericMessage.class, |
| 125 | + ErrorMessage.class, |
| 126 | + MessageHeaders.class, |
| 127 | + AdviceMessage.class, |
| 128 | + MutableMessage.class, |
| 129 | + MutableMessageHeaders.class, |
| 130 | + MessageGroupMetadata.class, |
| 131 | + MessageHolder.class, |
| 132 | + MessageMetadata.class, |
| 133 | + MessageHistory.class, |
| 134 | + MessageHistory.Entry.class, |
| 135 | + DelayHandler.DelayedMessageWrapper.class) |
| 136 | + .forEach(serializationHints::registerType); |
| 137 | + |
| 138 | + ProxyHints proxyHints = hints.proxies(); |
| 139 | + |
| 140 | + registerSpringJdkProxy(proxyHints, AbstractReplyProducingMessageHandler.RequestHandler.class); |
| 141 | + registerSpringJdkProxy(proxyHints, IntegrationFlow.class, SmartLifecycle.class); |
| 142 | + } |
| 143 | + |
| 144 | + private static void registerSpringJdkProxy(ProxyHints proxyHints, Class<?>... proxiedInterfaces) { |
| 145 | + proxyHints |
| 146 | + .registerJdkProxy(builder -> |
| 147 | + builder.proxiedInterfaces(proxiedInterfaces) |
| 148 | + .proxiedInterfaces(SpringProxy.class, Advised.class, DecoratingProxy.class)); |
| 149 | + } |
| 150 | + |
| 151 | +} |
0 commit comments