Description
The example REST endpoint to allow cross-origin requests doesn't work well in asynchronous contexts because it isn't thread safe. The chief cause of this seems to be that the extraPath dynamic variable isn't thread safe, which would affect any REST Endpoint that uses it.
As an example, add some debug text to the endpoint so that the bitbucketproxy looks something like this:
bitbucketproxy( httpMethod: "GET" ) { MultivaluedMap queryParams, String body, HttpServletRequest request -> // get the path after the method name, so we can proxy the request def extraPath = extraPath as String log.debug("Test") log.debug("Sent request to $extraPath") def response = http.request(GET, JSON) { path = extraPath } log.debug("Response: ${response.data}") return Response .ok(new JsonBuilder(response.data).toString()) .header("Access-Control-Allow-Origin", "*") .build() }
Then, click the button in the attached restendpointissue.html file. You can see from the javascript code that it's calling multiple URLs. However, the output will sometimes be something like:
2016-10-25 17:12:57 [http-bio-8080-exec-80] DEBUG c.o.s.runner.ScriptRunnerImpl - Test 2016-10-25 17:12:57 [http-bio-8080-exec-72] DEBUG c.o.s.runner.ScriptRunnerImpl - Test 2016-10-25 17:12:57 [http-bio-8080-exec-78] DEBUG c.o.s.runner.ScriptRunnerImpl - Test 2016-10-25 17:12:57 [http-bio-8080-exec-52] DEBUG c.o.s.runner.ScriptRunnerImpl - Test 2016-10-25 17:12:57 [http-bio-8080-exec-77] DEBUG c.o.s.runner.ScriptRunnerImpl - Test 2016-10-25 17:12:57 [http-bio-8080-exec-81] DEBUG c.o.s.runner.ScriptRunnerImpl - Test 2016-10-25 17:12:57 [http-bio-8080-exec-52] DEBUG c.o.s.runner.ScriptRunnerImpl - Sent request to /rest/api/1.0/projects 2016-10-25 17:12:57 [http-bio-8080-exec-80] DEBUG c.o.s.runner.ScriptRunnerImpl - Sent request to /rest/api/1.0/projects 2016-10-25 17:12:57 [http-bio-8080-exec-78] DEBUG c.o.s.runner.ScriptRunnerImpl - Sent request to /rest/api/1.0/projects 2016-10-25 17:12:57 [http-bio-8080-exec-72] DEBUG c.o.s.runner.ScriptRunnerImpl - Sent request to /rest/api/1.0/projects 2016-10-25 17:12:57 [http-bio-8080-exec-81] DEBUG c.o.s.runner.ScriptRunnerImpl - Sent request to /rest/api/1.0/projects 2016-10-25 17:12:57 [http-bio-8080-exec-77] DEBUG c.o.s.runner.ScriptRunnerImpl - Sent request to /rest/api/1.0/projects
The extraPath isn't different; sometimes, it's the same one from a previous call.
Attachments
Issue Links
- is related to
-
SRBITB-170 REST Endpoint Example to allow cross-origin requests is not thread safe
-
- Done
-