package org.bench4q.recorder;

import java.io.IOException;
import java.nio.charset.Charset;

import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.bench4q.recorder.httpcapture.Bench4qTestScriptAdapter;
import org.bench4q.recorder.httpcapture.ProxyServer;
import org.bench4q.recorder.httpcapture.RequestHandler;
import org.bench4q.recorder.httpcapture.generator.Bench4qCodeGenerator;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.junit.Test;

public class Test_RequestHandler {
	private static final int PORT = 8910;

//	@Test
//	public void test() {
//		try {
//			ProxyServer proxyServer = new ProxyServer(PORT);
//			Bench4qCodeGenerator observer = new Bench4qCodeGenerator(
//					new Bench4qTestScriptAdapter(new RunScenarioModel()));
//			proxyServer.addObserver(observer);
//			RequestHandler requestHandler = new RequestHandler(proxyServer,
//					proxyServer.getServerSocket().accept());
//			requestHandler.run();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}
//
//	@Test
//	public void test2() {
//		new SendRequest().run();
//	}
//
//	private static class SendRequest implements Runnable {
//		private HttpClient httpClient = new HttpClient();
//
//		@SuppressWarnings("deprecation")
//		public void run() {
//			HostConfiguration hostConfiguration = new HostConfiguration();
//			hostConfiguration.setProxy("127.0.0.1", PORT);
//			httpClient.setHostConfiguration(hostConfiguration);
////			CustomGetMethod get = new CustomGetMethod("http://www.baidu.com");
//			GetMethod get = new GetMethod("http://www.baidu.com");
//			
//			try {
//				get.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
//				get.addRequestHeader("Accept-Language", "zh-CN,zh;q=0.8");
//				get.addRequestHeader("Cache-Control", "max-age=0");
//				get.addRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
//				get.addRequestHeader("Cookie","__zpspc=188.1.1409195668.1409195668.1%234%7C%7C%7C%7C%7C; BDUSS=E45eXUtamxkY2JUbS12ZjFUSmJPbWdmUU13Ri1ZVHlzWWx2S1B3YXRxRVNUU1pVQVFBQUFBJCQAAAAAAAAAAAEAAAAOfOsxd29uYW5ndW8xMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABLA~lMSwP5Tc; cflag=65535%3A1; BD_UPN=123143; BD_HOME=1; BAIDUID=12B697CB05FD662D2CA4416FF118FCD8:FG=1; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; BD_CK_SAM=1; H_PS_PSSID=8307_5228_1466_7800_8235_8488_8057_6506_6017_8251_7607_7799_8483_8457_8167_8509_8435_8382_8114; BD_HOME=1");
//				
//				int statusCode = this.httpClient.executeMethod(get);
//				System.out.println(statusCode);
//				System.out.println(new String(get.getResponseBody(),Charset.forName("utf-8")));
//			} catch (URIException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			} catch (HttpException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//
//		}
//
//	}
}
