Log behaviour script REST API calls

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

This widget could not be displayed.
Alexey Matveev Community Champion Nov 03, 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

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 Community Champion Nov 07, 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

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

158 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you