Reputation: 9785
I am doing a REST Call to a Teamcity URI, to gte the lastSuccessful build Number but getting 406. If i use the same URI in Chrome's REST Console, i get the correct String ( Which is the latest Build Number
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
public class LastSuccessBuildNum {
public static void main(String[] args) {
try {
Client client = Client.create();
// client basic auth demonstration
client.addFilter(new HTTPBasicAuthFilter("username", "password"));
WebResource webResource = client
.resource("http://localteamcity.com/teamcity/app/rest/buildTypes/id:bt26/builds/status:SUCCESS/number");
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Output from Server .... \n");
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
}
stdout:
java.lang.RuntimeException: Failed : HTTP error code : 406
at LastSuccessBuildNum.main(LastSuccessBuildNum.java:22)
Upvotes: 2
Views: 12790
Reputation: 604
Check the MIME type of the transfer in Chrome REST Client, maybe it is not json. 406 means that the server does not have a MIME type that the client accepts: http://www.checkupdown.com/status/E406.html
Is there a specific reason that you use jersey client instead of Apache Http Components?
Upvotes: 5