Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Insight automation crippled in JSM 4.17 (How to rewrite Groovy HTTPBuilder calls easily?)

Gareth Cantrell
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.
June 30, 2021

After upgrading to JSM Data Center 4.17.0 (which bundles Insight 9.0.7), all of our Insight automations which rely on the the Groovy HTTP Builder library (http-builder-0.7.1) to communicate with external REST APIs no longer work, severely crippling our CMDB and Incident management processes (Atlassian has removed this library in the latest version without deprecation notice).

Is there any quick way to replace groovy RESTClient calls without writing reams of HTTP handler code?

(I have raised a separate support request with Atlassian, however we need to progress while we wait for a response)

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2021

Thanks for the heads up... I'll be sure to check the impact in our environment.

Have you tried using grapes to import the library in your environment?

Add this to your insight groovy script:

@Grapes(
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
)
Gareth Cantrell
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.
July 1, 2021

Thanks for the response Peter, however it appears that using grapes within Insight scripts does not work.

I've tried every imaginable combination, including manually downloading the jar file into the correct grapes location without any joy.

Insight still reports compilation errors.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2021

Using the SDK, I installed 4.17.1and 4.18.0 and was able to replicate this.

I tried to see if I could use import com.atlassian.sal.api.net.RequestFactory to generate a basic request, but I can't seem to correctly instantiate that from Insight Groovy. I have no problem in scriptrunner using the @PluginModule notation but I could not figure out how to do it natively.

I kinda got close with this:

import com.atlassian.jira.component.ComponentAccessor
def classLoader = ComponentAccessor.pluginAccessor.classLoader

Class HTTPBuilder = classLoader.loadClass('groovyx.net.http.HTTPBuilder')
Class Method = classLoader.loadClass('groovyx.net.http.Method')
Class ContentType = classLoader.loadClass('groovyx.net.http.ContentType')

classLoader.findClass('groovyx.net.http.HTTPBuilder')
System.getProperty('java.class.path')

def httpBuilder = HTTPBuilder.newInstance('http://localhost:2990')

log.info "${httpBuilder.metaClass.methods.name.sort().unique()}" //methods are correctly printed, so the class is loaded
httpBuilder.request(Method.GET){
uri.path = '/jira/status'
}

Gareth Cantrell
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.
July 7, 2021

I ended up writing a separate Groovy class which mimics the original RESTClient public methods (only the ones we make use of).

The implementations of these methods make use of the Apache HttpClient library which is mostly available to Insight (unfortunately, the HC fluent API is not made available to plugins).

Downside is we now have to maintain plumbing code in a script on top of the business logic, however at least we no longer face rewriting all our scripts to cater for the missing library.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events