The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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>
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.
Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.