Rev 1310 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1310 | Rev 1484 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.estgweb.web; |
1 | package pt.estgp.estgweb.web; |
2 | 2 | ||
3 | import jomm.utils.StreamsUtils; |
- | |
4 | import org.apache.commons.httpclient.URIException; |
3 | import org.apache.commons.httpclient.URIException; |
5 | import org.apache.commons.httpclient.util.URIUtil; |
4 | import org.apache.commons.httpclient.util.URIUtil; |
6 | import org.apache.log4j.Logger; |
5 | import org.apache.log4j.Logger; |
7 | import pt.estgp.estgweb.utils.ConfigProperties; |
6 | import pt.estgp.estgweb.utils.ConfigProperties; |
8 | import pt.estgp.estgweb.utils.StringsUtils; |
- | |
9 | 7 | ||
10 | import javax.servlet.ServletException; |
8 | import javax.servlet.ServletException; |
11 | import javax.servlet.http.HttpServlet; |
9 | import javax.servlet.http.HttpServlet; |
12 | import javax.servlet.http.HttpServletRequest; |
10 | import javax.servlet.http.HttpServletRequest; |
13 | import javax.servlet.http.HttpServletResponse; |
11 | import javax.servlet.http.HttpServletResponse; |
Line 16... | Line 14... | ||
16 | import java.io.IOException; |
14 | import java.io.IOException; |
17 | import java.io.InputStream; |
15 | import java.io.InputStream; |
18 | import java.io.OutputStream; |
16 | import java.io.OutputStream; |
19 | import java.net.*; |
17 | import java.net.*; |
20 | import java.util.Date; |
18 | import java.util.Date; |
21 | import java.util.zip.ZipInputStream; |
19 | import java.util.HashMap; |
22 | import java.util.zip.InflaterInputStream; |
20 | import java.util.Map; |
23 | import java.util.zip.GZIPInputStream; |
21 | import java.util.zip.GZIPInputStream; |
- | 22 | import java.util.zip.InflaterInputStream; |
|
- | 23 | import java.util.zip.ZipInputStream; |
|
24 | 24 | ||
25 | /** |
25 | /** |
26 | * @author Jorge Machado |
26 | * @author Jorge Machado |
27 | * @date 26/Fev/2008 |
27 | * @date 26/Fev/2008 |
28 | * @time 12:46:16 |
28 | * @time 12:46:16 |
Line 195... | Line 195... | ||
195 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/javax/print/URIException.html">URIException { |
195 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/javax/print/URIException.html">URIException { |
196 | 1.5.0/docs/api/java/lang/String.html">String path = "pagina.php?id=asdasd&jj=kk"; |
196 | 1.5.0/docs/api/java/lang/String.html">String path = "pagina.php?id=asdasd&jj=kk"; |
197 | 1.5.0/docs/api/java/lang/String.html">String pathFinal = path.indexOf("?") >=0 ? URIUtil.encodePath(path.substring(0,path.indexOf("?")), "ISO-8859-1") + "?" +path.substring(path.indexOf("?")+1) : path; |
197 | 1.5.0/docs/api/java/lang/String.html">String pathFinal = path.indexOf("?") >=0 ? URIUtil.encodePath(path.substring(0,path.indexOf("?")), "ISO-8859-1") + "?" +path.substring(path.indexOf("?")+1) : path; |
198 | 1.5.0/docs/api/java/lang/System.html">System.out.println(pathFinal); |
198 | 1.5.0/docs/api/java/lang/System.html">System.out.println(pathFinal); |
199 | } |
199 | } |
- | 200 | ||
- | 201 | static Map<String,Boolean> urlOKCACHE = new HashMap<String, Boolean>(); |
|
- | 202 | static Map<String,Integer> urlOKCACHE_LAST_CHECK_COUNT = new HashMap<String, Integer>(); |
|
- | 203 | ||
200 | public static boolean checkExist( 1.5.0/docs/api/java/lang/String.html">String server, 1.5.0/docs/api/java/lang/String.html">String path) |
204 | public static boolean checkExist( 1.5.0/docs/api/java/lang/String.html">String server, 1.5.0/docs/api/java/lang/String.html">String path) |
201 | { |
205 | { |
- | 206 | 1.5.0/docs/api/java/lang/String.html">String serverPathKey = server + "$" + path; |
|
- | 207 | 1.5.0/docs/api/java/lang/Boolean.html">Boolean urlOk = urlOKCACHE.get(serverPathKey); |
|
- | 208 | if(urlOk != null) |
|
- | 209 | { |
|
- | 210 | int count = urlOKCACHE_LAST_CHECK_COUNT.get(serverPathKey); |
|
- | 211 | if(count > 0) |
|
- | 212 | { |
|
- | 213 | count = count-1; |
|
- | 214 | urlOKCACHE_LAST_CHECK_COUNT.put(serverPathKey,count); |
|
- | 215 | return urlOk; |
|
- | 216 | } |
|
- | 217 | } |
|
202 | 218 | ||
203 | 1.5.0/docs/api/java/lang/String.html">String serverUrl = ConfigProperties.getProperty("server." + server); |
219 | 1.5.0/docs/api/java/lang/String.html">String serverUrl = ConfigProperties.getProperty("server." + server); |
204 | 1.5.0/docs/api/java/lang/String.html">String serverEncoding = ConfigProperties.getProperty(server + ".encoding"); |
220 | 1.5.0/docs/api/java/lang/String.html">String serverEncoding = ConfigProperties.getProperty(server + ".encoding"); |
205 | 1.5.0/docs/api/java/lang/String.html">String confStartPath = ConfigProperties.getProperty("server." + server + ".start.path"); |
221 | 1.5.0/docs/api/java/lang/String.html">String confStartPath = ConfigProperties.getProperty("server." + server + ".start.path"); |
206 | if (confStartPath != null) |
222 | if (confStartPath != null) |
Line 208... | Line 224... | ||
208 | 224 | ||
209 | 225 | ||
210 | try |
226 | try |
211 | { |
227 | { |
212 | 228 | ||
213 | 1.5.0/docs/api/java/lang/String.html">String pathFinal = path.indexOf("?") >=0 ? URIUtil.encodePath(path.substring(0,path.indexOf("?")), "ISO-8859-1") + path.substring(path.indexOf("?")) : path; |
229 | 1.5.0/docs/api/java/lang/String.html">String pathFinal = path.indexOf("?") >= 0 ? URIUtil.encodePath(path.substring(0,path.indexOf("?")), "ISO-8859-1") + path.substring(path.indexOf("?")) : path; |
214 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Getting: " + serverUrl + pathFinal); |
- | |
215 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(serverUrl + pathFinal); |
- | |
216 | - | ||
217 | 230 | ||
218 | 1.5.0/docs/api/java/net/URLConnection.html">URLConnection con = url.openConnection(); |
- | |
219 | 5+0%2Fdocs%2Fapi+InputStream">InputStream stream = con.getInputStream(); |
- | |
220 | 1.5.0/docs/api/java/lang/String.html">String out = StreamsUtils.readString(stream); |
- | |
221 | stream.close(); |
- | |
222 | 231 | ||
- | 232 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Getting: " + serverUrl + pathFinal + " CHECK TIME"); |
|
- | 233 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(serverUrl + pathFinal); |
|
- | 234 | 1.5.0/docs/api/java/net/HttpURLConnection.html">HttpURLConnection huc = (1.5.0/docs/api/java/net/HttpURLConnection.html">HttpURLConnection) url.openConnection(); |
|
- | 235 | huc.setRequestMethod("HEAD"); |
|
- | 236 | urlOKCACHE_LAST_CHECK_COUNT.put(serverPathKey,10); |
|
- | 237 | if(huc.getResponseCode() == 1.5.0/docs/api/java/net/HttpURLConnection.html">HttpURLConnection.HTTP_OK) |
|
- | 238 | { |
|
- | 239 | urlOKCACHE.put(serverPathKey,true); |
|
223 | if(out.trim().length() == 0) |
240 | huc.disconnect(); |
- | 241 | return true; |
|
- | 242 | } |
|
- | 243 | else |
|
- | 244 | { |
|
- | 245 | urlOKCACHE.put(serverPathKey,false); |
|
- | 246 | huc.disconnect(); |
|
224 | return false; |
247 | return false; |
225 | return true; |
248 | } |
- | 249 | ||
226 | } |
250 | } |
227 | catch (1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException e) |
251 | catch (1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException e) |
228 | { |
252 | { |
229 | return false; |
253 | return false; |
230 | } |
254 | } |