Search in sources :

Example 71 with Header

use of org.apache.commons.httpclient.Header in project zm-mailbox by Zimbra.

the class TestWsdlServlet method doWsdlServletRequest.

String doWsdlServletRequest(String wsdlUrl, boolean admin, int expectedCode) throws Exception {
    Server localServer = Provisioning.getInstance().getLocalServer();
    String protoHostPort;
    if (admin)
        protoHostPort = "https://localhost:" + localServer.getIntAttr(Provisioning.A_zimbraAdminPort, 0);
    else
        protoHostPort = "http://localhost:" + localServer.getIntAttr(Provisioning.A_zimbraMailPort, 0);
    String url = protoHostPort + wsdlUrl;
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(url);
    try {
        int respCode = HttpClientUtil.executeMethod(client, method);
        int statusCode = method.getStatusCode();
        String statusLine = method.getStatusLine().toString();
        ZimbraLog.test.debug("respCode=" + respCode);
        ZimbraLog.test.debug("statusCode=" + statusCode);
        ZimbraLog.test.debug("statusLine=" + statusLine);
        assertTrue("Response code", respCode == expectedCode);
        assertTrue("Status code", statusCode == expectedCode);
        Header[] respHeaders = method.getResponseHeaders();
        for (int i = 0; i < respHeaders.length; i++) {
            String header = respHeaders[i].toString();
            ZimbraLog.test.debug("ResponseHeader:" + header);
        }
        String respBody = method.getResponseBodyAsString();
        // ZimbraLog.test.debug("Response Body:" + respBody);
        return respBody;
    } catch (HttpException e) {
        fail("Unexpected HttpException" + e);
        throw e;
    } catch (IOException e) {
        fail("Unexpected IOException" + e);
        throw e;
    } finally {
        method.releaseConnection();
    }
}
Also used : Server(com.zimbra.cs.account.Server) Header(org.apache.commons.httpclient.Header) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 72 with Header

use of org.apache.commons.httpclient.Header in project cloudstack by apache.

the class BigSwitchApiTest method testExecuteUpdateObjectFailure.

@Test(expected = BigSwitchBcfApiException.class)
public void testExecuteUpdateObjectFailure() throws BigSwitchBcfApiException, IOException {
    NetworkData network = new NetworkData();
    _method = mock(PutMethod.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);
    when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
    when(_method.isRequestSent()).thenReturn(true);
    try {
        _api.executeUpdateObject(network, "/", Collections.<String, String>emptyMap());
    } finally {
        verify(_method, times(1)).releaseConnection();
    }
}
Also used : Header(org.apache.commons.httpclient.Header) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Test(org.junit.Test)

Example 73 with Header

use of org.apache.commons.httpclient.Header in project cloudstack by apache.

the class BigSwitchApiTest method testExecuteDeleteObjectFailure.

@Test(expected = BigSwitchBcfApiException.class)
public void testExecuteDeleteObjectFailure() throws BigSwitchBcfApiException, IOException {
    _method = mock(DeleteMethod.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);
    when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
    when(_method.isRequestSent()).thenReturn(true);
    try {
        _api.executeDeleteObject("/");
    } finally {
        verify(_method, times(1)).releaseConnection();
    }
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) Header(org.apache.commons.httpclient.Header) Test(org.junit.Test)

Example 74 with Header

use of org.apache.commons.httpclient.Header in project cloudstack by apache.

the class BigSwitchApiTest method testExecuteCreateObjectOK.

@Test
public void testExecuteCreateObjectOK() throws BigSwitchBcfApiException, IOException {
    NetworkData network = new NetworkData();
    _method = mock(PostMethod.class);
    when(_method.getResponseHeader("X-BSN-BVS-HASH-MATCH")).thenReturn(new Header("X-BSN-BVS-HASH-MATCH", UUID.randomUUID().toString()));
    when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
    String hash = _api.executeCreateObject(network, "/", Collections.<String, String>emptyMap());
    verify(_method, times(1)).releaseConnection();
    verify(_client, times(1)).executeMethod(_method);
    assertNotEquals(hash, "");
    assertNotEquals(hash, BigSwitchBcfApi.HASH_CONFLICT);
    assertNotEquals(hash, BigSwitchBcfApi.HASH_IGNORE);
}
Also used : Header(org.apache.commons.httpclient.Header) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Test(org.junit.Test)

Example 75 with Header

use of org.apache.commons.httpclient.Header in project cloudstack by apache.

the class BigSwitchApiTest method testExecuteCreateObjectFailure.

@Test(expected = BigSwitchBcfApiException.class)
public void testExecuteCreateObjectFailure() throws BigSwitchBcfApiException, IOException {
    NetworkData network = new NetworkData();
    _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);
    when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
    when(_method.isRequestSent()).thenReturn(true);
    try {
        _api.executeCreateObject(network, "/", Collections.<String, String>emptyMap());
    } finally {
        verify(_method, times(1)).releaseConnection();
    }
}
Also used : Header(org.apache.commons.httpclient.Header) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Test(org.junit.Test)

Aggregations

Header (org.apache.commons.httpclient.Header)93 GetMethod (org.apache.commons.httpclient.methods.GetMethod)23 Test (org.junit.Test)22 PostMethod (org.apache.commons.httpclient.methods.PostMethod)21 IOException (java.io.IOException)20 HttpClient (org.apache.commons.httpclient.HttpClient)20 NameValuePair (org.apache.commons.httpclient.NameValuePair)18 HttpMethod (org.apache.commons.httpclient.HttpMethod)17 ArrayList (java.util.ArrayList)16 InputStream (java.io.InputStream)14 HttpException (org.apache.commons.httpclient.HttpException)13 PutMethod (org.apache.commons.httpclient.methods.PutMethod)10 Account (com.zimbra.cs.account.Account)9 ServiceException (com.zimbra.common.service.ServiceException)6 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)6 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)6 Pair (com.zimbra.common.util.Pair)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 HashMap (java.util.HashMap)5 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)5