Hi. I am trying to update a review request to add a target group and I got 
it to work using curl, but if I try the same command using Java using 
Spring RestTemplate or Apache Commons HttpClient, it doesn't work. I get a 
200 response code but there is no update being done. Can someone tell me 
what I am doing wrong? Thanks.

-- Java Code
    public void testPut_rest() throws Exception{
        String reviewId= "4969";
        String authToken = "Basic YXBhbGFkaW5vOkNpdHJpeDExMTc=";
        String url = 
"https://reviewboard-ouraddress-it.net/api/review-requests/"+reviewId+"/draft/";;

        /*    This works.

curl -k -H "Authorization: Basic YXBhbGFkaW5vOkNpdHJpeDExMTc=" -X PUT 
"https://reviewboard-ouraddress-it.net/api/review-requests/4968/draft/"; 
-d"api_format=json&expand=target_groups&target_groups=dev-adminservice%2C%20"
*/

        try {

            SimpleClientHttpRequestFactory requestFactory = new 
SimpleClientHttpRequestFactory() {
                @Override
                protected void prepareConnection(HttpURLConnection 
connection, String httpMethod) throws IOException {
                    super.prepareConnection(connection, httpMethod);
                    connection.setInstanceFollowRedirects(true);
                }

            };
            RestTemplate restTemplate = new RestTemplate();
            restTemplate.getMessageConverters().add(new 
FormHttpMessageConverter());
            restTemplate.getMessageConverters().add(new 
MappingJacksonHttpMessageConverter());
            restTemplate.getMessageConverters().add(new 
StringHttpMessageConverter());
            restTemplate.getMessageConverters().add(new 
ByteArrayHttpMessageConverter());
            restTemplate.setRequestFactory(requestFactory);
            HttpHeaders requestHeaders = new HttpHeaders();
            requestHeaders.set("Authorization", authToken);
            requestHeaders.set("Content-Type", 
"application/x-www-form-urlencoded");

            HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);

            Map<String, String> args = new HashMap<String, String>();
            args.put("api_format", "json");
            args.put("expand", "target_groups");
            args.put("target_groups", "dev-adminservice%2C%20");


            HttpEntity<Map> response =
                    restTemplate.exchange(url, HttpMethod.PUT, 
requestEntity, Map.class, args);

            System.out.println(response.getBody());



        } catch (Exception e) {
            e.printStackTrace();
        }

    }


-- 200 response code with following output
{"stat": "ok", "draft": {"last_updated": "2012-10-08 08:46:07", 
"description": "", "target_people": [], "changedescription": "", 
"target_groups": [], "links": {"self": {"href": 
"https://reviewboard-ouraddress-it.net/api/review-requests/4969/draft/";, 
"method": "GET"}, "update": {"href": 
"https://reviewboard-ouraddress-it.net/api/review-requests/4969/draft/";, 
"method": "PUT"}, "draft_screenshots": {"href": 
"https://reviewboard-ouraddress-it.net/api/review-requests/4969/draft/screenshots/";,
 
"method": "GET"}, "draft_file_attachments": {"href": 
"https://reviewboard-ouraddress-it.net/api/review-requests/4969/draft/file-attachments/";,
 
"method": "GET"}, "review_request": {"href": 
"https://reviewboard-ouraddress-it.net/api/review-requests/4969/";, 
"method": "GET", "title": "(no summary)"}, "delete": {"href": 
"https://reviewboard-ouraddress-it.net/api/review-requests/4969/draft/";, 
"method": "DELETE"}}, "bugs_closed": [], "public": false, "testing_done": 
"", "branch": "", "summary": "", "id": 4720}}

-- 
Want to help the Review Board project? Donate today at 
http://www.reviewboard.org/donate/
Happy user? Let us know at http://www.reviewboard.org/users/
-~----------~----~----~----~------~----~------~--~---
To unsubscribe from this group, send email to 
reviewboard+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en

Reply via email to