org.eclipse.jetty.reactive.client.ReactiveRequest Java Examples
The following examples show how to use
org.eclipse.jetty.reactive.client.ReactiveRequest.
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: JettyClientHttpRequest.java From spring-analysis-note with MIT License | 5 votes |
@Override public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { Flux<ContentChunk> chunks = Flux.from(body).map(this::toContentChunk); ReactiveRequest.Content content = ReactiveRequest.Content.fromPublisher(chunks, getContentType()); this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).content(content).build(); return doCommit(this::completes); }
Example #2
Source File: JettyClientHttpRequest.java From spring-analysis-note with MIT License | 5 votes |
@Override public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) { Flux<ContentChunk> chunks = Flux.from(body) .flatMap(Function.identity()) .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release) .map(this::toContentChunk); ReactiveRequest.Content content = ReactiveRequest.Content.fromPublisher(chunks, getContentType()); this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).content(content).build(); return doCommit(this::completes); }
Example #3
Source File: JettyClientHttpRequest.java From java-technology-stack with MIT License | 5 votes |
@Override public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { Flux<ContentChunk> chunks = Flux.from(body).map(this::toContentChunk); ReactiveRequest.Content content = ReactiveRequest.Content.fromPublisher(chunks, getContentType()); this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).content(content).build(); return doCommit(this::completes); }
Example #4
Source File: JettyClientHttpRequest.java From java-technology-stack with MIT License | 5 votes |
@Override public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) { Flux<ContentChunk> chunks = Flux.from(body) .flatMap(Function.identity()) .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release) .map(this::toContentChunk); ReactiveRequest.Content content = ReactiveRequest.Content.fromPublisher(chunks, getContentType()); this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).content(content).build(); return doCommit(this::completes); }
Example #5
Source File: JettyReactiveHttpClient.java From feign-reactive with Apache License 2.0 | 5 votes |
@Override public Mono<ReactiveHttpResponse> executeRequest(ReactiveHttpRequest request) { Request jettyRequest = httpClient.newRequest(request.uri()).method(request.method()); setUpHeaders(request, jettyRequest.getHeaders()); if(requestTimeout > 0){ jettyRequest.timeout(requestTimeout, TimeUnit.MILLISECONDS); } ReactiveRequest.Builder requestBuilder = ReactiveRequest.newBuilder(jettyRequest); if(bodyActualClass != null){ ReactiveRequest.Content content = provideBody(request); requestBuilder.content(content); jettyRequest.getHeaders().put(CONTENT_TYPE.asString(), singletonList(content.getContentType())); } return Mono.<ReactiveHttpResponse>from(requestBuilder.build().response((response, content) -> Mono.just( new JettyReactiveHttpResponse(response.getResponse(), postProcess(content, (contentChunk, throwable) -> { if(throwable != null){ contentChunk.callback.failed(throwable); } else { contentChunk.callback.succeeded(); } }), returnPublisherClass, returnActualClass, jsonFactory, responseReader)) )).onErrorMap(ex -> ex instanceof java.util.concurrent.TimeoutException, ReadTimeoutException::new); }
Example #6
Source File: JettyReactiveHttpClient.java From feign-reactive with Apache License 2.0 | 5 votes |
protected ReactiveRequest.Content provideBody(ReactiveHttpRequest request) { Publisher<ContentChunk> bodyPublisher; String contentType; if(request.body() instanceof Mono){ if(bodyActualClass == ByteBuffer.class){ bodyPublisher = ((Mono)request.body()).map(this::toByteBufferChunk); contentType = APPLICATION_OCTET_STREAM; } else if(bodyActualClass == byte[].class){ bodyPublisher = Flux.from(request.body()).map(this::toByteArrayChunk); contentType = APPLICATION_OCTET_STREAM; } else if (CharSequence.class.isAssignableFrom(bodyActualClass)){ bodyPublisher = Flux.from(request.body()).map(this::toCharSequenceChunk); contentType = TEXT_UTF_8; } else { bodyPublisher = Flux.from(request.body()).map(data -> toJsonChunk(data, false)); contentType = APPLICATION_JSON_UTF_8; } } else { if(bodyActualClass == ByteBuffer.class){ bodyPublisher = Flux.from(request.body()).map(this::toByteBufferChunk); contentType = APPLICATION_OCTET_STREAM; } else if(bodyActualClass == byte[].class){ bodyPublisher = Flux.from(request.body()).map(this::toByteArrayChunk); contentType = APPLICATION_OCTET_STREAM; } else { bodyPublisher = Flux.from(request.body()).map(data -> toJsonChunk(data, true)); contentType = APPLICATION_STREAM_JSON_UTF_8; } } return ReactiveRequest.Content.fromPublisher(bodyPublisher, contentType); }
Example #7
Source File: RxJava2UnitTest.java From tutorials with MIT License | 5 votes |
@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 #8
Source File: RxJava2UnitTest.java From tutorials with MIT License | 5 votes |
@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 #9
Source File: JettyClientHttpRequest.java From spring-analysis-note with MIT License | 4 votes |
ReactiveRequest getReactiveRequest() { if (this.reactiveRequest == null) { this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).build(); } return this.reactiveRequest; }
Example #10
Source File: JettyClientHttpRequest.java From java-technology-stack with MIT License | 4 votes |
ReactiveRequest getReactiveRequest() { if (this.reactiveRequest == null) { this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).build(); } return this.reactiveRequest; }