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.

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted

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

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

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

Community showcase
Published in Training & Certification

Introducing Atlassian University Live!

Atlassian University is committed to providing the best training and certification for Atlassian products through on-demand classes, in-person team training, a world-class certification program, and ...

173 views 3 15
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