Search in sources :

Example 91 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project TaEmCasa by Dionen.

the class BasicNetworkTest method serverError_enableRetries.

@Test
public void serverError_enableRetries() throws Exception {
    for (int i = 500; i <= 599; i++) {
        MockHttpStack mockHttpStack = new MockHttpStack();
        BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), i, "");
        mockHttpStack.setResponseToReturn(fakeResponse);
        BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack, new ByteArrayPool(4096));
        Request<String> request = buildRequest();
        request.setRetryPolicy(mMockRetryPolicy);
        request.setShouldRetryServerErrors(true);
        doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
        try {
            httpNetwork.performRequest(request);
        } catch (VolleyError e) {
        // expected
        }
        // should retry all 500 errors
        verify(mMockRetryPolicy).retry(any(ServerError.class));
        reset(mMockRetryPolicy);
    }
}
Also used : VolleyError(com.android.volley.VolleyError) MockHttpStack(com.android.volley.mock.MockHttpStack) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ServerError(com.android.volley.ServerError) ProtocolVersion(org.apache.http.ProtocolVersion) Test(org.junit.Test)

Example 92 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project jmeter-plugins-manager by undera.

the class HttpRetryStrategyTest method testFlow.

@Test
public void testFlow() throws Exception {
    HttpRetryStrategy strategy = new HttpRetryStrategy();
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
    assertFalse(strategy.retryRequest(response, 1, null));
    strategy = new HttpRetryStrategy(2, 3333);
    response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, ""));
    assertTrue(strategy.retryRequest(response, 1, null));
    assertFalse(strategy.retryRequest(response, 4, null));
    assertEquals(2, strategy.getMaxRetries());
    assertEquals(3333, strategy.getRetryInterval());
    try {
        new HttpRetryStrategy(-1, 2222);
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals("MaxRetries must be greater than 1", ex.getMessage());
    }
    try {
        new HttpRetryStrategy(2, -1);
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals("Retry interval must be greater than 1", ex.getMessage());
    }
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 93 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project android-uploader by nightscout.

the class RestV1UploaderTest method setUpExecuteCaptor.

public void setUpExecuteCaptor(int status) throws IOException {
    captor = ArgumentCaptor.forClass(HttpUriRequest.class);
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("mock", 1, 2), status, ""));
    response.setEntity(new StringEntity(""));
    when(mockHttpClient.execute(captor.capture())).thenReturn(response);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 94 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project k-9 by k9mail.

the class WebDavStoreTest method createOkPropfindResponse.

// TODO: Replace XML with actual XML from an Exchange server
private BasicHttpResponse createOkPropfindResponse() throws UnsupportedEncodingException {
    BasicHttpResponse okPropfindResponse = createOkResponse();
    HttpEntity propfindResponseEntity = new StringEntity("" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<D:multistatus xmlns:D=\"DAV:\" xmlns:e=\"urn:schemas:httpmail:\">\n" + "  <D:response><e:inbox>http://example.org/Exchange/user/Inbox</e:inbox></D:response>\n" + "</D:multistatus>");
    okPropfindResponse.setEntity(propfindResponseEntity);
    return okPropfindResponse;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpEntity(org.apache.http.HttpEntity) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity)

Example 95 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project k-9 by k9mail.

the class WebDavStoreTest method createOkSearchResponse.

// TODO: Replace XML with actual XML from an Exchange server
private BasicHttpResponse createOkSearchResponse() throws UnsupportedEncodingException {
    BasicHttpResponse okSearchResponse = createOkResponse();
    HttpEntity searchResponseEntity = new StringEntity("" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "   <D:multistatus xmlns:D=\"DAV:\"\n" + "      xmlns:R=\"http://example.org/propschema\">\n" + "     <D:response>" + "       <D:propstat>\n" + "       <uid>Inbox</uid>" + "       <href>http://example.org/Exchange/user/Inbox</href>\n" + "     </D:propstat></D:response>\n" + "     <D:response>" + "       <D:propstat>\n" + "       <uid>Drafts</uid>" + "       <href>http://example.org/Exchange/user/Drafts</href>\n" + "     </D:propstat></D:response>\n" + "     <D:response>" + "       <D:propstat>\n" + "       <uid>Folder2</uid>" + "       <href>http://example.org/Exchange/user/Folder2</href>\n" + "     </D:propstat></D:response>\n" + "   </D:multistatus>");
    okSearchResponse.setEntity(searchResponseEntity);
    return okSearchResponse;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpEntity(org.apache.http.HttpEntity) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity)

Aggregations

BasicHttpResponse (org.apache.http.message.BasicHttpResponse)107 BasicStatusLine (org.apache.http.message.BasicStatusLine)64 ProtocolVersion (org.apache.http.ProtocolVersion)58 HttpResponse (org.apache.http.HttpResponse)51 StatusLine (org.apache.http.StatusLine)39 Test (org.junit.Test)39 StringEntity (org.apache.http.entity.StringEntity)34 IOException (java.io.IOException)33 List (java.util.List)24 Header (org.apache.http.Header)22 HttpHost (org.apache.http.HttpHost)19 HashMap (java.util.HashMap)18 URL (java.net.URL)17 BasicHeader (org.apache.http.message.BasicHeader)17 HttpURLConnection (java.net.HttpURLConnection)16 HttpEntity (org.apache.http.HttpEntity)14 MainResponse (org.elasticsearch.action.main.MainResponse)14 Before (org.junit.Before)13 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)12