Java Code Examples for org.eclipse.jetty.client.api.Response#CompleteListener

The following examples show how to use org.eclipse.jetty.client.api.Response#CompleteListener . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncHttpExecutableTest.java    From cougar with Apache License 2.0 6 votes vote down vote up
private void fireResponse(CapturingRequest request, int errorCode, String responseText, int resultSize, ObservableObserver observer, boolean successfulResponse) throws InterruptedException {
    Response.CompleteListener listener = request.awaitSend(1000, TimeUnit.MILLISECONDS);
    assertNotNull(listener);
    InputStreamResponseListener responseListener = (InputStreamResponseListener) listener;

    Result result = mock(Result.class);
    Response response = mock(Response.class);
    when(result.getResponse()).thenReturn(response);
    when(result.isSucceeded()).thenReturn(successfulResponse);
    when(result.isFailed()).thenReturn(!successfulResponse);
    HttpFields headers = mock(HttpFields.class);
    when(response.getHeaders()).thenReturn(headers);
    when(headers.get(HttpHeader.CONTENT_LENGTH)).thenReturn(String.valueOf(resultSize));
    when(response.getStatus()).thenReturn(errorCode);
    when(response.getVersion()).thenReturn(HttpVersion.HTTP_1_1);

    // fire that event
    responseListener.onHeaders(response);
    responseListener.onContent(response, ByteBuffer.allocate(0));
    responseListener.onComplete(result);

    assertTrue(observer.getLatch().await(1000, TimeUnit.MILLISECONDS));
}
 
Example 2
Source File: CapturingRequest.java    From cougar with Apache License 2.0 4 votes vote down vote up
@Override
public Request onComplete(Response.CompleteListener listener) {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
}
 
Example 3
Source File: CapturingRequest.java    From cougar with Apache License 2.0 4 votes vote down vote up
@Override
public void send(Response.CompleteListener listener) {
    completeListener.set(listener);
    sendLatch.countDown();

}
 
Example 4
Source File: CapturingRequest.java    From cougar with Apache License 2.0 4 votes vote down vote up
public Response.CompleteListener awaitSend(long time, TimeUnit unit) throws InterruptedException {
    if (sendLatch.await(time, unit)) {
        return completeListener.get();
    }
    return null;
}