com.lonepulse.zombielink.executor.ZombieConfig.java Source code

Java tutorial

Introduction

Here is the source code for com.lonepulse.zombielink.executor.ZombieConfig.java

Source

package com.lonepulse.zombielink.executor;

/*
 * #%L
 * ZombieLink
 * %%
 * Copyright (C) 2013 - 2014 Lonepulse
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import org.apache.http.client.HttpClient;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import com.lonepulse.zombielink.proxy.Zombie;

/**
 * <p>An implementation of {@link Zombie.Configuration} which configures a custom {@link HttpClient} 
 * to be used for executing requests with {@link ConfigEndpoint}.</p> 
 * 
 * @version 1.1.0
 * <br><br>
 * @since 1.3.0
 * <br><br>
 * @category test
 * <br><br> 
 * @author <a href="http://sahan.me">Lahiru Sahan Jayasinghe</a>
 */
public class ZombieConfig extends Zombie.Configuration {

    @Override
    public HttpClient httpClient() {

        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));

        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setSoTimeout(params, 2 * 1000); //to simulate a socket timeout

        return new DefaultHttpClient(new PoolingClientConnectionManager(schemeRegistry), params);
    }
}