Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpException


    @Test (expected=BigSwitchVnsApiException.class)
    public void testExecuteDeleteObjectException() throws BigSwitchVnsApiException, IOException {
        _api.setControllerAddress("10.10.0.10");
        _method = mock(DeleteMethod.class);
        when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
        when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
        try {
            _api.executeDeleteObject("/");
        } finally {
            verify(_method, times(1)).releaseConnection();
        }
View Full Code Here


   * It not possible to properly mock login()
   */
  @Test (expected=NiciraNvpApiException.class)
  public void executeMethodTestWithLogin() throws NiciraNvpApiException, HttpException, IOException {
    GetMethod gm = mock(GetMethod.class);
    when(_client.executeMethod((HttpMethod)any())).thenThrow(new HttpException());
    when(gm.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED).thenReturn(HttpStatus.SC_UNAUTHORIZED);
    _api.executeMethod(gm);
    verify(gm, times(1)).getStatusCode();
  }
View Full Code Here

  }

  @Test (expected=NiciraNvpApiException.class)
  public void testExecuteCreateObjectException() throws NiciraNvpApiException, IOException {
    LogicalSwitch ls = new LogicalSwitch();
    when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
    _method = mock(PostMethod.class);
    when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    Header header = mock(Header.class);
    when(header.getValue()).thenReturn("text/html");
    when(_method.getResponseHeader("Content-Type")).thenReturn(header);
View Full Code Here

  @Test (expected=NiciraNvpApiException.class)
  public void testExecuteDeleteObjectException() throws NiciraNvpApiException, IOException {
    _method = mock(DeleteMethod.class);
    when(_method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
    try {
      _api.executeDeleteObject("/");
    } finally {
      verify(_method, times(1)).releaseConnection();     
   
View Full Code Here

  @Test (expected=NiciraNvpApiException.class)
  public void testExecuteRetrieveObjectException() throws NiciraNvpApiException, IOException {
    _method = mock(GetMethod.class);
    when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
    when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
    when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
    try {
      _api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
    } finally {
      verify(_method, times(1)).releaseConnection();
    }
View Full Code Here

    post.setRequestBody(data);

    try {
      httpClient.executeMethod(post);
      if (post.getStatusCode() != HttpStatus.SC_OK) {
        throw new HttpException(post.getStatusLine().toString());
      }
      response = post.getResponseBodyAsString().trim();
      ssoToken = response.substring(9);
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

    post.setRequestBody(data);

    try {
      httpClient.executeMethod(post);
      if (post.getStatusCode() != HttpStatus.SC_OK) {
        throw new HttpException(post.getStatusLine().toString());
      }
    } catch (HttpException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
View Full Code Here

        ChukwaHttpSender.metrics.httpTimeOutException.inc();
      }
     
      log.error(">>>>>> HTTP response from " + dest + " statusLine: " + method.getStatusLine());
      // do something aggressive here
      throw new HttpException("got back a failure from server");
    }
    // implicitly "else"
    log.info(">>>>>> HTTP Got success back from "+ dest + "; response length "
            + method.getResponseContentLength());
View Full Code Here

            case HttpStatus.SC_SEE_OTHER:
            case HttpStatus.SC_TEMPORARY_REDIRECT:
                if(!methid.getFollowRedirects()) {
                    if(LOG.isInfoEnabled())
                        LOG.warn("Redirect requested but not supported");
                    throw new HttpException("Redirect requested");
                }

                Header locationHeader = methid.getResponseHeader("location");
                if(locationHeader == null) {
                    if(LOG.isInfoEnabled())
                        LOG.warn("Redirect requested, no location header");
                    throw new HttpException("Redirected without a location");
                }

                String location = locationHeader.getValue();
                if(LOG.isInfoEnabled())
                    LOG.info("Redirected requested to: " + location);

                URI newLocation = new URI(location.toCharArray());

                // Retrieve the RequestHeaders
                Header[] requestHeaders = methid.getRequestHeaders();

                // Recycle this method so we can use it again.
                methid.recycle();

                HostConfiguration hc = methid.getHostConfiguration();
                hc.setHost(
                    newLocation.getHost(),
                    newLocation.getPort(),
                    newLocation.getScheme()
                );

                methid.setFollowRedirects(true);

                for(int j = 0; j < requestHeaders.length; j++) {
                    if(!requestHeaders[j].getName().equals("Host"))
                        methid.addRequestHeader(requestHeaders[j]);
                }

                // Set up the new values for the method.
                methid.setPath(newLocation.getEscapedPath());
                methid.setQueryString(newLocation.getEscapedQuery());
                methid.removeRequestHeader(HttpAuthenticator.WWW_AUTH_RESP);

                // Loop around and try the method again.
                break;
            default:
                return;
            }
        }
        throw new HttpException("Maximum redirects encountered, bailing");
    }
View Full Code Here

            }
            catch (Exception e)
            {
                exPayload = "Invalid status code: " + statusCode;
            }
            message.setExceptionPayload(new DefaultExceptionPayload(new HttpException(exPayload)));
        }
        else
        {
            message.setPayload(payload);
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.HttpException

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.