Log behaviour script REST API calls

Miguel Ángel García Gómez November 3, 2017

I have asked this question in Script Runner support, so I realley appreciate any help that somebody can gives me:

I have implemented a behaviour initialiser function script which makes a REST API call.

The behavoiur script is executed one, two, three or four times (this behavoiur was reported https://productsupport.adaptavist.com/servicedesk/customer/portal/2/SRJSUP-2729) and I want to log how many times the REST API is called, filtering calls for example with Chrome debug tool or with some protocol analyzer like Wireshark, but I don't know how to filter the API REST calls because are wrapped into the script.

The REST API call is made like this:

Map getInstallInfo(OkHttpClient httpClient) {
    String url = 'http://192.168.5.227:51681/GeneralService.svc/GetClientProductList'    String projectName = getIssueContext().getProjectObject().getName()

    RequestBody body = RequestBody.create(MediaType.parse("text/plain"), JsonOutput.toJson([Product: projectName, Client: null]))
    Response response
    try {
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build()

        response = httpClient.newCall(request).execute()
        return response.isSuccessful() ? [contentText: response.body().string()] : [errorText: "${response.code()} - ${response.message()}"]
    } catch (e) {
        return [errorText: "${e.class.canonicalName} - ${e.message}"]
    } finally {
        response?.close()
    }
}

 Therefore, I want to know how many times this URL (http://192.168.5.227:51681/GeneralService.svc/GetClientProductList) is called.

I really appreciate yout help.

Thank you in advanve.

Regards,
Miguel.

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 3, 2017

Hello, 

I think you can not see it in a browser because rest is executed on the server. Put the first line in you rest api call( before String url)  log.error("rest executed") and search for the number of these messages in atlassian-jira.log

Miguel Ángel García Gómez November 7, 2017

Hello Alexey,

Thank you for your response. However, I'm thinking in log the request when JIRA makes it.

I mean, I've put a log, as you said, in the first line method and then I see it in the atalassian-jira.log. This approach is rigth and useful, but I'm trying to intercept the REST API call in the exact moment when it is called. Because of that, I'm thinking in an analyzer like Wireshark to intercept this call, but I don't know how to intercept it, because if a filter by IP is done, it doesn't appear. 

To clarify, the analyzer would be in JIRA server.

Regards,

Miguel.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2017

Hello,

I do not work with Adaptivist and that is why I do not have access to the source code of Scriptrunner. But here is my understanding on how the behavour works in your case.

Scriptrunner loads its generic JavaScript on the creation, edit, browse and transition screens. This generic Javascript calls REST modules of ScriptRunner which can execute the code which you defined in the behavour and return the result to the generic JavaScript.  Generic Javascript works on the result and makes changes to UI according to the result. Your custom Rest Call is executed on the server that is why you can not see its executions in your browser. You can only see Rest calls which are produced by the generic Javascript to  Scriptrunner Rest Api. For example that woud be the call

/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json

Push F12 key in your browser, go to Network part and you will see this call. But from this call you will not understand if it calls your custom Rest Api or not. That is why you can just see executions of your custom Rest api in atlassian-jira.log

Miguel Ángel García Gómez November 7, 2017

Thanks Alexey for your explanation ;)

I could see that {{/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json}} is called and the response  contains all information about custom fields (errorMsg, helpText, setValue, validity, readonly, fieldOptions an dfieldType). 

This clarifies me how the calls to Script Runner are made, so thank you ;)

But I still have the doubt about how to filter in the JIRA server the REST API call to the endpoint {{http://192.168.5.227:51681/GeneralService.svc/GetClientProductList}}. Now, I've untderstood that the solution shuold be found in the server side, but as I mentioned before, if a filter by IP 192.168.5.227 is done in JIRA server, no results are shown. So here is my doubt, why I can't see this filtered by IP results.

If you, or anyone, could figure out how to do, it would be great ;)

Thanks!

Suggest an answer

Log in or Sign up to answer