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

Calling REST service from groovy script. Encoding troubles.

Andrey Pechnikov Mar 03, 2015

Hello all.
I'm trying to call one of REST services from groovy script. I'm doing it this way:

HttpClient client=new DefaultHttpClient();        
            HttpEntity requestEntity=null;
                requestEntity=new StringEntity(json);
                HttpPost post = null;
                post = new HttpPost("");
                post.setHeader("Authorization", "Basic base64_encoded_login"); 
                post.addHeader("Content-Type", "application/json;charset=utf-8");
                ResponseHandler<String> handler = new BasicResponseHandler();
                HttpResponse response = client.execute(post);
                String body = handler.handleResponse(response);
                int statusCode = response.getStatusLine().getStatusCode();
                    System.err.println("Status code = " + statusCode);
                    System.err.println("Method failed: "+method.getStatusLine());
                System.out.println("BODY  = \n"+body);
                System.out.println("CODE = " + statusCode );

service works successfully but russian symbols are displayed as "?", and that's the trouble.
They're in json string.
As you see i set encoding in Content-Type header. 
May be i need to change system's groovy encoding?

Thanks in advance.

3 answers

1 accepted

1 vote
Answer accepted
Andrey Pechnikov Mar 05, 2015

requestEntity=new StringEntity(json,HTTP.UTF_8) is the answer.

0 votes
Andrey Pechnikov Mar 03, 2015

Also all the application encoding settings are set to UTF-8 and everything is fie if calling rest service via rest client.

0 votes
Prabu Sivagnanam May 24, 2019

hey guys help me to integrate JIRA to Salesforce...i am sfdc developer but business asks me write JIRA code to push issues from jira side to salesforce which need to be done via JIRA code

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Featured Groups

Never Not Networking! Share your LinkedIn profile and let's connect.

As suggested on the Friday Funday thread ( - and happy bir...

377 views 38 6
View post

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