1 24 package org.objectweb.clif.isac.plugins.httpinjector10.tools; 25 26 import java.net.InetAddress ; 27 import java.net.MalformedURLException ; 28 import java.net.UnknownHostException ; 29 import java.util.Hashtable ; 30 31 import org.apache.commons.httpclient.HostConfiguration; 32 import org.apache.commons.httpclient.protocol.Protocol; 33 import org.objectweb.clif.isac.plugins.httpinjector10.SessionObject; 34 import org.objectweb.clif.scenario.util.isac.engine.IsacScenarioEngine; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 import org.objectweb.util.monolog.api.Logger; 37 38 import com.sun.jndi.toolkit.url.Uri; 39 40 47 public class HostConfigurationUtils { 48 49 static protected Logger log = IsacScenarioEngine.logger 50 .getLogger(HostConfigurationUtils.class.getName()); 51 52 66 public static HostConfiguration setHostConfiguration( 67 SessionObject sessionObject, Hashtable params) 68 throws MalformedURLException { 69 log.log(BasicLevel.DEBUG, "-> [Enter] setHostConfiguration"); 70 HostConfiguration hostConfiguration = new HostConfiguration(); 71 String proxyHost = (String ) params.get(ParametersConstantes.PROXYHOST); 72 String proxyPort = (String ) params.get(ParametersConstantes.PROXYPORT); 73 String localAddress = (String ) params 74 .get(ParametersConstantes.LOCALADDRESS); 75 76 Uri uri = new Uri((String ) params.get(ParametersConstantes.URI)); 77 String schema = uri.getScheme(); 78 Protocol protocol = Protocol.getProtocol(schema); 79 String host = uri.getHost(); 80 int port = uri.getPort(); 81 hostConfiguration.setHost(host,localAddress, port, protocol); 82 84 if (proxyHost != null && !proxyHost.equals("")) { 86 int defaultProxyPort = (proxyPort != null && !proxyPort.equals("")) 87 ? new Integer (proxyPort).intValue() 88 : ParametersConstantes.PROXYDEFAULTPORT; 89 log.log(BasicLevel.DEBUG, "Set a proxy : " + proxyHost + " : " 90 + proxyPort); 91 hostConfiguration.setProxy(proxyHost, new Integer (proxyPort) 92 .intValue()); 93 } else { 94 String defaultProxyHost = sessionObject.getProxyHost(); 96 String defaultProxyPort = sessionObject.getProxyPort(); 97 if (defaultProxyHost != null && !defaultProxyHost.equals("") 98 && defaultProxyPort != null && !defaultProxyPort.equals("")) 99 hostConfiguration.setProxy(defaultProxyHost, new Integer ( 100 defaultProxyPort).intValue()); 101 } 102 if (localAddress != null && !localAddress.equals("")) { 104 InetAddress inetAddress; 105 try { 106 inetAddress = InetAddress.getByName(localAddress); 107 hostConfiguration.setLocalAddress(inetAddress); 108 } catch (UnknownHostException e) { 109 e.printStackTrace(); 110 } 111 } 112 log.log(BasicLevel.DEBUG, "<- [Exit] setHostConfiguration"); 113 return hostConfiguration; 114 } 115 116 } | Popular Tags |