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

Calling REST service from groovy script. Encoding troubles.

Andrey Pechnikov March 3, 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;
            try{
                requestEntity=new StringEntity(json);
                HttpPost post = null;
                post = new HttpPost("https://myjira.com:8443/rest/tempo-teams/1/team");
                post.setHeader("Authorization", "Basic base64_encoded_login"); 
                post.addHeader("Content-Type", "application/json;charset=utf-8");
                post.setEntity(requestEntity);
                ResponseHandler<String> handler = new BasicResponseHandler();
                HttpResponse response = client.execute(post);
                String body = handler.handleResponse(response);
                int statusCode = response.getStatusLine().getStatusCode();
                if(statusCode!=HttpStatus.SC_OK){
                    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
Andrey Pechnikov March 5, 2015

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

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

0 votes
Andrey Pechnikov March 3, 2015

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

TAGS
AUG Leaders

Atlassian Community Events