简体   繁体   中英

Transformer not accepting Message as the input

I've just begun migrating the java DSL we've used for our project from Java 7 to 8, and i'm facing weird issues. I have a success channel for an ExpressionEvaluatingRequestHandlerAdvice which is expecting an AdviceMessage . In the Java 7 version, it was working fine with:

.transform(new GenericTransformer<AdviceMessage, Message<?>>() {
    @Override
    public Message<?> transform(AdviceMessage source) {
        return source.getInputMessage();
    }
})

but when i convert it to Java 8:

.<AdviceMessage, Message<?>>transform(advice -> advice.getInputMessage())

it gives me an exception:

org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$ MessageHandlingExpressionEvaluatingAdviceException: Handler Failed; nested exception is org.springframework.integration.transformer.MessageTransformationException: Failed to transform Message; nested exception is org.springframework.messaging.MessageHandlingException: nested exception is java.lang.ClassCastException: java.lang.Boolean cannot be cast to org.springframework.integration.message.AdviceMessage

Boolean was the result of the success expression i had given so it turns out that the method is expecting the payload and not letting me get hold of the whole message.

When i tried to change other parts of the flow the error consistently started popping up wherever I've tried to put a generic argument expecting a Message<?> instead of the payload of the message.

I can't figure out if i'm doing any of the Java 8 syntax wrong, or the error is due to something else entirely, since the Java 7 version is working perfectly.

I couldn't find any Java DSL examples on the web where there were generic casts to Message instead of the payload, so i don't even know if it's supposed to work.

Thanks for the help.

That the problem of genetics erasure. Since that one becomes just an Object , we don't have choice unless try to extract only payload from the message, because this is most common use-case.

To fix your concern you have to use overload .transform() version with the AdviceMesaage.class as a first argument.

That way we know the expected type and can make the method invocation with the proper argument call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM