package de.quaddy_services.proxy;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.URL;
import java.net.URLConnection;

/**
 *
 */
public class ProxyTestApp {

	public static void main(String[] args) throws IOException {
		new ProxyTestApp().testHttpGoogle();
		new ProxyTestApp().testHttpsGoogle();
	}

	public void testHttpGoogle() throws IOException {
		String tempHttp = "http://www.google.com";
		readViaProxy(tempHttp);

	}

	public void testHttpsGoogle() throws IOException {
		String tempHttp = "https://www.google.com";
		readViaProxy(tempHttp);

	}

	/**
	 *
	 */
	private void readViaProxy(String tempHttp) throws MalformedURLException, IOException {
		System.out.println();
		System.out.println(tempHttp);
		System.out.println();

		URL tempUrl = new URL(tempHttp);

		Proxy tempProxy = new Proxy(Type.HTTP, new InetSocketAddress(3128));
		URLConnection tempConnection = tempUrl.openConnection(tempProxy);

		tempConnection.setConnectTimeout(30000);
		tempConnection.setReadTimeout(30000);

		InputStream in = tempConnection.getInputStream();

		byte[] tempB = new byte[1000];
		int tempRead = in.read(tempB);
		if (tempRead > 0) {
			System.out.println("Result=" + new String(tempB, 0, tempRead));
			while (tempRead>0) {
				tempRead = in.read(tempB);
				System.out.println("Read another " + tempRead+" bytes");
			}
		}

		in.close();
	}

}

@@ -88,16 +88,52 @@
 tream;%0D%0A
+import java.net.HttpURLConnection;%0D%0A
 import j
@@ -1074,16 +1074,20 @@
 8));%0D%0A%09%09
+Http
 URLConne
@@ -1108,16 +1108,36 @@
 ection =
+ (HttpURLConnection)
  tempUrl
@@ -1268,16 +1268,34 @@
 tStream 
+in;%0D%0A%09%09try %7B%0D%0A%09%09%09 
 in = tem
@@ -1320,24 +1320,229 @@
 utStream();%0D
+%0A%09%09%7D catch (IOException e) %7B%0D%0A%09%09%09System.err.println(%22ResponseCode=%22 + tempConnection.getResponseCode());%0D%0A%09%09%09System.err.println(%22ResponseMessage=%22 + tempConnection.getResponseMessage());%0D%0A%09%09%09throw e;%0D%0A%09%09%7D%0D
 %0A%0D%0A%09%09byte%5B%5D 
@@ -1600,16 +1600,45 @@
 empB);%0D%0A
+%09%09int tempTotal = tempRead;%0D%0A
 %09%09if (te
@@ -1738,17 +1738,19 @@
 tempRead
-%3E
+ %3E 
 0) %7B%0D%0A%09%09
@@ -1779,16 +1779,42 @@
 empB);%0D%0A
+%09%09%09%09tempTotal+=tempRead;%0D%0A
 %09%09%09%09Syst
@@ -1854,17 +1854,19 @@
 tempRead
-+
+ + 
 %22 bytes%22
@@ -1876,24 +1876,65 @@
 %0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A
+%09%09System.out.println(%22Total=%22+tempTotal);
 %0D%0A%09%09in.close

add infos