Changeset 32556 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
- Timestamp:
- 2016-07-04T14:18:17+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
r32425 r32556 1 // License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others1 // License: GPL. For details, see LICENSE file. 2 2 package cadastre_fr; 3 3 … … 49 49 } 50 50 } 51 51 52 private List<PlanImage> listOfFeuilles = new ArrayList<>(); 52 53 private long cookieTimestamp; … … 109 110 * @return true if a cookie is delivered by WMS and false is WMS is not opening a client session 110 111 * (too many clients or in maintenance) 111 * @throws IOException112 112 */ 113 113 private void getCookie() throws IOException { … … 117 117 searchFormURL = new URL(BASE_URL + "/scpc/accueil.do"); 118 118 while (!success && retries > 0) { 119 urlConn = (HttpURLConnection)searchFormURL.openConnection(); 119 urlConn = (HttpURLConnection) searchFormURL.openConnection(); 120 120 urlConn.setRequestProperty("Connection", "close"); 121 121 urlConn.setRequestMethod("GET"); … … 124 124 Main.info("GET "+searchFormURL); 125 125 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8)); 126 while(in.readLine() != null) { 126 while (in.readLine() != null) { 127 127 // read the buffer otherwise we sent POST too early 128 128 } … … 132 132 CookieHandler cookieHandler = CookieHandler.getDefault(); 133 133 if (cookieHandler != null) { 134 if (handleCookie(cookieHandler.get(searchFormURL.toURI(), new HashMap<String,List<String>>()).get("Cookie").get(0))) { 134 if (handleCookie(cookieHandler.get(searchFormURL.toURI(), new HashMap<String, List<String>>()).get("Cookie").get(0))) { 135 135 break; 136 136 } 137 137 } else { 138 138 String headerName; 139 for (int i =1; (headerName = urlConn.getHeaderFieldKey(i))!=null; i++) {139 for (int i = 1; (headerName = urlConn.getHeaderFieldKey(i)) != null; i++) { 140 140 if ("Set-Cookie".equals(headerName) && handleCookie(urlConn.getHeaderField(i))) { 141 141 break; 142 } 142 } 143 143 } 144 144 } … … 146 146 Main.warn("Request to home page failed. Http error:"+urlConn.getResponseCode()+". Try again "+retries+" times"); 147 147 CadastrePlugin.safeSleep(3000); 148 retries --;148 retries--; 149 149 } 150 150 } … … 238 238 } 239 239 240 private void openInterface() throws IOException {240 private void openInterface() throws IOException { 241 241 try { 242 242 // finally, open the interface on server side giving access to the wms server 243 243 URL interfaceURL = new URL(BASE_URL + "/scpc/"+interfaceRef); 244 urlConn = (HttpURLConnection)interfaceURL.openConnection(); 244 urlConn = (HttpURLConnection) interfaceURL.openConnection(); 245 245 urlConn.setRequestMethod("GET"); 246 246 setCookie(); … … 283 283 * where QP224 is the code commune known by the WMS (or "afficherCarteTa.do?c=..." for raster images). 284 284 * 285 * @param location286 * @param codeCommune287 285 * @return retURL url to available code commune in the cadastre; "" if not found 288 * @throws IOException289 286 */ 290 287 private String postForm(WMSLayer wmsLayer, String codeCommune) throws IOException { … … 308 305 content += "&x=0&y=0"; 309 306 searchFormURL = new URL(BASE_URL + "/scpc/rechercherPlan.do"); 310 urlConn = (HttpURLConnection)searchFormURL.openConnection(); 307 urlConn = (HttpURLConnection) searchFormURL.openConnection(); 311 308 urlConn.setRequestMethod("POST"); 312 309 urlConn.setDoOutput(true); … … 335 332 if (!wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_VECTOR) != -1) { // "afficherCarteCommune.do" 336 333 // shall be something like: interfaceRef = "afficherCarteCommune.do?c=X2269"; 337 lines = lines.substring(lines.indexOf(C_INTERFACE_VECTOR),lines.length()); 334 lines = lines.substring(lines.indexOf(C_INTERFACE_VECTOR), lines.length()); 338 335 lines = lines.substring(0, lines.indexOf('\'')); 339 336 lines = Entities.unescape(lines); … … 369 366 } catch (MalformedURLException e) { 370 367 throw (IOException) new IOException("Illegal url.").initCause(e); 371 } catch (DuplicateLayerException e){ 368 } catch (DuplicateLayerException e) { 372 369 Main.error(e); 373 370 } … … 401 398 try { 402 399 URL getAllImagesURL = new URL(BASE_URL + "/scpc/listerFeuillesParcommune.do?keepVolatileSession=&offset=2000"); 403 urlConn2 = (HttpURLConnection)getAllImagesURL.openConnection(); 400 urlConn2 = (HttpURLConnection) getAllImagesURL.openConnection(); 404 401 setCookie(urlConn2); 405 402 urlConn2.connect(); … … 491 488 * and store the result in the wmsLayer as well. 492 489 * @param wmsLayer the WMSLayer where the commune data and images are stored 493 * @throws IOException494 490 */ 495 491 public void retrieveCommuneBBox(WMSLayer wmsLayer) throws IOException { … … 500 496 content += "&dontSaveLastForward&keepVolatileSession="; 501 497 searchFormURL = new URL(content); 502 urlConn = (HttpURLConnection)searchFormURL.openConnection(); 498 urlConn = (HttpURLConnection) searchFormURL.openConnection(); 503 499 urlConn.setRequestMethod("GET"); 504 500 setCookie(); … … 534 530 int l = input.indexOf(C_BBOX_COMMUN_END, k+1); 535 531 double maxy = Double.parseDouble(input.substring(k+1, l)); 536 wmsLayer.setCommuneBBox( new EastNorthBound(new EastNorth(minx,miny), new EastNorth(maxx,maxy)));532 wmsLayer.setCommuneBBox(new EastNorthBound(new EastNorth(minx, miny), new EastNorth(maxx, maxy))); 537 533 } 538 534 }
Note:
See TracChangeset
for help on using the changeset viewer.
