All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.king.platform.net.http.netty.requestbuilder.HttpClientSseRequestBuilderImpl Maven / Gradle / Ivy

There is a newer version: 3.0.26
Show newest version
// Copyright (C) king.com Ltd 2016
// https://github.com/king/king-http-client
// Author: Magnus Gustafsson
// License: Apache 2.0, https://raw.github.com/king/king-http-client/LICENSE-APACHE

package com.king.platform.net.http.netty.requestbuilder;


import com.king.platform.net.http.BuiltSseClientRequest;
import com.king.platform.net.http.HttpClientSseRequestBuilder;
import com.king.platform.net.http.SseClient;
import com.king.platform.net.http.SseClientCallback;
import com.king.platform.net.http.netty.ConfMap;
import com.king.platform.net.http.netty.HttpClientCaller;
import com.king.platform.net.http.netty.ServerInfoValidator;
import com.king.platform.net.http.netty.sse.SseClientImpl;
import com.king.platform.net.http.netty.sse.VoidResponseConsumer;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpVersion;

import java.util.concurrent.Executor;

public class HttpClientSseRequestBuilderImpl extends HttpClientRequestHeaderBuilderImpl implements HttpClientSseRequestBuilder {
	public HttpClientSseRequestBuilderImpl(HttpClientCaller httpClientCaller, String uri, ConfMap confMap,
										   Executor callbackExecutor) {
		super(HttpClientSseRequestBuilder.class, httpClientCaller, HttpVersion.HTTP_1_1, HttpMethod.GET, uri, confMap, callbackExecutor);
	}

	@Override
	public BuiltSseClientRequest build() {

		addHeader("Accept", "text/event-stream");

		final BuiltNettyClientRequest builtNettyClientRequest = new BuiltNettyClientRequest<>(httpClientCaller, httpVersion, httpMethod, uri, defaultUserAgent,
			idleTimeoutMillis, totalRequestTimeoutMillis, followRedirects, acceptCompressedResponse, keepAlive, automaticallyDecompressResponse, null, null, null, queryParameters,
			headerParameters, callbackExecutor, VoidResponseConsumer::new, null, ServerInfoValidator.HTTP);


		return new BuiltSseClientRequest() {
			@Override
			public SseClient execute(SseClientCallback providedSseExecutionCallback) {
				SseClientImpl sseClient = new SseClientImpl(providedSseExecutionCallback, builtNettyClientRequest, callbackExecutor);
				sseClient.connect();
				return sseClient;
			}

			@Override
			public SseClient execute() {
				SseClientImpl sseClient = new SseClientImpl(null, builtNettyClientRequest, callbackExecutor);
				sseClient.connect();
				return sseClient;
			}

			@Override
			public SseClient build() {
				return new SseClientImpl(null, builtNettyClientRequest, callbackExecutor);
			}
		};

	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy