0

I have created a review request on ReviewBoard using the api, but I am now unable to add a diff file to this review request.

I am following the ReviewBoard instructions to sent a POST request to ReviewBoard API --> https://www.reviewboard.org/docs/manual/2.0/webapi/2.0/resources/diff-list/

My request header looks like this

{Content-Type: multipart/form-data; boundary=------- 1511347017267}{Accept: application/xml}{Authorization: token 4937d...sometoken...584b23}

My request body looks like this

------- 1511345733192
Content-Disposition: form-data; name="basedir"

/trunk_projectABC/
------- 1511345733192
Content-Disposition: form-data; name="path"; filename="build.diff"
Content-Type: text/xml

Index: utility/build.bat
===================================================================
--- utility/build.bat   (revision 67210)
+++ utility/build.bat   (working copy)
@@ -10,8 +10,8 @@
 echo off
 set thpcra=false
 set patchBuild=false
-set help=true
-set clientBuild=true
+set help=false
+set clientBuild=false
 set runJavaTestCases=false
 set buildpath="%BUILD_PATH%"
 set jdkpath="%JDK_17%"
------- 1511345733192 --

I found another question here review board diff not uploading and made sure that the repo URL + basedir + relative path is set right but I still get BAD REQUEST response from the server.

NOTE: I generated the diff using tortoiseSVN tool I am using HttpURLConnection conn = (HttpURLConnection) url.openConnection();

Any inputs on why I am getting BAD REQUEST from the server ?

Alpana
  • 1
  • 1

1 Answers1

0

Answering my own question.

I was using PrintWriter to write the request body on the connection output stream. Probably using a stream introduced any extra characters or somehow malformed the request body, but it was the reason why I was getting bad request.

I am now using MultipartRequestEntity to create the request body. Here is the code snippet

PostMethod method = new PostMethod(apiURL);
File diff = new File("D:/path_to_diff/build.diff");
partsList.add(new FilePart("path", diff.getName(), diff));
partsList.add(new StringPart("basedir", "/trunk_projectABC/"));
Part[] parts = partsList.toArray(new Part[partsList.size()]);
RequestEntity entity = new MultipartRequestEntity(parts, method.getParams());
method.setRequestEntity(entity);

This works and uploads a diff file on the review request

Alpana
  • 1
  • 1