Changeset 17330 in josm for trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
- Timestamp:
- 2020-11-22T22:54:01+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
r16913 r17330 43 43 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerErrorException; 44 44 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerForbiddenException; 45 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerOsmApiException; 45 46 import org.openstreetmap.josm.io.remotecontrol.handler.VersionHandler; 46 47 import org.openstreetmap.josm.tools.Logging; … … 185 186 String get = in.readLine(); 186 187 if (get == null) { 187 send Error(out);188 sendInternalError(out, null); 188 189 return; 189 190 } … … 192 193 StringTokenizer st = new StringTokenizer(get); 193 194 if (!st.hasMoreTokens()) { 194 send Error(out);195 sendInternalError(out, null); 195 196 return; 196 197 } 197 198 String method = st.nextToken(); 198 199 if (!st.hasMoreTokens()) { 199 send Error(out);200 sendInternalError(out, null); 200 201 return; 201 202 } … … 252 253 String help = "No command specified! The following commands are available:<ul>" + usage 253 254 + "</ul>" + "See <a href=\""+websiteDoc+"\">"+websiteDoc+"</a> for complete documentation."; 254 sendHeader(out, "400 Bad Request", "text/html", true); 255 out.write(String.format( 256 RESPONSE_TEMPLATE, 257 "<title>Bad Request</title>", 258 "<h1>HTTP Error 400: Bad Request</h1>" + 259 "<p>" + help + "</p>")); 260 out.flush(); 255 sendBadRequest(out, help); 261 256 } else { 262 257 // create handler object … … 273 268 out.write(handler.getContent()); 274 269 out.flush(); 270 } catch (RequestHandlerOsmApiException ex) { 271 Logging.debug(ex); 272 sendBadGateway(out, ex.getMessage()); 275 273 } catch (RequestHandlerErrorException ex) { 276 274 Logging.debug(ex); 277 send Error(out);275 sendInternalError(out, ex.getMessage()); 278 276 } catch (RequestHandlerBadRequestException ex) { 279 277 Logging.debug(ex); … … 289 287 Logging.error(e); 290 288 try { 291 send Error(out);289 sendInternalError(out, e.getMessage()); 292 290 } catch (IOException e1) { 293 291 Logging.warn(e1); … … 302 300 } 303 301 304 /** 305 * Sends a 500 error: server error 306 * 307 * @param out 308 * The writer where the error is written 309 * @throws IOException 310 * If the error can not be written 311 */ 312 private static void sendError(Writer out) throws IOException { 313 sendHeader(out, "500 Internal Server Error", "text/html", true); 302 private static void sendError(Writer out, int errorCode, String errorName, String help) throws IOException { 303 sendHeader(out, errorCode + " " + errorName, "text/html", true); 314 304 out.write(String.format( 315 305 RESPONSE_TEMPLATE, 316 "<title>Internal Error</title>", 317 "<h1>HTTP Error 500: Internal Server Error</h1>" 306 "<title>" + errorName + "</title>", 307 "<h1>HTTP Error " + errorCode + ": " + errorName + "</h1>" + 308 (help == null ? "" : "<p>"+Utils.escapeReservedCharactersHTML(help) + "</p>") 318 309 )); 319 310 out.flush(); … … 321 312 322 313 /** 323 * Sends a 501 error: not implemented 324 * 325 * @param out 326 * The writer where the error is written 327 * @throws IOException 328 * If the error can not be written 329 */ 330 private static void sendNotImplemented(Writer out) throws IOException { 331 sendHeader(out, "501 Not Implemented", "text/html", true); 332 out.write(String.format( 333 RESPONSE_TEMPLATE, 334 "<title>Not Implemented</title>", 335 "<h1>HTTP Error 501: Not Implemented</h1>" 336 )); 337 out.flush(); 338 } 339 340 /** 341 * Sends a 403 error: forbidden 314 * Sends a 500 error: internal server error 342 315 * 343 316 * @param out … … 348 321 * If the error can not be written 349 322 */ 323 private static void sendInternalError(Writer out, String help) throws IOException { 324 sendError(out, 500, "Internal Server Error", help); 325 } 326 327 /** 328 * Sends a 501 error: not implemented 329 * 330 * @param out 331 * The writer where the error is written 332 * @throws IOException 333 * If the error can not be written 334 */ 335 private static void sendNotImplemented(Writer out) throws IOException { 336 sendError(out, 501, "Not Implemented", null); 337 } 338 339 /** 340 * Sends a 502 error: bad gateway 341 * 342 * @param out 343 * The writer where the error is written 344 * @param help 345 * Optional HTML help content to display, can be null 346 * @throws IOException 347 * If the error can not be written 348 */ 349 private static void sendBadGateway(Writer out, String help) throws IOException { 350 sendError(out, 502, "Bad Gateway", help); 351 } 352 353 /** 354 * Sends a 403 error: forbidden 355 * 356 * @param out 357 * The writer where the error is written 358 * @param help 359 * Optional HTML help content to display, can be null 360 * @throws IOException 361 * If the error can not be written 362 */ 350 363 private static void sendForbidden(Writer out, String help) throws IOException { 351 sendHeader(out, "403 Forbidden", "text/html", true); 352 out.write(String.format( 353 RESPONSE_TEMPLATE, 354 "<title>Forbidden</title>", 355 "<h1>HTTP Error 403: Forbidden</h1>" + 356 (help == null ? "" : "<p>"+Utils.escapeReservedCharactersHTML(help) + "</p>") 357 )); 358 out.flush(); 364 sendError(out, 403, "Forbidden", help); 359 365 } 360 366 … … 367 373 */ 368 374 private static void sendBadRequest(Writer out, String help) throws IOException { 369 sendHeader(out, "400 Bad Request", "text/html", true); 370 out.write(String.format( 371 RESPONSE_TEMPLATE, 372 "<title>Bad Request</title>", 373 "<h1>HTTP Error 400: Bad Request</h1>" + 374 (help == null ? "" : ("<p>" + Utils.escapeReservedCharactersHTML(help) + "</p>")) 375 )); 376 out.flush(); 375 sendError(out, 400, "Bad Request", help); 377 376 } 378 377
Note:
See TracChangeset
for help on using the changeset viewer.