Accessing Crucible rest-service-fe/search-v1/reviewsForChangeset via Google HTTP Client returns Code 500
Asked by Jeff Wilson:

I'm writing a Java client to the Atlassian Crucible REST API to return all reviews for a given changeset, and cannot seen to get it working.

The code looks correct, but returns HTTP Code 500 and a non-specific message.

Here is the code:

```
/** * @see * https://docs.atlassian.com/fisheye-crucible/latest/wadl/fisheye.html#rest-service-fe:search-v1:reviewsForChangeset:repository */List&lt;Review&gt; searchReviewsForChangeset(String repo, String changeset){   HttpResponse response;   try   {      String command = String.format("%s/reviewsForChangeset/%s", SEARCH, repo);      CrucibleUrl crucibleUrl = new CrucibleUrl(url + command);      HttpContent content = new UrlEncodedContent(new Object()      {         @Key         String cs = changeset;      });      HttpRequest request = requestFactory.buildPostRequest(crucibleUrl, content);      request.setLoggingEnabled(true);      // request.setUnsuccessfulResponseHandler(this);      response = request.execute();      Reviews x = response.parseAs(Reviews.class);      return x.list;   }   catch (IOException ex)   {      Logger.getLogger(Crucible.class.getName()).log(Level.SEVERE, null, ex);      return Collections.emptyList();   }}
```

The HttpRequestFactory is initialized like this:

```
HttpTransport transport = new NetHttpTransport();  JsonFactory jsonFactory = new GsonFactory();  HttpRequestFactory requestFactory = transport.createRequestFactory(request -&gt;  {     request.setParser(new JsonObjectParser(jsonFactory));     HttpHeaders httpHeaders = new HttpHeaders();     httpHeaders.setContentType("application/json");     httpHeaders.setAccept("application/json");     request.setHeaders(httpHeaders);  });
```

```
Here is the output I get (with logging turned on in the Google HTTP Client):
```

```
CONFIG: -------------- REQUEST  --------------POST http://crucible.snt.bst.bls.com:8060/rest-service-fe/search-v1/reviewsForChangeset/BBNMS-JBBOSAccept: application/jsonAccept-Encoding: gzipAuthorization: &lt;Not Logged&gt;Content-Type: application/jsonUser-Agent: Google-HTTP-Java-Client/1.20.0 (gzip)Content-Type: application/x-www-form-urlencoded; charset=UTF-8Content-Length: 9Nov 03, 2015 4:05:21 PM com.google.api.client.http.HttpRequest executeCONFIG: curl -v --compressed -X POST -H 'Accept: application/json' -H 'Accept-Encoding: gzip' -H 'Authorization: &lt;Not Logged&gt;' -H 'Content-Type: application/json' -H 'User-Agent: Google-HTTP-Java-Client/1.20.0 (gzip)' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d '@-' -- 'http://crucible.snt.bst.bls.com:8060/rest-service-fe/search-v1/reviewsForChangeset/BBNMS-JBBOS' &lt;&lt; $$$Nov 03, 2015 4:05:21 PM com.google.api.client.util.LoggingByteArrayOutputStream closeCONFIG: Total: 9 bytesNov 03, 2015 4:05:21 PM com.google.api.client.util.LoggingByteArrayOutputStream closeCONFIG: cs=161883Nov 03, 2015 4:05:21 PM com.google.api.client.http.HttpResponse &lt;init&gt;CONFIG: -------------- RESPONSE --------------HTTP/1.1 500 Internal Server ErrorTransfer-Encoding: chunkedServer: Jetty(6.1.26)Cache-Control: privateX-AUSERNAME: jw9615Set-Cookie: FESESSIONID=qbewjdhe9f17q9ykuetqqzbv;Path=/;HttpOnlySet-Cookie: crucibleprefs1="D%3D1446584721687";Path=/;Expires=Wed, 02-Nov-2016 21:05:21 GMTSet-Cookie: remember=;Path=/;Expires=Thu, 01-Jan-1970 00:00:00 GMT;HttpOnlyExpires: Thu, 01-Jan-1970 00:00:00 GMTContent-Type: application/jsonNov 03, 2015 4:05:21 PM com.google.api.client.util.LoggingByteArrayOutputStream closeCONFIG: Total: 12,071 bytesNov 03, 2015 4:05:21 PM com.google.api.client.util.LoggingByteArrayOutputStream closeCONFIG: {"code":"WebApplication","message":null,"stacktrace":"javax.ws.rs.WebApplicationException\n\tat com.sun.jersey.server.impl.uri.rules.TerminatingRule.accept(TerminatingRule.java:66)\n\tat com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)\n\tat com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tat com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)... many more lines elided ...at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)\n\tat org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)\n\tat org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)\n\tat org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)\n\tat org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)\n\tat org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:451)\n"}
```

What am I doing wrong? I can provide the entire stacktrace as needed.

Here is a list of my dependencies:

Java 8u40, plus the following:

```
&lt;dependency&gt;        &lt;groupId&gt;commons-cli&lt;/groupId&gt;        &lt;artifactId&gt;commons-cli&lt;/artifactId&gt;        &lt;version&gt;1.3.1&lt;/version&gt;    &lt;/dependency&gt;    &lt;dependency&gt;        &lt;groupId&gt;commons-configuration&lt;/groupId&gt;        &lt;artifactId&gt;commons-configuration&lt;/artifactId&gt;        &lt;version&gt;1.10&lt;/version&gt;    &lt;/dependency&gt;    &lt;dependency&gt;        &lt;groupId&gt;com.google.http-client&lt;/groupId&gt;        &lt;artifactId&gt;google-http-client&lt;/artifactId&gt;        &lt;version&gt;1.20.0&lt;/version&gt;    &lt;/dependency&gt;    &lt;dependency&gt;        &lt;groupId&gt;com.google.http-client&lt;/groupId&gt;        &lt;artifactId&gt;google-http-client-gson&lt;/artifactId&gt;        &lt;version&gt;1.20.0&lt;/version&gt;    &lt;/dependency&gt;
```


Answers:
author: Piotr Swiecicki
body: Hi @Jeff Wilson,

I think the problem is caused by repeated Content-Type header - it is set to application/json first, but then set again to application/x-www-form-urlencoded; charset=UTF-8.

As you are submitting form-urlencoded data try removing

```
httpHeaders.setContentType("application/json");
```

That should help.