Skip to content

Commit

Permalink
spring-atticGH-1134: Restore Spring Integration support
Browse files Browse the repository at this point in the history
Fixes spring-attic#1134

* Upgrade sample to the latest Spring Integration `5.5.7-SNAPSHOT`
* Add `maven-shade-plugin` and `native-maven-plugin` under Windows profile
to make native image build working on Windows.
Se more info in Native Build Tools docs:
https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#long_classpath_and_shading_support
This profile simply can go to the `../maven-parent/pom.xml` to make all the samples working on Windows.
Or you can remove this on merge since it might be just a noise for a broader community
* Add custom `ReactorClientHttpConnector` bean into the sample app, since by default a DNS resolver
fails with NPE on Windows in native image.
See more info in the: spring-projects/spring-framework#27749
* Add more type nints into the `IntegrationHints`
  • Loading branch information
artembilan committed Nov 29, 2021
1 parent e259814 commit ee2efc2
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 5 deletions.
49 changes: 49 additions & 0 deletions samples/integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<properties>
<java.version>11</java.version>
<spring-integration.version>5.5.7-SNAPSHOT</spring-integration.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -75,4 +76,52 @@
</plugins>
</build>

<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native.buildtools.version}</version>
<configuration>
<skip>false</skip>
<imageName>${project.artifactId}</imageName>
<mainClass>${exec.mainClass}</mainClass>
<buildArgs>
<buildArg>--no-fallback</buildArg>
</buildArgs>
<classpath>
<param>${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar</param>
</classpath>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.Duration;
import java.util.Calendar;
import java.util.Date;
import java.util.function.Function;

import javax.sql.DataSource;

Expand All @@ -15,6 +16,8 @@
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.client.reactive.ReactorResourceFactory;
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.annotation.ServiceActivator;
Expand All @@ -39,6 +42,10 @@

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.netty.resolver.DefaultAddressResolverGroup;
import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;
import reactor.netty.resources.LoopResources;

@SpringBootApplication
@EnableMessageHistory("dateChannel")
Expand Down Expand Up @@ -81,6 +88,25 @@ public static void main(String[] args) throws InterruptedException {
System.out.println("CURRENT INTEGRATION GRAPH:\n" + integrationGraph);
}

@Bean
ReactorResourceFactory reactorClientResourceFactory() {
return new ReactorResourceFactory();
}

@Bean
ReactorClientHttpConnector reactorClientHttpConnector(ReactorResourceFactory reactorResourceFactory) {
ConnectionProvider provider = reactorResourceFactory.getConnectionProvider();
LoopResources resources = reactorResourceFactory.getLoopResources();
Function<HttpClient, HttpClient> mapper =
httpClient -> httpClient.resolver(DefaultAddressResolverGroup.INSTANCE);
HttpClient httpClient =
mapper.apply(HttpClient.create(provider))
.tcpConfiguration(tcpClient -> tcpClient.runOn(resources));

return new ReactorClientHttpConnector(httpClient);
}


@Bean
MeterRegistry simpleMeterRegistry() {
return new SimpleMeterRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,28 @@
}),
@TypeHint(access = AccessBits.CLASS | AccessBits.PUBLIC_METHODS,
types = {
org.springframework.beans.factory.config.BeanExpressionContext.class,
org.springframework.integration.config.ConsumerEndpointFactoryBean.class,
org.springframework.integration.context.IntegrationContextUtils.class,
org.springframework.integration.xml.xpath.XPathUtils.class,
org.springframework.integration.json.JsonPathUtils.class,
com.jayway.jsonpath.JsonPath.class,
org.springframework.integration.gateway.MethodArgsHolder.class,
org.springframework.integration.routingslip.ExpressionEvaluatingRoutingSlipRouteStrategy.RequestAndReply.class,
org.springframework.integration.core.Pausable.class
org.springframework.integration.core.Pausable.class,
org.springframework.integration.annotation.ServiceActivator.class,
org.springframework.integration.annotation.Splitter.class,
org.springframework.integration.annotation.Transformer.class,
org.springframework.integration.annotation.Router.class,
org.springframework.integration.annotation.Filter.class,
org.springframework.integration.annotation.BridgeFrom.class,
org.springframework.integration.annotation.BridgeTo.class,
org.springframework.integration.annotation.Aggregator.class,
org.springframework.integration.annotation.Gateway.class,
org.springframework.integration.annotation.GatewayHeader.class,
org.springframework.integration.annotation.InboundChannelAdapter.class,
org.springframework.integration.annotation.Poller.class,
org.springframework.integration.annotation.Publisher.class
})
},
serializables = {
Expand Down Expand Up @@ -127,7 +143,6 @@
@TypeHint(
types = {
org.springframework.integration.core.GenericSelector.class,
org.springframework.messaging.support.GenericMessage.class,
org.springframework.integration.transformer.GenericTransformer.class,
org.springframework.integration.handler.GenericHandler.class,
java.util.function.Function.class,
Expand Down Expand Up @@ -187,8 +202,7 @@ public List<HintDeclaration> computeHints(TypeSystem typeSystem) {
hints.addAll(computeMessagingGatewayHints(typeSystem));
hints.addAll(computeAbstractEndpointHints(typeSystem));
hints.addAll(computeIntegrationNodeHints(typeSystem));
// TODO Fails with 'Unable to find class file for org/springframework/web/server/WebFilter' on 'spring-aot-maven-plugin:test-generate'
// hints.addAll(computeMessageHints(typeSystem));
hints.addAll(computeMessageHints(typeSystem));
return hints;
}

Expand Down Expand Up @@ -244,7 +258,7 @@ private static List<HintDeclaration> computeMessageHints(TypeSystem typeSystem)
.skipMethodInspection()
.skipFieldInspection()
.skipConstructorInspection()
.filter(type -> type.implementsInterface(MESSAGE_TYPE))
.filter(type -> type.implementsInterface(MESSAGE_TYPE, true))
.onTypeDiscovered((type, context) ->
context.addReflectiveAccess(type,
new AccessDescriptor(AccessBits.CLASS | AccessBits.PUBLIC_METHODS)))
Expand Down

0 comments on commit ee2efc2

Please sign in to comment.