Best way to get Remote IP in Http Inbound Spring Integration

123 Views Asked by At

How can I get remote IP in spring integration (Http Inbound ). I have searched through stack overflow , I could not relate answers to what I want to achieve.

    @Bean
    public IntegrationFlow inquiry(IntegrationFlow outboundGateway){
        return IntegrationFlows.from(Http.inboundGateway("/inquiry")
                .errorChannel("errorChannel")
                .requestPayloadType(String.class)
                .requestMapping(m -> m.methods(HttpMethod.POST)))
                .wireTap(Loggers.REQUEST_LOGGER_CHANNEL)
                .handle((p,h)->{
                    log.info("REMOTE IP: {}",...)
                    return p;
                })
                .transform(Transformers.fromJson(PayloadDTO.class))
                ...;
    }
1

There are 1 best solutions below

0
On BEST ANSWER
log.info("REMOTE IP: {}", 
         ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getRemoteAddr()) 

Also see this: https://mkyong.com/java/how-to-get-client-ip-address-in-java/