1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   |  
/**
	 * @param pUrl
	 * @return
	 * Send an Http request (used to invoke the billing url)
	 */
	public static String sendRequest(String pUrl) {
		InputStream is = null;
 
		InputStreamReader  reader = null;
		Charset charset = Charset.forName("UTF-8");
		URL url = null;     
		int readTimeOut = 10000 ;
		String content=null;
		try {
            Properties p = System.getProperties();
 
            p.put("sun.net.client.defaultConnectTimeout",Integer.toString(readTimeOut));
            p.put("sun.net.client.defaultReadTimeout",Integer.toString(readTimeOut));
 
           System.setProperties(p);
 
            url = new URL(pUrl);
 
            is = url.openStream();   
            reader = new InputStreamReader(is, charset); 
            content = ReadContent(reader);
	    }
	    catch (Exception e) {
		      logExtErrors.error(e.getMessage());
		      logExtErrors.error(e.getStackTrace());
 
	    }
	    finally{
	    	 try {
               if(is!=null)
            	   is.close();
 
              if(reader!=null)
                 reader.close();
             }catch (IOException e1) {}
 
		}
 
		return content;
	}
 
 
	private static String ReadContent(InputStreamReader reader)
	{
		BufferedReader in = null;
		StringBuffer strBuf = new StringBuffer();
		try
		{
			in = new BufferedReader (reader);
			String line;
			while ((line = in.readLine()) != null) {
				strBuf.append(line);
				strBuf.append("\n");
			}
		}catch (IOException e){e.printStackTrace();}
 
		String content = null;
		if (in != null)
			content = strBuf.toString();
 
		return(content);
 
	} | 
Partager