Changeset 9732 in josm
- Timestamp:
- 2016-02-04T00:48:38+01:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r9214 r9732 273 273 // 274 274 final OsmDataLayer layer = createNewLayer(newLayerName); 275 Main.main.addLayer(layer, computeBbox(bounds)); 275 if (Main.main != null) 276 Main.main.addLayer(layer, computeBbox(bounds)); 276 277 return layer; 277 278 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r9353 r9732 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException; 6 7 import java.io.InputStream; 7 8 import java.net.HttpURLConnection; … … 122 123 } 123 124 125 if ("file".equals(url.getProtocol())) { 126 try { 127 return url.openStream(); 128 } catch (IOException e) { 129 throw new OsmTransferException(e); 130 } 131 } 132 124 133 final HttpClient client = HttpClient.create(url); 125 134 activeConnection = client; -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
r8846 r9732 115 115 protected void validateRequest() throws RequestHandlerBadRequestException { 116 116 try { 117 lat = Double.parseDouble(args .get("lat"));118 lon = Double.parseDouble(args .get("lon"));117 lat = Double.parseDouble(args != null ? args.get("lat") : ""); 118 lon = Double.parseDouble(args != null ? args.get("lon") : ""); 119 119 } catch (NumberFormatException e) { 120 120 throw new RequestHandlerBadRequestException("NumberFormatException ("+e.getMessage()+')', e); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java
r8444 r9732 98 98 @Override 99 99 protected void validateRequest() throws RequestHandlerBadRequestException { 100 String urlString = args .get("url");100 String urlString = args != null ? args.get("url") : null; 101 101 if (Main.pref.getBoolean("remotecontrol.importhandler.fix_url_query", true)) { 102 102 urlString = Utils.fixURLQuery(urlString); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r8929 r9732 223 223 List<String> missingKeys = new LinkedList<>(); 224 224 boolean error = false; 225 if (mandatory != null) for (String key : mandatory) { 226 String value = args.get(key); 227 if (value == null || value.isEmpty()) { 228 error = true; 229 Main.warn('\'' + myCommand + "' remote control request must have '" + key + "' parameter"); 230 missingKeys.add(key); 225 if (mandatory != null && args != null) { 226 for (String key : mandatory) { 227 String value = args.get(key); 228 if (value == null || value.isEmpty()) { 229 error = true; 230 Main.warn('\'' + myCommand + "' remote control request must have '" + key + "' parameter"); 231 missingKeys.add(key); 232 } 231 233 } 232 234 } 233 235 Set<String> knownParams = new HashSet<>(); 234 if (mandatory != null) Collections.addAll(knownParams, mandatory); 235 if (optional != null) Collections.addAll(knownParams, optional); 236 for (String par: args.keySet()) { 237 if (!knownParams.contains(par)) { 238 Main.warn("Unknown remote control parameter {0}, skipping it", par); 236 if (mandatory != null) 237 Collections.addAll(knownParams, mandatory); 238 if (optional != null) 239 Collections.addAll(knownParams, optional); 240 if (args != null) { 241 for (String par: args.keySet()) { 242 if (!knownParams.contains(par)) { 243 Main.warn("Unknown remote control parameter {0}, skipping it", par); 244 } 239 245 } 240 246 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9720 r9732 1221 1221 */ 1222 1222 public static String fixURLQuery(String url) { 1223 if (url .indexOf('?') == -1)1223 if (url == null || url.indexOf('?') == -1) 1224 1224 return url; 1225 1225 -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java
r8876 r9732 4 4 import static org.junit.Assert.assertEquals; 5 5 6 import java.io.File; 7 8 import org.junit.BeforeClass; 9 import org.junit.Rule; 6 10 import org.junit.Test; 11 import org.junit.rules.ExpectedException; 12 import org.openstreetmap.josm.JOSMFixture; 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.TestUtils; 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 16 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 17 import org.openstreetmap.josm.tools.Utils; 7 18 8 19 /** … … 12 23 13 24 /** 25 * Rule used for tests throwing exceptions. 26 */ 27 @Rule 28 public ExpectedException thrown = ExpectedException.none(); 29 30 /** 31 * Setup test. 32 */ 33 @BeforeClass 34 public static void setUpBeforeClass() { 35 JOSMFixture.createUnitTestFixture().init(true); 36 } 37 38 private static ImportHandler newHandler(String url) { 39 ImportHandler req = new ImportHandler(); 40 if (url != null) 41 req.setUrl(url); 42 return req; 43 } 44 45 /** 14 46 * Non-regression test for bug #7434. 15 47 */ 16 48 @Test 17 49 public void testTicket7434() { 18 final ImportHandler req = new ImportHandler(); 19 req.setUrl("http://localhost:8111/import?url=http://localhost:8888/relations?relations=19711&mode=recursive"); 50 ImportHandler req = newHandler("http://localhost:8111/import?url=http://localhost:8888/relations?relations=19711&mode=recursive"); 20 51 assertEquals("http://localhost:8888/relations?relations=19711&mode=recursive", req.args.get("url")); 21 52 } 53 54 /** 55 * Unit test for bad request - no param. 56 * @throws Exception if any error occurs 57 */ 58 @Test 59 public void testBadRequestNoParam() throws Exception { 60 thrown.expect(RequestHandlerBadRequestException.class); 61 thrown.expectMessage("MalformedURLException: null"); 62 newHandler(null).handle(); 63 } 64 65 /** 66 * Unit test for bad request - invalid URL. 67 * @throws Exception if any error occurs 68 */ 69 @Test 70 public void testBadRequestInvalidUrl() throws Exception { 71 thrown.expect(RequestHandlerBadRequestException.class); 72 thrown.expectMessage("MalformedURLException: no protocol: invalid_url"); 73 newHandler("https://localhost?url=invalid_url").handle(); 74 } 75 76 /** 77 * Unit test for bad request - incomplete URL. 78 * @throws Exception if any error occurs 79 */ 80 @Test 81 public void testBadRequestIncompleteUrl() throws Exception { 82 thrown.expect(RequestHandlerBadRequestException.class); 83 thrown.expectMessage("The following keys are mandatory, but have not been provided: url"); 84 newHandler("https://localhost").handle(); 85 } 86 87 /** 88 * Unit test for nominal request - local data file. 89 * @throws Exception if any error occurs 90 */ 91 @Test 92 public void testNominalRequest() throws Exception { 93 String url = new File(TestUtils.getRegressionDataFile(11957, "data.osm")).toURI().toURL().toExternalForm(); 94 try { 95 newHandler("https://localhost?url=" + Utils.encodeUrl(url)).handle(); 96 } finally { 97 for (OsmDataLayer layer : Main.map.mapView.getLayersOfType(OsmDataLayer.class)) { 98 Main.main.removeLayer(layer); 99 } 100 } 101 } 22 102 }
Note:
See TracChangeset
for help on using the changeset viewer.