These are chat archives for spring-cloud/spring-cloud

24th
Feb 2017
Casey Link
@Ramblurr
Feb 24 2017 09:01
another batch question: in java 8 is there any benefit to using RepositoryItemWriter over just passing the repository::save method reference?
Dave Syer
@dsyer
Feb 24 2017 09:39
This is a channel for spring cloud.
Please put usage questions for other spring libraries in stackoverflow
Casey Link
@Ramblurr
Feb 24 2017 09:39
Ah my apologies! Will do.
Amin Abu-Taleb
@aabutaleb
Feb 24 2017 11:07
hi Guys! since yesterday I'm having issues with an OPTIONS request coming from cross-origin client. The service automatically rejects it because it doesn't match any of the defined RequestMappings. I saw @dsyer comment in github that zuul already passes it through onto the service so I guess it's a service issue I need to solve.
I've tried to do spring.mvc.dispatchOptionsRequest: true but it doesn't work, can anyone help on this?
Dave Syer
@dsyer
Feb 24 2017 11:12
How about a minimal sample?
If you can reproduce it we can analyse what's going on easier
Amin Abu-Taleb
@aabutaleb
Feb 24 2017 11:17

Sure, having:

@RequestMapping("/")
public class TestController {

    private static final Logger LOG = LoggerFactory.getLogger(TestController.class);

    @RequestMapping(value = "/test",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE)
    public MyResponse search(@Validated SearchCriteria criteria) {
        LOG.info("Performing a Search with criteria: {}", criteria);
        return new MyResponse();
    }
}

curl --verbose -H "Origin: http://localhost" -H "Access-Control-Request-Method: GET" -H "Api-Version: v10" -X OPTIONS http://localhost:9014/test

returns: Invalid CORS request

I see this in the logs:

Request 'OPTIONS /test' doesn't match 'GET /**'

Dave Syer
@dsyer
Feb 24 2017 11:17
How about putting some code in github?
I don't think that's a valid CORS request
Amin Abu-Taleb
@aabutaleb
Feb 24 2017 11:19
It works if I remove the -H "Access-Control-Request-Method: GET"
Dave Syer
@dsyer
Feb 24 2017 11:22
"works" in what sense?
If you can put a simple app on github it will help a lot
Amin Abu-Taleb
@aabutaleb
Feb 24 2017 11:23
I know, sorry i can try writing a whole new example, I'm working on a proprietary code and cannot share any details, and that could be a totally different problem
I'm just trying to understand what's happening, that's why my question is a bit vague
Dave Syer
@dsyer
Feb 24 2017 11:27
Well, for a start, if you want to serve a CORS response you have to send a valid request
Amin Abu-Taleb
@aabutaleb
Feb 24 2017 11:27
The web client consuming my API receives Invalid CORS request when doing a POST from a different domain because the browser sends an OPTIONS request first and that doesn't work. I've a Zuul proxy in front of my services layer but I bypassed it assuming (based on one of your comments in github) that zuul passes that through onto the services. It indeed fails without zuul so I assume I need to do something to enable this OPTIONS but all I found in SO was people writhing their OPTIONS endpoints so they can handle it :S
Dave Syer
@dsyer
Feb 24 2017 11:28
It's not really a Spring Cloud problem then is it?
There's a big section in the Spring User Guide on CORS: https://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cors
Amin Abu-Taleb
@aabutaleb
Feb 24 2017 11:29
cool, that's a good start, thanks again
Josh Fix
@joshfix
Feb 24 2017 18:21
in the past i've used this controller to universally handle all of my options requests
public class PreFlightOptionsController {

    // this method will handle all cross-domain preflight OPTIONS requests
    @RequestMapping(method = RequestMethod.OPTIONS, value = "/*")
    @ResponseBody
    public ResponseEntity handleOptions() {
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }
}