2012年5月2日星期三

set http proxy on httpclient4

//proxy
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("conf/system.properties");
       Properties properties = new Properties(); 
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            logger.debug("load system.properties failure...");
        } 
        String r=properties.getProperty("crawlNode.httpProxy", "none").toLowerCase().trim();
        if (!r.equals("none")){
            String[] arr=StringUtils.split(r, ":");
            int port=80;
            String url=r;
            if (arr.length==2)
            {
                port=Integer.parseInt(arr[1]);
                url=arr[0].trim();
            }
            HttpHost proxy = new HttpHost(url, port);
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            logger.debug("start using http proxy {}:{}",url,port);
           
        }

没有评论:

发表评论