Changeset 12596 in josm
- Timestamp:
- 2017-08-13T00:24:03+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r12510 r12596 119 119 120 120 /** 121 * Open a connection to the given url and return a reader on the input stream121 * Open a connection to the given url (if HTTP, trough a GET request) and return a reader on the input stream 122 122 * from that connection. In case of user cancel, return <code>null</code>. 123 123 * @param urlStr The exact url to connect to. … … 129 129 * @throws OsmTransferException if data transfer errors occur 130 130 */ 131 protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason, 132 boolean uncompressAccordingToContentDisposition) throws OsmTransferException { 133 return getInputStreamRaw(urlStr, progressMonitor, reason, uncompressAccordingToContentDisposition, "GET", null); 134 } 135 136 /** 137 * Open a connection to the given url (if HTTP, with the specified method) and return a reader on the input stream 138 * from that connection. In case of user cancel, return <code>null</code>. 139 * @param urlStr The exact url to connect to. 140 * @param progressMonitor progress monitoring and abort handler 141 * @param reason The reason to show on console. Can be {@code null} if no reason is given 142 * @param uncompressAccordingToContentDisposition Whether to inspect the HTTP header {@code Content-Disposition} 143 * for {@code filename} and uncompress a gzip/bzip2 stream. 144 * @param httpMethod HTTP method ("GET", "POST" or "PUT") 145 * @param requestBody HTTP request body (for "POST" and "PUT" methods only). Must be null for "GET" method. 146 * @return An reader reading the input stream (servers answer) or <code>null</code>. 147 * @throws OsmTransferException if data transfer errors occur 148 * @since 12596 149 */ 131 150 @SuppressWarnings("resource") 132 151 protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason, 133 boolean uncompressAccordingToContentDisposition ) throws OsmTransferException {152 boolean uncompressAccordingToContentDisposition, String httpMethod, byte[] requestBody) throws OsmTransferException { 134 153 try { 135 154 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(urlStr, Main.getJOSMWebsite()); … … 151 170 } 152 171 153 final HttpClient client = HttpClient.create(url); 172 final HttpClient client = HttpClient.create(url, httpMethod) 173 .setFinishOnCloseOutput(false) 174 .setReasonForRequest(reason) 175 .setRequestBody(requestBody); 154 176 activeConnection = client; 155 client.setReasonForRequest(reason);156 177 adaptRequest(client); 157 178 if (doAuthenticate) { -
trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java
r12542 r12596 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.nio.charset.StandardCharsets; 8 9 import java.util.EnumMap; 9 10 import java.util.Map; … … 35 36 */ 36 37 public class OverpassDownloadReader extends BoundingBoxDownloader { 38 39 private static final String DATA_PREFIX = "?data="; 37 40 38 41 static final class OverpassOsmReader extends OsmReader { … … 144 147 final String query = this.overpassQuery.replace("{{bbox}}", lat1 + "," + lon1 + "," + lat2 + "," + lon2); 145 148 final String expandedOverpassQuery = expandExtendedQueries(query); 146 return "interpreter ?data="+ Utils.encodeUrl(expandedOverpassQuery);149 return "interpreter" + DATA_PREFIX + Utils.encodeUrl(expandedOverpassQuery); 147 150 } 148 151 } … … 195 198 boolean uncompressAccordingToContentDisposition) throws OsmTransferException { 196 199 try { 197 return super.getInputStreamRaw(urlStr, progressMonitor, reason, uncompressAccordingToContentDisposition); 200 int index = urlStr.indexOf(DATA_PREFIX); 201 // Make an HTTP POST request instead of a simple GET, allows more complex queries 202 return super.getInputStreamRaw(urlStr.substring(0, index), 203 progressMonitor, reason, uncompressAccordingToContentDisposition, 204 "POST", Utils.decodeUrl(urlStr.substring(index + DATA_PREFIX.length())).getBytes(StandardCharsets.UTF_8)); 198 205 } catch (OsmApiException ex) { 199 206 final String errorIndicator = "Error</strong>: ";
Note:
See TracChangeset
for help on using the changeset viewer.