1 45 package org.exolab.jms.net.http; 46 47 import java.io.IOException ; 48 import java.net.HttpURLConnection ; 49 import java.net.URL ; 50 51 import org.apache.commons.codec.binary.Base64; 52 53 54 60 class TunnelHelper { 61 62 74 public static HttpURLConnection create(URL url, String id, String action, 75 HTTPRequestInfo info) 76 throws IOException { 77 HttpURLConnection connection = 78 (HttpURLConnection ) url.openConnection(); 79 connection.setRequestMethod("POST"); 80 if (id != null) { 81 connection.setRequestProperty("id", id); 82 } 83 connection.setRequestProperty("action", action); 84 connection.setUseCaches(false); 85 if (info.getProxyUser() != null && info.getProxyPassword() != null) { 86 String pwd = info.getProxyUser() + ":" + info.getProxyPassword(); 87 String encoded = new String (Base64.encodeBase64(pwd.getBytes())); 88 connection.setRequestProperty("Proxy-Authorization", 89 "Basic " + encoded); 90 } 91 return connection; 92 } 93 94 108 public static HttpURLConnection connect(URL url, String id, String action, 109 HTTPRequestInfo info) 110 throws IOException { 111 112 HttpURLConnection connection = create(url, id, action, info); 113 connection.setRequestProperty("Content-Length", "0"); 114 connection.connect(); 115 if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { 116 throw new IOException (connection.getResponseCode() + " " 117 + connection.getResponseMessage()); 118 } 119 return connection; 120 } 121 } 122 | Popular Tags |