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

stalkr.http.DefaultRequestFactory Maven / Gradle / Ivy

package stalkr.http;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.inject.Singleton;

import lombok.Getter;
import lombok.val;
import lombok.experimental.Accessors;

import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.AsyncHttpClientConfig.Builder;

@Getter
@Accessors( fluent = true )
@Singleton
public class DefaultRequestFactory extends Requests {

	final AsyncHttpClient client = configureClient();
	final StoredContext storedContext = null;
	final ExecutorService executor = Executors.newCachedThreadPool();

	AsyncHttpClient configureClient() {
		val config = createHttpClientConfig();
		return new AsyncHttpClient( config );
	}

	AsyncHttpClientConfig createHttpClientConfig() {
		return new Builder()
			.setCompressionEnabled( true )
			.setAllowPoolingConnection( true )
			.setExecutorService( executor )
			.setRequestTimeoutInMs( 30000 )
			.build();
	}

	@Override
	protected ListenableRequestBuilder builder() {
		val requests = new ContextualRequests( client, executor, new CookieStoredContext() );
		return new ListenableRequestBuilder( requests );
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy