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

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

Accessing Crucible rest-service-fe/search-v1/reviewsForChangeset via Google HTTP Client returns Code 500

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<Review> 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 ->
  {
     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-JBBOS
Accept: application/json
Accept-Encoding: gzip
Authorization: <Not Logged>
Content-Type: application/json
User-Agent: Google-HTTP-Java-Client/1.20.0 (gzip)
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 9

Nov 03, 2015 4:05:21 PM com.google.api.client.http.HttpRequest execute
CONFIG: curl -v --compressed -X POST -H 'Accept: application/json' -H 'Accept-Encoding: gzip' -H 'Authorization: <Not Logged>' -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' << $$$
Nov 03, 2015 4:05:21 PM com.google.api.client.util.LoggingByteArrayOutputStream close
CONFIG: Total: 9 bytes
Nov 03, 2015 4:05:21 PM com.google.api.client.util.LoggingByteArrayOutputStream close
CONFIG: cs=161883
Nov 03, 2015 4:05:21 PM com.google.api.client.http.HttpResponse <init>
CONFIG: -------------- RESPONSE --------------
HTTP/1.1 500 Internal Server Error
Transfer-Encoding: chunked
Server: Jetty(6.1.26)
Cache-Control: private
X-AUSERNAME: jw9615
Set-Cookie: FESESSIONID=qbewjdhe9f17q9ykuetqqzbv;Path=/;HttpOnly
Set-Cookie: crucibleprefs1="D%3D1446584721687";Path=/;Expires=Wed, 02-Nov-2016 21:05:21 GMT
Set-Cookie: remember=;Path=/;Expires=Thu, 01-Jan-1970 00:00:00 GMT;HttpOnly
Expires: Thu, 01-Jan-1970 00:00:00 GMT
Content-Type: application/json

Nov 03, 2015 4:05:21 PM com.google.api.client.util.LoggingByteArrayOutputStream close
CONFIG: Total: 12,071 bytes
Nov 03, 2015 4:05:21 PM com.google.api.client.util.LoggingByteArrayOutputStream close
CONFIG: {"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:

<dependency>
        <groupId>commons-cli</groupId>
        <artifactId>commons-cli</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client</artifactId>
        <version>1.20.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client-gson</artifactId>
        <version>1.20.0</version>
    </dependency>

1 answer

1 accepted

1 vote
Answer accepted

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Statuspage

New feature: Slack notifications for Statuspage

We're excited to announce the release of a long-requested feature on Statuspage. Now visitors to your status page can subscribe to get notified in Slack when you report an incident or maintenance. Th...

67 views 0 9
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