Repository navigation
Provide runtime hints for the reflection of Spring WS - #1946
Closed
sharanggupta wants to merge 2 commits into
Closed
sharanggupta wants to merge 2 commits into
sharanggupta wants to merge 2 commits into
Conversation
Spring WS uses reflection in a few places that a GraalVM native image cannot see, so users had to find and register hints themselves. This commit registers, through META-INF/spring/aot.factories: * the properties files of the default strategies of WebServiceTemplate, MessageDispatcher, SoapMessageDispatcher and MessageDispatcherServlet, and the constructors of the strategies they list, which DefaultStrategiesHelper instantiates * the constructors of the SOAP method argument resolvers, and the types of the optional XML libraries, that DefaultMethodEndpointAdapter loads by class name * the constructor of the normalize-space XPath function of the JDK, which the WS-Addressing support evaluates It also meta-annotates @PayloadRoot, @SoapAction and @action with @Reflective, so that the endpoint methods they map can be found and invoked, like @RequestMapping does for Spring MVC handler methods. See spring-projectsgh-1329 Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
Loading MessageDispatcherServlet requires the Servlet API, which is an optional dependency of spring-ws-core, so referencing it with a class literal made the registrar fail during AOT processing for applications without the Servlet API, such as client-only ones. Reference all the hinted types by name, and register the types of the optional XML libraries only when they are present. See spring-projectsgh-1329 Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
Author
|
I pushed a follow-up commit: the registrar now references all the hinted types by name. With the |
Member
|
See #1329 (comment) - We don't have the bandwidth to review and support this going forward. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a first step for #1329: it provides the runtime hints for the reflection that Spring WS performs itself, as suggested in #1329 (comment), so that an application does not have to collect them with the tracing agent.
What it registers
A
WebServicesRuntimeHintsregistrar inMETA-INF/spring/aot.factoriesregisters:WebServiceTemplate, theMessageDispatcher, theSoapMessageDispatcherand theMessageDispatcherServlet, and the constructors of the strategies they list, which theDefaultStrategiesHelperinstantiates. The registrar reads the same properties files, so the hints follow any change to the defaults.SoapMethodArgumentResolverandSoapHeaderElementMethodArgumentResolver, which theDefaultMethodEndpointAdapterinstantiates by class name.DefaultMethodEndpointAdapterdetects by class name, so that the detection works in a native image when the library is present.normalize-spaceXPath function of the JDK, which the JDK instantiates reflectively when the WS-Addressing support evaluates its expressions.This covers what the configurations in the issue had to register by hand, except the internals of third-party libraries (the SAAJ resource bundle and the JAXB runtime classes), which belong to those libraries.
Endpoint methods
@PayloadRoot,@SoapActionand@Actionare now meta-annotated with@Reflective, in the same way that@RequestMappingis for Spring MVC. During AOT processing, the methods of@Endpointbeans that they map are registered for invocation, so the endpoint mappings can find them and theMethodEndpointcan invoke them in a native image. The repeated forms work as well, asMergedAnnotationssees the annotations inside@PayloadRootsand@SoapActions.The payload types of the endpoints, such as JAXB classes, still need their own hints, for instance with
@RegisterReflectionForBinding. AReflectiveProcessorthat registers them from the@RequestPayloadand@ResponsePayloadsignatures could follow, likeControllerMappingReflectiveProcessordoes for@RequestBody, if you think that it belongs in Spring WS.Testing
Developed test first: the tests failed against
main(no hints are registered), and pass with the change.WebServicesRuntimeHintsTestsloads the registrars fromaot.factories, like the AOT engine does, and checks the hints withRuntimeHintsPredicates. For each default strategies file, it checks the resource and every strategy that the file lists.EndpointMappingAnnotationsRuntimeHintsTestsruns theReflectiveRuntimeHintsRegistraron a sample endpoint, and checks that the mapped methods, including repeated annotations, are registered for invocation and that an unmapped method is not../gradlew :spring-ws-core:check :spring-ws-core:javadocpasses locally on JDK 25 (1047 tests inspring-ws-core, none skipped).I did not build a native image to verify this end to end: that needs more memory than my machine has to spare. The hints match the configurations reported in the issue, which were verified in native images.