Java tutorial
package com.lonepulse.robozombie.executor; /* * #%L * RoboZombie * %% * 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.ClientConnectionManager; 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.tsccm.ThreadSafeClientConnManager; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import com.lonepulse.robozombie.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() { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(params, 2 * 1000); //to simulate a socket timeout SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(manager, params); } }