org.eclipse.jetty.reactive.client.ReactiveResponse Java Examples

The following examples show how to use org.eclipse.jetty.reactive.client.ReactiveResponse. 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: RxJava2UnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenReactiveClient_whenRequestedWithBody_ShouldReturnBody() throws Exception {

    Request request = httpClient.newRequest(uri());
    ReactiveRequest reactiveRequest = ReactiveRequest.newBuilder(request)
        .content(ReactiveRequest.Content.fromString(CONTENT, MediaType.TEXT_PLAIN_VALUE, UTF_8))
        .build();
    Publisher<String> publisher = reactiveRequest.response(ReactiveResponse.Content.asString());

    String responseContent = Single.fromPublisher(publisher)
        .blockingGet();

    Assert.assertEquals(CONTENT, responseContent);
}
 
Example #2
Source File: RxJava2UnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenReactiveClient_whenRequested_ShouldPrintEvents() throws Exception {
    ReactiveRequest request = ReactiveRequest.newBuilder(httpClient, uri())
        .content(ReactiveRequest.Content.fromString(CONTENT, MediaType.TEXT_PLAIN_VALUE, UTF_8))
        .build();
    Publisher<ReactiveRequest.Event> requestEvents = request.requestEvents();
    Publisher<ReactiveResponse.Event> responseEvents = request.responseEvents();

    List<Type> requestEventTypes = new ArrayList<>();
    List<ReactiveResponse.Event.Type> responseEventTypes = new ArrayList<>();

    Flowable.fromPublisher(requestEvents)
        .map(ReactiveRequest.Event::getType)
        .subscribe(requestEventTypes::add);

    Flowable.fromPublisher(responseEvents)
        .map(ReactiveResponse.Event::getType)
        .subscribe(responseEventTypes::add);

    Single<ReactiveResponse> response = Single.fromPublisher(request.response());
    int actualStatus = response.blockingGet()
        .getStatus();

    Assert.assertEquals(6, requestEventTypes.size());
    Assert.assertEquals(5, responseEventTypes.size());

    Assert.assertEquals(actualStatus, HttpStatus.OK_200);
}
 
Example #3
Source File: JettyClientHttpResponse.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public JettyClientHttpResponse(ReactiveResponse reactiveResponse, Publisher<DataBuffer> content) {
	this.reactiveResponse = reactiveResponse;
	this.content = Flux.from(content);
}
 
Example #4
Source File: JettyClientHttpResponse.java    From java-technology-stack with MIT License 4 votes vote down vote up
public JettyClientHttpResponse(ReactiveResponse reactiveResponse, Publisher<DataBuffer> content) {
	this.reactiveResponse = reactiveResponse;
	this.content = Flux.from(content);
}
 
Example #5
Source File: BlockingSubscriber.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public void onNext(ReactiveResponse response) {
    sink.offer(response);
}
 
Example #6
Source File: BlockingSubscriber.java    From tutorials with MIT License 4 votes vote down vote up
public ReactiveResponse block() throws InterruptedException {
    return sink.poll(5, TimeUnit.SECONDS);
}