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

http-builder RESTClient dependencies

Leo Dopson Mar 26, 2013

Hi Jaimie,

I'm hoping you can help pointing me in the right direction, I'm receiving this class dependency in my logs :

2013-03-27 11:24:40,153 http-bio-8081-exec-1 ERROR [webwork.util.ValueStack] METHOD: "promotedLinks", exception:

java.lang.NoClassDefFoundError: groovy/lang/GroovyObject

while using:

-----------------------

import groovyx.net.http.RESTClient

import groovy.util.slurpersupport.GPathResult;

import static groovyx.net.http.ContentType.URLENC

def myRC = new RESTClient("http://localhost/")

------------------------

I'm using the http-builder-0-1.7-20130216.204411-3.jar to access the RESTClient class.

I noticed that this class it's in the jar:

../META-INF/lib/groovy-all-1.8.5-scriptrunner.jar

Should I install groovy-all-1.0-jsr-06.jar to resolve this dependency? Or should this be picked up by your groovyrunner jar?

Leo

1 answer

1 accepted

1 vote
Answer accepted
Leo Dopson Mar 27, 2013

I decided to try apache's implementation instead, this script is called from another script and should really pass the rest_data parameter (needs to be cleaned up).

-rw-r--r-- 1 root root 115669 Mar 27 14:08 httpclient-cache-4.2.3.jar

-rw-r--r-- 1 root root 223571 Mar 27 13:53 httpcore-4.2.2.jar

-rw-r--r-- 1 root root 433070 Mar 27 13:51 httpclient-4.2.3.jar

Here is the script that eventually worked.

import groovy.sql.Sql;
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import groovy.json.*;
import java.util.ArrayList as ArrayList;
import java.sql.Connection;
import org.apache.log4j.Category;
import org.ofbiz.core.entity.ConnectionFactory;
import org.ofbiz.core.entity.DelegatorInterface;
import java.security.MessageDigest
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

log.error("sugarREST.groovy script " );
def username = "USERNAME";
def password = "PASSWORD";
def url = "http://localhost/service/v4/rest.php";
def restdata = new BasicNameValuePair("rest_data", '{"user_auth":{"user_name":"' + username + '","password":"' + MD5(password) + '","version":"1"},"application_name":"RestTest","name_value_list":[]}');
//println("restdata: " + restdata);

def result = call("login", restdata, url);
def session_id = result.id;

//println("SESSION ID: " + result.id);

//get list of records --------------------------------
def get_entry_list_parameters = new BasicNameValuePair("rest_data", '{"session" : "' + session_id + '", "module_name" : "Opportunities", "query" : "", "order_by" : "", "offset" : "0", \
     "fields" : ["name","description","start_date", "last_name", "end_date", "status", "nrc"], \
     "link_name_to_fields_array":[], "max_results":"2", "deleted":"0", "Favorites":false }');

//println("get_entry_list_parameters: " + get_entry_list_parameters);

def get_entry_list_result = call('get_entry_list', get_entry_list_parameters, url);

println("RESULTS: " + get_entry_list_result);

//--------------------------------------------
// sugar call
//--------------------------------------------
def call (method, rest_data, restURL) {
     def response = null;
     def returnVal = "";

     try {
      DefaultHttpClient client = new DefaultHttpClient();
      def post = new HttpPost(restURL);

      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
      nameValuePairs.add(new BasicNameValuePair("method", "${method}"));
      nameValuePairs.add(new BasicNameValuePair("input_type", "JSON"));
      nameValuePairs.add(new BasicNameValuePair("response_type", "JSON"));
      nameValuePairs.add(rest_data);

      post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
      response = client.execute(post);
      BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
      String line = "";
      while ((line = rd.readLine()) != null) {
          returnVal = returnVal + line;
          //println ("LINE : " + line);
      }

    } catch (e) {
      //e.printStackTrace();
      log.error("sugarREST.groovy failed, turn on stack trace to see the problem");
   }

   if(returnVal && returnVal != null && returnVal != "null" ) {
      println ("VALUE: [" + returnVal + "]");
      def jsonObj = new JsonSlurper().parseText(returnVal);
      return jsonObj;
   } else {
      return null;
   }
}

//-----
//MD5
//-----
 def MD5(String s) {
    MessageDigest digest = MessageDigest.getInstance("MD5")
    digest.update(s.bytes);
    new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
 }


JamieA Mar 30, 2013

It's a bit of a pain using httpbuilder, because, although it is excellent and easy to use, the maven dependencies include a load of xml stuff and httpcommons that conflicts with other libraries in use.

Leo Dopson Mar 31, 2013

I spent a couple of days trying to wade through those dependencies which eventually led to conflicting calls. After that, it just wasn't worth the effort.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar alert! An IT Admin's Guide to Securing Collaboration at Scale

Hello, Atlassian Community! My name is Dave Meyer and I'm a Principal Product Manager at Atlassian. I wanted to give this community a heads up about an upcoming Webinar that might be of interest...

171 views 2 7
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