Search in sources :

Example 26 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project incubator-skywalking by apache.

the class StateInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    ServiceManager.INSTANCE.boot();
    stateInterceptor = new StateInterceptor();
    setResponseInterceptor = new SetResponseInterceptor();
    processResponseInterceptor = new ProcessResponseInterceptor();
    PowerMockito.mock(HttpHost.class);
    when(statusLine.getStatusCode()).thenReturn(200);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    when(httpHost.getHostName()).thenReturn("127.0.0.1");
    when(httpHost.getSchemeName()).thenReturn("http");
    when(request.getOriginal()).thenReturn(httpRequest);
    when(httpRequest.getRequestLine()).thenReturn(new RequestLine() {

        @Override
        public String getMethod() {
            return "GET";
        }

        @Override
        public ProtocolVersion getProtocolVersion() {
            return new ProtocolVersion("http", 1, 1);
        }

        @Override
        public String getUri() {
            return "http://127.0.0.1:8080/test-web/httpasync";
        }
    });
    when(httpHost.getPort()).thenReturn(8080);
    allArguments = new Object[] { request };
    argumentsType = new Class[] { request.getClass() };
}
Also used : RequestLine(org.apache.http.RequestLine) Matchers.anyString(org.mockito.Matchers.anyString) ProtocolVersion(org.apache.http.ProtocolVersion) Before(org.junit.Before)

Example 27 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project incubator-skywalking by apache.

the class TestException method setUp.

@Before
public void setUp() throws Exception {
    ServiceManager.INSTANCE.boot();
    stateInterceptor = new StateInterceptor();
    setResponseInterceptor = new SetResponseInterceptor();
    processResponseInterceptor = new ProcessResponseInterceptor();
    PowerMockito.mock(HttpHost.class);
    when(statusLine.getStatusCode()).thenReturn(200);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    when(httpHost.getHostName()).thenReturn("127.0.0.1");
    when(httpHost.getSchemeName()).thenReturn("http");
    when(request.getOriginal()).thenReturn(httpRequest);
    when(httpRequest.getRequestLine()).thenReturn(new RequestLine() {

        @Override
        public String getMethod() {
            return "GET";
        }

        @Override
        public ProtocolVersion getProtocolVersion() {
            return new ProtocolVersion("http", 1, 1);
        }

        @Override
        public String getUri() {
            return "http://127.0.0.1:8080/test-web/httpasync";
        }
    });
    when(httpHost.getPort()).thenReturn(8080);
    allArguments = new Object[] { request };
    setResponseInterceptorArguments = new Object[] { httpResponse };
    argumentsType = new Class[] { request.getClass() };
}
Also used : RequestLine(org.apache.http.RequestLine) Matchers.anyString(org.mockito.Matchers.anyString) ProtocolVersion(org.apache.http.ProtocolVersion) Before(org.junit.Before)

Example 28 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project opencast by opencast.

the class HttpNotificationWorkflowOperationHandlerTest method testNotificationFailedAfterOneTry.

@Test
public void testNotificationFailedAfterOneTry() throws Exception {
    client = EasyMock.createNiceMock(TrustedHttpClient.class);
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_NOT_FOUND, ""));
    EasyMock.expect(client.execute((HttpPut) EasyMock.anyObject(), EasyMock.anyInt(), EasyMock.anyInt())).andReturn(response);
    EasyMock.replay(client);
    // set up service
    operationHandler = new HttpNotificationWorkflowOperationHandler();
    // operation configuration
    Map<String, String> configurations = new HashMap<String, String>();
    configurations.put(HttpNotificationWorkflowOperationHandler.OPT_URL_PATH, "http://127.0.0.1:9");
    configurations.put(HttpNotificationWorkflowOperationHandler.OPT_NOTIFICATION_SUBJECT, "test");
    configurations.put(HttpNotificationWorkflowOperationHandler.OPT_MAX_RETRY, "0");
    configurations.put(HttpNotificationWorkflowOperationHandler.OPT_TIMEOUT, Integer.toString(10));
    // run the operation handler
    try {
        getWorkflowOperationResult(mp, configurations);
        Assert.fail("Operation handler should have thrown an exception!");
    } catch (WorkflowOperationException e) {
        Assert.assertTrue("Exception thrown as expected by the operation handler", true);
    }
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HashMap(java.util.HashMap) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) 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 29 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project ecf by eclipse.

the class HttpClientRetrieveFileTransfer method getResponseCode.

public int getResponseCode() {
    if (responseCode != -1)
        return responseCode;
    ProtocolVersion version = getMethod.getProtocolVersion();
    if (version == null) {
        responseCode = -1;
        httpVersion = 1;
        return responseCode;
    }
    httpVersion = version.getMinor();
    responseCode = httpResponse.getStatusLine().getStatusCode();
    return responseCode;
}
Also used : ProtocolVersion(org.apache.http.ProtocolVersion)

Example 30 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project spring-cloud-netflix by spring-cloud.

the class HttpClientStatusCodeExceptionTest method getResponse.

@Test
public void getResponse() throws Exception {
    CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    doReturn(new Locale("en")).when(response).getLocale();
    Header foo = new BasicHeader("foo", "bar");
    Header[] headers = new Header[] { foo };
    doReturn(headers).when(response).getAllHeaders();
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, "Success");
    doReturn(statusLine).when(response).getStatusLine();
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(new ByteArrayInputStream("foo".getBytes()));
    entity.setContentLength(3);
    doReturn(entity).when(response).getEntity();
    HttpEntity copiedEntity = HttpClientUtils.createEntity(response);
    HttpClientStatusCodeException ex = new HttpClientStatusCodeException("service", response, copiedEntity, new URI("http://service.com"));
    assertEquals("en", ex.getResponse().getLocale().toString());
    assertArrayEquals(headers, ex.getResponse().getAllHeaders());
    assertEquals("Success", ex.getResponse().getStatusLine().getReasonPhrase());
    assertEquals(200, ex.getResponse().getStatusLine().getStatusCode());
    assertEquals("http", ex.getResponse().getStatusLine().getProtocolVersion().getProtocol());
    assertEquals(1, ex.getResponse().getStatusLine().getProtocolVersion().getMajor());
    assertEquals(1, ex.getResponse().getStatusLine().getProtocolVersion().getMinor());
    assertEquals("foo", EntityUtils.toString(ex.getResponse().getEntity()));
    verify(response, times(1)).close();
}
Also used : Locale(java.util.Locale) HttpEntity(org.apache.http.HttpEntity) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) ProtocolVersion(org.apache.http.ProtocolVersion) URI(java.net.URI) BasicStatusLine(org.apache.http.message.BasicStatusLine) BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) ByteArrayInputStream(java.io.ByteArrayInputStream) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Aggregations

ProtocolVersion (org.apache.http.ProtocolVersion)143 BasicStatusLine (org.apache.http.message.BasicStatusLine)67 Test (org.junit.Test)53 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)50 StatusLine (org.apache.http.StatusLine)44 HttpResponse (org.apache.http.HttpResponse)32 HttpEntity (org.apache.http.HttpEntity)31 Header (org.apache.http.Header)25 StringEntity (org.apache.http.entity.StringEntity)25 IOException (java.io.IOException)18 BasicHeader (org.apache.http.message.BasicHeader)15 URL (java.net.URL)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 HttpURLConnection (java.net.HttpURLConnection)13 HashMap (java.util.HashMap)13 List (java.util.List)13 ParseException (org.apache.http.ParseException)13 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)13 HttpHost (org.apache.http.HttpHost)12 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)11