Changeset 32212 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
- Timestamp:
- 2016-06-01T02:41:04+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
r32211 r32212 9 9 import java.io.InputStreamReader; 10 10 import java.io.OutputStream; 11 import java.net.CookieHandler; 11 12 import java.net.HttpURLConnection; 12 13 import java.net.MalformedURLException; 14 import java.net.URISyntaxException; 13 15 import java.net.URL; 14 16 import java.nio.charset.StandardCharsets; 15 17 import java.util.ArrayList; 16 18 import java.util.Date; 19 import java.util.HashMap; 17 20 import java.util.List; 18 21 … … 24 27 import org.openstreetmap.josm.Main; 25 28 import org.openstreetmap.josm.data.coor.EastNorth; 29 import org.openstreetmap.josm.data.validation.util.Entities; 26 30 import org.openstreetmap.josm.gui.layer.Layer; 27 31 import org.openstreetmap.josm.tools.GBC; … … 124 128 } 125 129 success = true; 126 String headerName; 127 for (int i=1; (headerName = urlConn.getHeaderFieldKey(i))!=null; i++) { 128 if (Main.isDebugEnabled()) { 129 Main.debug(headerName + ": " + urlConn.getHeaderField(i)); 130 // See https://bugs.openjdk.java.net/browse/JDK-8036017 131 // When a cookie handler is setup, "Set-Cookie" header returns empty values 132 CookieHandler cookieHandler = CookieHandler.getDefault(); 133 if (cookieHandler != null) { 134 if (handleCookie(cookieHandler.get(searchFormURL.toURI(), new HashMap<String,List<String>>()).get("Cookie").get(0))) { 135 break; 130 136 } 131 if ("Set-Cookie".equals(headerName)) { 132 cookie = urlConn.getHeaderField(i); 133 if (cookie.isEmpty()) { 134 Main.warn("received empty cookie"); 135 cookie = null; 136 } else { 137 cookie = cookie.substring(0, cookie.indexOf(';')); 138 cookieTimestamp = new Date().getTime(); 139 Main.info("received cookie=" + cookie + " at " + new Date(cookieTimestamp)); 137 } else { 138 String headerName; 139 for (int i=1; (headerName = urlConn.getHeaderFieldKey(i))!=null; i++) { 140 if ("Set-Cookie".equals(headerName) && handleCookie(urlConn.getHeaderField(i))) { 140 141 break; 141 } 142 } 142 } 143 } 143 144 } 144 145 } else { … … 148 149 } 149 150 } 150 } catch (MalformedURLException e) {151 } catch (MalformedURLException | URISyntaxException e) { 151 152 throw new IOException("Illegal url.", e); 152 153 } 154 } 155 156 private boolean handleCookie(String pCookie) { 157 cookie = pCookie; 158 if (cookie == null || cookie.isEmpty()) { 159 Main.warn("received empty cookie"); 160 cookie = null; 161 } else { 162 int index = cookie.indexOf(';'); 163 if (index > -1) { 164 cookie = cookie.substring(0, index); 165 } 166 cookieTimestamp = new Date().getTime(); 167 Main.info("received cookie=" + cookie + " at " + new Date(cookieTimestamp)); 168 } 169 return cookie != null; 153 170 } 154 171 … … 320 337 lines = lines.substring(lines.indexOf(C_INTERFACE_VECTOR),lines.length()); 321 338 lines = lines.substring(0, lines.indexOf('\'')); 339 lines = Entities.unescape(lines); 322 340 Main.info("interface ref.:"+lines); 323 341 return lines; … … 335 353 wmsLayer.setCodeCommune(listOfFeuilles.get(res).ref); 336 354 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.get(res).ref); 355 lines = Entities.unescape(lines); 337 356 Main.info("interface ref.:"+lines); 338 357 return lines;
Note:
See TracChangeset
for help on using the changeset viewer.