Changeset 13358 in josm for trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
- Timestamp:
- 2018-01-26T23:21:57+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
r13346 r13358 18 18 import java.util.NoSuchElementException; 19 19 import java.util.Set; 20 import java.util.regex.Matcher; 20 21 import java.util.regex.Pattern; 21 22 import java.util.stream.Collectors; … … 121 122 private URL serviceUrl; 122 123 private List<String> formats; 124 private String version = "1.1.1"; 123 125 124 126 /** … … 136 138 public URL getServiceUrl() { 137 139 return serviceUrl; 140 } 141 142 /** 143 * Returns the WMS version used. 144 * @return the WMS version used (1.1.1 or 1.3.0) 145 * @since 13358 146 */ 147 public String getVersion() { 148 return version; 138 149 } 139 150 … … 198 209 public String buildGetMapUrl(Collection<LayerDetails> selectedLayers, String format) { 199 210 return buildRootUrl() + "FORMAT=" + format + (imageFormatHasTransparency(format) ? "&TRANSPARENT=TRUE" : "") 200 + "&VERSION= 1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS="211 + "&VERSION=" + version + "&SERVICE=WMS&REQUEST=GetMap&LAYERS=" 201 212 + selectedLayers.stream().map(x -> x.ident).collect(Collectors.joining(",")) 202 + "&STYLES=& SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}";213 + "&STYLES=&" + ("1.3.0".equals(version) ? "CRS" : "SRS") + "={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"; 203 214 } 204 215 … … 238 249 } 239 250 251 /** 252 * Attempts WMS GetCapabilities with version 1.1.1 first, then 1.3.0 in case of specific errors. 253 * @param serviceUrlStr WMS service URL 254 * @param getCapabilitiesUrl GetCapabilities URL 255 * @throws IOException if any I/O error occurs 256 * @throws WMSGetCapabilitiesException if any HTTP or parsing error occurs 257 */ 240 258 private void doAttemptGetCapabilities(String serviceUrlStr, URL getCapabilitiesUrl) 241 259 throws IOException, WMSGetCapabilitiesException { 260 final String url = getCapabilitiesUrl.toExternalForm(); 242 261 final Response response = HttpClient.create(getCapabilitiesUrl).connect(); 243 262 263 // Is the HTTP connection successul ? 244 264 if (response.getResponseCode() >= 400) { 245 throw new WMSGetCapabilitiesException(response.getResponseMessage(), response.fetchContent()); 265 // HTTP error for servers handling only WMS 1.3.0 ? 266 String errorMessage = response.getResponseMessage(); 267 String errorContent = response.fetchContent(); 268 Matcher tomcat = HttpClient.getTomcatErrorMatcher(errorContent); 269 boolean messageAbout130 = errorMessage != null && errorMessage.contains("1.3.0"); 270 boolean contentAbout130 = errorContent != null && tomcat != null && tomcat.matches() && tomcat.group(1).contains("1.3.0"); 271 if (url.contains("VERSION=1.1.1") && (messageAbout130 || contentAbout130)) { 272 doAttemptGetCapabilities130(serviceUrlStr, url); 273 return; 274 } 275 throw new WMSGetCapabilitiesException(errorMessage, errorContent); 246 276 } 247 277 248 278 try { 279 // Parse XML capabilities sent by the server 249 280 parseCapabilities(serviceUrlStr, response.getContent()); 250 281 } catch (WMSGetCapabilitiesException e) { 251 String url = getCapabilitiesUrl.toExternalForm();252 282 // ServiceException for servers handling only WMS 1.3.0 ? 253 283 if (e.getCause() == null && url.contains("VERSION=1.1.1")) { 254 doAttemptGetCapabilities(serviceUrlStr, new URL(url.replace("VERSION=1.1.1", "VERSION=1.3.0"))); 255 if (serviceUrl.toExternalForm().contains("VERSION=1.1.1")) { 256 serviceUrl = new URL(serviceUrl.toExternalForm().replace("VERSION=1.1.1", "VERSION=1.3.0")); 257 } 284 doAttemptGetCapabilities130(serviceUrlStr, url); 258 285 } else { 259 286 throw e; 260 287 } 261 288 } 289 } 290 291 /** 292 * Attempts WMS GetCapabilities with version 1.3.0. 293 * @param serviceUrlStr WMS service URL 294 * @param url GetCapabilities URL 295 * @throws IOException if any I/O error occurs 296 * @throws WMSGetCapabilitiesException if any HTTP or parsing error occurs 297 * @throws MalformedURLException in case of invalid URL 298 */ 299 private void doAttemptGetCapabilities130(String serviceUrlStr, final String url) 300 throws IOException, WMSGetCapabilitiesException, MalformedURLException { 301 doAttemptGetCapabilities(serviceUrlStr, new URL(url.replace("VERSION=1.1.1", "VERSION=1.3.0"))); 302 if (serviceUrl.toExternalForm().contains("VERSION=1.1.1")) { 303 serviceUrl = new URL(serviceUrl.toExternalForm().replace("VERSION=1.1.1", "VERSION=1.3.0")); 304 } 305 version = "1.3.0"; 262 306 } 263 307
Note:
See TracChangeset
for help on using the changeset viewer.