Package org.apache.http.client

Examples of org.apache.http.client.HttpResponseException


     */
    public String handleResponse(final HttpResponse response)
            throws HttpResponseException, IOException {
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }

        HttpEntity entity = response.getEntity();
        return entity == null ? null : EntityUtils.toString(entity);
View Full Code Here


  @Test (expected = ApplicationException.class)
  @SuppressWarnings("unchecked")
  public void failsWithApplicationExceptionOnInternalErrors() throws Exception {
    TestMusicBrainzClient client = getClient();
    when(client.getHttpClient().execute(any(HttpUriRequest.class),
        any(ResponseHandler.class))).thenThrow(new HttpResponseException(503, "NA"));

    client.get();
  }
View Full Code Here

  @Test
  public void validatePackagingOfResponseCode404() throws ApplicationException, IOException {
    final int errorCode = 404;
    final String errorMessage = "Not found";
    HttpResponseException hpe = new HttpResponseException(errorCode, errorMessage);
    TestWSGetClient testWSClient = getTestWSClient(hpe);
    WSResponse response = testWSClient.testCall();
   
    Assert.assertTrue(response.wasCallAllowed());
    Assert.assertFalse(response.wasCallSuccessful());
View Full Code Here

  @Test
  public void validatePackagingOfResponseCode503() throws ApplicationException, IOException {
    final int errorCode = 503;
    final String errorMessage = "Service temporary unavailable";
    HttpResponseException hpe = new HttpResponseException(errorCode, errorMessage);
    TestWSGetClient testWSClient = getTestWSClient(hpe);
    WSResponse response = testWSClient.testCall();
   
    Assert.assertTrue(response.wasCallAllowed());
    Assert.assertFalse(response.wasCallSuccessful());
View Full Code Here

  public void handlesArtistFailureDuringUpdate() throws ApplicationException {
    final String revName = reverse(artistName);
    submitFile(additionDao, getFile(revName, albumName, trackName));
   
    Mockito.when(service.artistQueryClient.get(revName)).thenThrow(
      new ApplicationException("Fail", new HttpResponseException(503, "Overloaded")));
   
    service.updateDiscography();
   
    List<MBAlbum> albums = service.getMissingAlbums(artistName, asList(TYPE_EP), null, -1, 0);
    Assert.assertEquals(2, albums.size());
View Full Code Here

     */
    public String handleResponse(final HttpResponse response)
            throws HttpResponseException, IOException {
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }

        HttpEntity entity = response.getEntity();
        return entity == null ? null : EntityUtils.toString(entity);
View Full Code Here

     */
    public String handleResponse(final HttpResponse response)
            throws HttpResponseException, IOException {
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }

        HttpEntity entity = response.getEntity();
        return entity == null ? null : EntityUtils.toString(entity);
View Full Code Here

    HttpGet httpget = new HttpGet(uri);
    HttpResponse response = httpclient.execute(httpget);
    StatusLine statusline = response.getStatusLine();
    if (statusline.getStatusCode() >= HttpStatus.SC_BAD_REQUEST) {
      httpget.abort();
      throw new HttpResponseException(
          statusline.getStatusCode(), statusline.getReasonPhrase());
    }
    HttpEntity entity = response.getEntity();
    if (entity == null) {
      // Should _almost_ never happen with HTTP GET requests.
View Full Code Here

    StatusLine statusline = response.getStatusLine();
    if (statusline.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
      return null;
    }
    if (statusline.getStatusCode() != HttpStatus.SC_OK) {
      throw new HttpResponseException(
          statusline.getStatusCode(), statusline.getReasonPhrase());
    }
    HttpEntity entity = response.getEntity();
    if (entity != null) {
      return entity.getContent();
View Full Code Here

    HttpGet httpget = new HttpGet(uri);
    HttpResponse response = getHttpClient().execute(httpget);
    StatusLine statusline = response.getStatusLine();
    if (statusline.getStatusCode() >= HttpStatus.SC_BAD_REQUEST) {
      httpget.abort();
      throw new HttpResponseException(
          statusline.getStatusCode(), statusline.getReasonPhrase());
    }
    HttpEntity entity = response.getEntity();
    if (entity == null) {
      // Should _almost_ never happen with HTTP GET requests.
View Full Code Here

TOP

Related Classes of org.apache.http.client.HttpResponseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.