- Timestamp:
- 2016-09-08T00:02:03+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r10587 r10973 146 146 */ 147 147 PermissionPrefWithDefault permissionPref = getPermissionPref(); 148 if (permissionPref != null && permissionPref.pref != null) { 149 if (!Main.pref.getBoolean(permissionPref.pref, permissionPref.defaultVal)) { 150 String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by preferences", myCommand); 151 Main.info(err); 152 throw new RequestHandlerForbiddenException(err); 153 } 148 if (permissionPref != null && permissionPref.pref != null && !Main.pref.getBoolean(permissionPref.pref, permissionPref.defaultVal)) { 149 String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by preferences", myCommand); 150 Main.info(err); 151 throw new RequestHandlerForbiddenException(err); 154 152 } 155 153 … … 179 177 * 180 178 * @param url The request URL. 181 */ 182 public void setUrl(String url) { 179 * @throws RequestHandlerBadRequestException if request URL is invalid 180 */ 181 public void setUrl(String url) throws RequestHandlerBadRequestException { 183 182 this.request = url; 184 parseArgs(); 183 try { 184 parseArgs(); 185 } catch (URISyntaxException e) { 186 throw new RequestHandlerBadRequestException(e); 187 } 185 188 } 186 189 … … 190 193 * 191 194 * Can be overridden by subclass. 192 */ 193 protected void parseArgs() { 194 try { 195 this.args = getRequestParameter(new URI(this.request)); 196 } catch (URISyntaxException ex) { 197 throw new RuntimeException(ex); 198 } 195 * @throws URISyntaxException if request URL is invalid 196 */ 197 protected void parseArgs() throws URISyntaxException { 198 this.args = getRequestParameter(new URI(this.request)); 199 199 } 200 200 … … 311 311 312 312 public static class RequestHandlerErrorException extends RequestHandlerException { 313 314 /** 315 * Constructs a new {@code RequestHandlerErrorException}. 316 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). 317 */ 313 318 public RequestHandlerErrorException(Throwable cause) { 314 319 super(cause); … … 318 323 public static class RequestHandlerBadRequestException extends RequestHandlerException { 319 324 325 /** 326 * Constructs a new {@code RequestHandlerBadRequestException}. 327 * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. 328 */ 320 329 public RequestHandlerBadRequestException(String message) { 321 330 super(message); 322 331 } 323 332 333 /** 334 * Constructs a new {@code RequestHandlerBadRequestException}. 335 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). 336 */ 337 public RequestHandlerBadRequestException(Throwable cause) { 338 super(cause); 339 } 340 341 /** 342 * Constructs a new {@code RequestHandlerBadRequestException}. 343 * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. 344 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). 345 */ 324 346 public RequestHandlerBadRequestException(String message, Throwable cause) { 325 347 super(message, cause); … … 328 350 329 351 public static class RequestHandlerForbiddenException extends RequestHandlerException { 330 private static final long serialVersionUID = 2263904699747115423L; 331 352 353 /** 354 * Constructs a new {@code RequestHandlerForbiddenException}. 355 * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. 356 */ 332 357 public RequestHandlerForbiddenException(String message) { 333 358 super(message); … … 337 362 public abstract static class RawURLParseRequestHandler extends RequestHandler { 338 363 @Override 339 protected void parseArgs() {364 protected void parseArgs() throws URISyntaxException { 340 365 Map<String, String> args = new HashMap<>(); 341 366 if (request.indexOf('?') != -1) { -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandlerTest.java
r10436 r10973 31 31 } 32 32 33 private static AddNodeHandler newHandler(String url) {33 private static AddNodeHandler newHandler(String url) throws RequestHandlerBadRequestException { 34 34 AddNodeHandler req = new AddNodeHandler(); 35 35 if (url != null) -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.java
r10436 r10973 31 31 } 32 32 33 private static AddWayHandler newHandler(String url) {33 private static AddWayHandler newHandler(String url) throws RequestHandlerBadRequestException { 34 34 AddWayHandler req = new AddWayHandler(); 35 35 if (url != null) -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java
r10116 r10973 28 28 } 29 29 30 private static ImageryHandler newHandler(String url) {30 private static ImageryHandler newHandler(String url) throws RequestHandlerBadRequestException { 31 31 ImageryHandler req = new ImageryHandler(); 32 32 if (url != null) -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java
r10436 r10973 36 36 } 37 37 38 private static ImportHandler newHandler(String url) {38 private static ImportHandler newHandler(String url) throws RequestHandlerBadRequestException { 39 39 ImportHandler req = new ImportHandler(); 40 40 if (url != null) … … 45 45 /** 46 46 * Non-regression test for bug #7434. 47 * @throws Exception if any error occurs 47 48 */ 48 49 @Test 49 public void testTicket7434() {50 public void testTicket7434() throws Exception { 50 51 ImportHandler req = newHandler("http://localhost:8111/import?url=http://localhost:8888/relations?relations=19711&mode=recursive"); 51 52 assertEquals("http://localhost:8888/relations?relations=19711&mode=recursive", req.args.get("url")); -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandlerTest.java
r10116 r10973 28 28 } 29 29 30 private static LoadAndZoomHandler newHandler(String url) {30 private static LoadAndZoomHandler newHandler(String url) throws RequestHandlerBadRequestException { 31 31 LoadAndZoomHandler req = new LoadAndZoomHandler(); 32 32 if (url != null) -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java
r10116 r10973 28 28 } 29 29 30 private static LoadObjectHandler newHandler(String url) {30 private static LoadObjectHandler newHandler(String url) throws RequestHandlerBadRequestException { 31 31 LoadObjectHandler req = new LoadObjectHandler(); 32 32 if (url != null) -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandlerTest.java
r8876 r10973 10 10 import org.junit.Test; 11 11 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 12 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 12 13 13 14 /** … … 16 17 public class RequestHandlerTest { 17 18 18 Map<String, String> getRequestParameter(String url) {19 Map<String, String> getRequestParameter(String url) throws RequestHandlerBadRequestException { 19 20 final RequestHandler req = new RequestHandler() { 20 21 @Override … … 47 48 /** 48 49 * Test request parameter - case 1 50 * @throws RequestHandlerBadRequestException never 49 51 */ 50 52 @Test 51 public void testRequestParameter1() {53 public void testRequestParameter1() throws RequestHandlerBadRequestException { 52 54 final Map<String, String> expected = new HashMap<>(); 53 55 expected.put("query", "a"); … … 58 60 /** 59 61 * Test request parameter - case 2 62 * @throws RequestHandlerBadRequestException never 60 63 */ 61 64 @Test 62 public void testRequestParameter2() {65 public void testRequestParameter2() throws RequestHandlerBadRequestException { 63 66 assertEquals(Collections.singletonMap("query", "a&b==c"), 64 67 getRequestParameter("http://example.com/?query=a%26b==c")); … … 67 70 /** 68 71 * Test request parameter - case 3 72 * @throws RequestHandlerBadRequestException never 69 73 */ 70 74 @Test 71 public void testRequestParameter3() {75 public void testRequestParameter3() throws RequestHandlerBadRequestException { 72 76 assertEquals(Collections.singleton("blue+light blue"), 73 77 getRequestParameter("http://example.com/blue+light%20blue?blue%2Blight+blue").keySet()); … … 78 82 * @see <a href="http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding"> 79 83 * What every web developer must know about URL encoding</a> 84 * @throws RequestHandlerBadRequestException never 80 85 */ 81 86 @Test 82 public void testRequestParameter4() {87 public void testRequestParameter4() throws RequestHandlerBadRequestException { 83 88 assertEquals(Collections.singletonMap("/?:@-._~!$'()* ,;", "/?:@-._~!$'()* ,;=="), getRequestParameter( 84 89 // CHECKSTYLE.OFF: LineLength … … 89 94 /** 90 95 * Test request parameter - case 5 96 * @throws RequestHandlerBadRequestException never 91 97 */ 92 98 @Test 93 public void testRequestParameter5() {99 public void testRequestParameter5() throws RequestHandlerBadRequestException { 94 100 final Map<String, String> expected = new HashMap<>(); 95 101 expected.put("space", " "); … … 97 103 assertEquals(expected, getRequestParameter("http://example.com/?space=%20&tab=%09")); 98 104 } 105 106 /** 107 * Test request parameter - invalid case 108 * @throws RequestHandlerBadRequestException always 109 */ 110 @Test(expected = RequestHandlerBadRequestException.class) 111 public void testRequestParameterInvalid() throws RequestHandlerBadRequestException { 112 getRequestParameter("http://localhost:8111/load_and_zoom"+ 113 "?addtags=wikipedia:de=Wei%C3%9Fe_Gasse|maxspeed=5"+ 114 "&select=way23071688,way23076176,way23076177,"+ 115 "&left=13.739727546842&right=13.740890970188&top=51.049987191025&bottom=51.048466954325"); 116 } 99 117 }
Note:
See TracChangeset
for help on using the changeset viewer.