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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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')
)

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.

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'
}

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
Community showcase
Published in Jira Service Management

Atlympic Event: Jira Service Managemnt

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

121 views 0 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you