1 19 20 package com.maverick.http; 21 22 import java.io.IOException ; 23 import java.text.MessageFormat ; 24 import java.util.Enumeration ; 25 26 import com.maverick.ssl.SSLTransportFactory; 27 28 34 public class ConnectMethod extends HttpMethod { 35 36 String hostname; 37 int port; 38 boolean targetIsSecure; 39 HttpMethod toExecute; 40 41 static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(ConnectMethod.class); 43 44 46 public ConnectMethod(String hostname, int port, boolean targetIsSecure, HttpMethod toExecute) { 47 super("CONNECT", hostname + ":" + port); this.hostname = hostname; 49 this.port = port; 50 this.targetIsSecure = targetIsSecure; 51 this.toExecute = toExecute; 52 } 53 54 public ConnectMethod(String hostname, int port, boolean targetIsSecure) { 55 this(hostname, port, targetIsSecure, null); 56 } 57 58 public String getVersion() { 59 return "1.0"; } 61 62 public String getURI() { 63 return hostname + ":" + port; } 65 66 public void processRequest(HttpRequest request) { 67 68 request.setHeaderField("Proxy-Connection", "Keep-Alive"); 70 } 71 72 public HttpResponse execute(HttpRequest request, HttpConnection con) throws IOException { 73 74 HttpResponse response = super.execute(request, con); 75 76 log.info(MessageFormat.format(Messages.getString("ConnectMethod.httpConnect"), new Object [] { hostname, new Integer (port), new Integer (response.getStatus()), response.getReason() })); 79 for (Enumeration e = response.getHeaderFieldNames(); e.hasMoreElements();) { 80 String name = (String ) e.nextElement(); 81 log.info(name + ": " + response.getHeaderField(name)); } 83 85 if (response.getStatus() == 200) { 86 87 if (targetIsSecure) 88 ((SocketWithLayeredTransport) response.getConnection().getSocket()).pushTransport(SSLTransportFactory.newInstance()); 89 90 } 91 92 return response; 93 } 94 95 } 96 | Popular Tags |