1

after the user is hitting an URL which triggers my Spring cloud function (will be deployed later on as Amazon Lambda), and some logic is being done... I want to redirect the user to some URL.

Here is what I have so far:

@RestController
public class ScanQrCode implements Function<String, ResponseEntity<Void>>{

    @Autowired
    private QrCodeRepository qrCodeRepository;

    @Override
    public ResponseEntity<Void> apply(String s) {
        
        Optional<QrCode> qrCodeFromDb = qrCodeRepository.findByText("burger_box");
        if(qrCodeFromDb.isPresent()) {
            QrCode qrCode = qrCodeFromDb.get();
            long scanCount = Long.valueOf(qrCode.getScanCount());
            qrCode.setScanCount(++scanCount);
            qrCodeRepository.save(qrCode);
        }
        
        return ResponseEntity.status(HttpStatus.FOUND)
                .location(URI.create("http://www.google.com"))
                .build();
        
    }

}

When hitting the URL which triggers the above function, it returns following json Object (tested with Postman):

 {
    "headers": {
        "Location": [
            "http://www.google.com"
        ]
    },
    "body": null,
    "statusCodeValue": 302,
    "statusCode": "FOUND"
}

But it doesn´t actually redirect the user...so what is missing here?

skm
  • 559
  • 1
  • 6
  • 22
  • I am not seeing anything here related to spring-cloud-function. Can you possibly post more information or better off a sample project somewhere on github where we can tae a look? – Oleg Zhurakousky Jul 13 '20 at 12:08

1 Answers1

0

Found the Solution....

When this function is called by AWS, the redirect goes back to AWS and so is executed...localls its difficult to test as I could not test it actually.

skm
  • 559
  • 1
  • 6
  • 22