1,11 → 1,9 |
package pt.estgp.estgweb.web; |
|
import jomm.utils.StreamsUtils; |
import org.apache.commons.httpclient.URIException; |
import org.apache.commons.httpclient.util.URIUtil; |
import org.apache.log4j.Logger; |
import pt.estgp.estgweb.utils.ConfigProperties; |
import pt.estgp.estgweb.utils.StringsUtils; |
|
import javax.servlet.ServletException; |
import javax.servlet.http.HttpServlet; |
18,9 → 16,11 |
import java.io.OutputStream; |
import java.net.*; |
import java.util.Date; |
import java.util.HashMap; |
import java.util.Map; |
import java.util.zip.GZIPInputStream; |
import java.util.zip.InflaterInputStream; |
import java.util.zip.ZipInputStream; |
import java.util.zip.InflaterInputStream; |
import java.util.zip.GZIPInputStream; |
|
/** |
* @author Jorge Machado |
197,8 → 197,24 |
String pathFinal = path.indexOf("?") >=0 ? URIUtil.encodePath(path.substring(0,path.indexOf("?")), "ISO-8859-1") + "?" +path.substring(path.indexOf("?")+1) : path; |
System.out.println(pathFinal); |
} |
|
static Map<String,Boolean> urlOKCACHE = new HashMap<String, Boolean>(); |
static Map<String,Integer> urlOKCACHE_LAST_CHECK_COUNT = new HashMap<String, Integer>(); |
|
public static boolean checkExist( String server, String path) |
{ |
String serverPathKey = server + "$" + path; |
Boolean urlOk = urlOKCACHE.get(serverPathKey); |
if(urlOk != null) |
{ |
int count = urlOKCACHE_LAST_CHECK_COUNT.get(serverPathKey); |
if(count > 0) |
{ |
count = count-1; |
urlOKCACHE_LAST_CHECK_COUNT.put(serverPathKey,count); |
return urlOk; |
} |
} |
|
String serverUrl = ConfigProperties.getProperty("server." + server); |
String serverEncoding = ConfigProperties.getProperty(server + ".encoding"); |
210,19 → 226,27 |
try |
{ |
|
String pathFinal = path.indexOf("?") >=0 ? URIUtil.encodePath(path.substring(0,path.indexOf("?")), "ISO-8859-1") + path.substring(path.indexOf("?")) : path; |
System.out.println("Getting: " + serverUrl + pathFinal); |
URL url = new URL(serverUrl + pathFinal); |
String pathFinal = path.indexOf("?") >= 0 ? URIUtil.encodePath(path.substring(0,path.indexOf("?")), "ISO-8859-1") + path.substring(path.indexOf("?")) : path; |
|
|
URLConnection con = url.openConnection(); |
InputStream stream = con.getInputStream(); |
String out = StreamsUtils.readString(stream); |
stream.close(); |
System.out.println("Getting: " + serverUrl + pathFinal + " CHECK TIME"); |
URL url = new URL(serverUrl + pathFinal); |
HttpURLConnection huc = (HttpURLConnection) url.openConnection(); |
huc.setRequestMethod("HEAD"); |
urlOKCACHE_LAST_CHECK_COUNT.put(serverPathKey,10); |
if(huc.getResponseCode() == HttpURLConnection.HTTP_OK) |
{ |
urlOKCACHE.put(serverPathKey,true); |
huc.disconnect(); |
return true; |
} |
else |
{ |
urlOKCACHE.put(serverPathKey,false); |
huc.disconnect(); |
return false; |
} |
|
if(out.trim().length() == 0) |
return false; |
return true; |
} |
catch (FileNotFoundException e) |
{ |