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

Error with Groovy in ScriptRunner

Jon Starbird
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.
October 5, 2017

I am trying to write a script that will talk to the Autotask API and I'm using the Script Console to test on. 

When I run I am hitting this error:

javax.xml.stream.FactoryConfigurationError: Provider for class javax.xml.stream.XMLInputFactory cannot be created 

and I've tried adding that as an import but it still fails.

Based on some posts online I believe the issue is something to do with the Autotask API messages needing to be in XML but not sure how to get around this.

I'm just doing a very simple call right now to verify the connection will work. 

Here is the test code I've written, this is taken from some sample code I was given and also from their documentation:

 

import javax.xml.ws.BindingProvider
import net.autotask.atws.v1_5.ATWS
import net.autotask.atws.v1_5.ATWSResponse
import net.autotask.atws.v1_5.ATWSSoap
import net.autotask.atws.v1_5.ATWSZoneInfo
import net.autotask.atws.v1_5.GetZoneInfo
import net.autotask.atws.v1_5.Ticket
import net.autotask.atws.v1_5.ArrayOfEntity
import net.autotask.atws.v1_5.Entity
import groovyx.net.http.HTTPBuilder

def ATWS newser = new ATWS()

ATWSSoap port = newser.getPort(ATWSSoap.class)
BindingProvider prov = (BindingProvider) port

prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,"username")
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "userspwd")
prov.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"https://webservices2.autotask.net/ATServices/1.5/atws.asmx")

def ATWSZoneInfo azi = new ATWSZoneInfo()
azi = port.getZoneInfo("username")

return azi.URL

 

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Jonny Carter
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.
October 9, 2017

So, I'm having some difficulty finding any information about the AutoTask Java API. I've found a Web Services API, a REST API, but no JavaDoc or anything.

My hunch is that you would need to make sure that a library with the AutoTask API was available on the classpath. I've been unable to find such a library in any maven repositories. Is there a particular plugin you're using to integrate AutoTask with Jira?

Jon Starbird
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.
October 11, 2017

I've done that. As you can see by my imports I am referring to a Java version of their API. the error I'm getting appears to be from a conflict with an XML library. 

The Scriptrunner console seems to find their libs fine as I get no errors loading it in the editor whereas I did when it could not find them.

At run time though I get that XML error. 

Jonny Carter
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.
October 11, 2017

I understand that. The trouble for me is in reproducing the problem. Where are you _getting_ the AutoTask libs?

The full stack trace would also help me help you.

Jon Starbird
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.
October 11, 2017

Certainly. Sorry, I should have thought of that. 

I got it from this link which was provided to me by the company whose Autotask setup we're trying to link up with.

https://github.com/jmuthu/autotask-helloworld

adammarkham
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.
October 18, 2017

Your right in that it sounds like it's some conflict with an XML library. Similar to this question here.

In that case they excluded the dependency which was causing the issue. If this is a JAR file that's just been provided to you then it's difficult to seework out which dependency is causing the issue.

I see your getting the JAR file from here: https://github.com/jmuthu/autotask-helloworld

I've unzipped the JAR file and taken a look. It looks like it could be one of the compiled classes that is conflicting. Is there any other API you could use apart from the Java API? The REST API may be easier to use for you. I'd assume this is just a wrapper around that one.

There's a good example here of using the RESTClient already available in ScriptRunner to execute REST calls. There's also further documentation here on that client.

Jon Starbird
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.
October 18, 2017

The Java lib was ported over from .Net libs they use. That would be the only other option. 

The issue I'm having is that Autotask's API uses SOAP and expects it's messages in XML. So I was trying to use their libs to construct the required formats. Without their libs I'll have to write all that myself. 

I'm no Java/Groovy expert so I was looking for the easiest route here.

I do know about the Rest Client and have used it a bit before but with Json.  

TAGS
AUG Leaders

Atlassian Community Events