Home > Net >  Spring Integration: Calling transformer before handler denies transactional context
Spring Integration: Calling transformer before handler denies transactional context

Time:01-07

I am still fighting to realize the following flow using Spring Integration 5.5:

  1. read a file from remote SFTP service as InputStream
  2. transform that stream into a custom entity
  3. persist the entity via JPA
  4. delete remote file from SFTP server

So, I have the following flow using Java DSL:

@Configuration
public class Flow {

    @Bean
    public StandardIntegrationFlow createFlow() {
        return IntegrationFlows
            .from(source())
            .publishSubscribeChannel(pubSub -> pubSub
                .subscribe(sub1 -> sub1
                    .transform(Message.class, this::transform)
                    .handle(persist(), e -> e.transactional(false))
                )
                .subscribe(sub2 -> sub2 
                    .handle(remove())
                )
            )
            .get();

    }

    public MessageSource<InputStream> source() {
        return null;
    }

    public Message<MyEntity> transform(Message<InputStream> message) {
        return null;
    }

    public JpaOutboundGateway persist() {
        return null;
    }

    public AbstractMessageHandler remove() {
        return null;
    }

}

My IDE (VSCode) is giving me no warning about this code, however when trying to compile it using Apache Maven 3.8 / JDK 17, I get the following compilation error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project amqp: Compilation failure
[ERROR] /C:/Users/.../src/main/java/com/example/Flow.java:[25,46] cannot find symbol
[ERROR]   symbol:   method transactional(boolean)
[ERROR]   location: variable e of type java.lang.Object

The reason seems to the the transformation (transform()), because as soon as I remove that transformation, the code compiles. Of course it fails during runtime, because persist() method expects a Message, not Message.

Any ideas on what is wrong with my transform-methods signature?

CodePudding user response:

Confirmed. Looks like some bug in Java compiler by itself. When I swap those transform() and handle() it compiles. Or if I remove it or modify some other way...

You can use this as a workaround for now:

.transform(this, "transform")

That compiler error is fully not relevant to your transform() definition.

I might be mistaken judging Java compiler, so will be glad to see some other explanations and hints what is wrong with our code.

  • Related