spring-projects / spring-integration

Spring Integration provides an extension of the Spring programming model to support the well-known Enterprise Integration Patterns (EIP)
http://projects.spring.io/spring-integration/
Apache License 2.0
1.52k stars 1.09k forks source link

AOT support for ROME Feed Adapter #3979

Closed joshlong closed 1 year ago

joshlong commented 1 year ago

Hi,

I used the RSS/ATOM feed support provided through the ROME inbound adapter and ran into some issues when trying to build a GraalVm native image. I had to manually register some hints that I wanted to share:

  class RomeHints implements RuntimeHintsRegistrar {

        private static List<String> classes(String propertyName, String propertyValue) {
            Assert.hasText(propertyName, "the propertyName must not be null");
            Assert.hasText(propertyValue, "the propertyValue must not be null");
            return Arrays //
                    .stream((propertyValue.contains(" ")) ? propertyValue.split(" ") : new String[] { propertyValue }) //
                    .map(String::trim).filter(xValue -> !xValue.strip().equals("")).toList();
        }

        @Override
        public void registerHints(RuntimeHints hints, ClassLoader classLoader) {

            var mcs = MemberCategory.values();

            // rome
            for (var c : new Class<?>[] { com.rometools.rome.feed.module.DCModuleImpl.class })
                hints.reflection().registerType(c, mcs);

            var resource = new ClassPathResource("/com/rometools/rome/rome.properties");
            hints.resources().registerResource(resource);
            try (var in = resource.getInputStream()) {
                var props = new Properties();
                props.load(in);
                props.propertyNames().asIterator().forEachRemaining(pn -> {
                    var classes = classes((String) pn, props.getProperty((String) pn));
                    classes.forEach(cn -> hints.reflection().registerType(TypeReference.of(cn), mcs));
                });
            }
            catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }

thanks for your consideration and happy holidays!

artembilan commented 1 year ago

You know , Josh, we have similar discussion with you before about Paho hints: https://github.com/spring-projects/spring-integration/issues/3900. the answer here is the same: such a hint has to be exposed by that ROME tools library.

Happy holidays!

artembilan commented 1 year ago

Closed in favor of: https://github.com/rometools/rome/issues/599.

The ROME tools is used not only in Spring Integration, so broader community would benefit from a single place of truth.