01: package com.xoetrope.carousel.testpilot;
02:
03: import java.io.*;
04: import java.net.*;
05:
06: /**
07: * Support for ???
08: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
09: * the GNU Public License (GPL), please see license.txt for more details. If
10: * you make commercial use of this software you must purchase a commercial
11: * license from Xoetrope.</p>
12: * <p> $Revision: 1.2 $</p>
13: */
14: public class Proxy extends Thread {
15:
16: ServerSocket serverSocket;
17:
18: public Proxy() {
19: try {
20: System.out.println("proxySet"
21: + System.getProperties().get("proxySet"));
22: System.out.println("proxyHost"
23: + System.getProperties().get("proxyHost"));
24: System.out.println("proxyPort"
25: + System.getProperties().get("proxyPort"));
26:
27: System.getProperties().put("proxySet", "false");
28: // System.getProperties().put( "proxyHost", "localhost" );
29: // System.getProperties().put( "proxyPort", "8001" );
30:
31: serverSocket = new ServerSocket(8001);
32: start();
33: } catch (IOException ex) {
34: ex.printStackTrace();
35: }
36: }
37:
38: public void run() {
39: try {
40: Socket socket = null;
41: try {
42: socket = (Socket) serverSocket.accept();
43: } catch (Exception ex) {
44: ex.printStackTrace();
45: }
46: while (true) {
47: BufferedReader in = new BufferedReader(
48: new InputStreamReader(socket.getInputStream()));
49: String inputLine, outputLine;
50:
51: inputLine = in.readLine();
52: byte b[] = getData(inputLine);
53: socket.getOutputStream().write(b);
54: }
55: } catch (IOException e) {
56: e.printStackTrace();
57: }
58: }
59:
60: private byte[] getData(String src) {
61: src = src.substring(4);
62: src = src.substring(0, src.indexOf("HTTP"));
63: try {
64: URL url = new URL(src);
65:
66: URLConnection conn = url.openConnection();
67: conn.connect();
68: BufferedInputStream bis = new BufferedInputStream(conn
69: .getInputStream());
70: byte b[] = new byte[conn.getContentLength()];
71: bis.read(b);
72: return b;
73: } catch (IOException ex) {
74: ex.printStackTrace();
75: }
76: return null;
77: }
78: }
|