Error with Groovy in ScriptRunner Edited

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

This widget could not be displayed.

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?

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. 

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.

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

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.

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.  

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

222 views 1 3
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