Changeset 10587 in josm
- Timestamp:
- 2016-07-22T22:52:14+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/remotecontrol
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
r10208 r10587 12 12 import java.io.Writer; 13 13 import java.net.Socket; 14 import java.nio.charset.Charset; 14 15 import java.nio.charset.StandardCharsets; 15 16 import java.util.Arrays; 16 17 import java.util.Date; 17 18 import java.util.HashMap; 19 import java.util.Locale; 18 20 import java.util.Map; 19 21 import java.util.Map.Entry; … … 45 47 */ 46 48 public class RequestProcessor extends Thread { 49 50 private static final Charset RESPONSE_CHARSET = StandardCharsets.UTF_8; 51 private static final String RESPONSE_TEMPLATE = "<!DOCTYPE html><html><head><meta charset=\"" 52 + RESPONSE_CHARSET.name() 53 + "\">%s</head><body>%s</body></html>"; 54 47 55 /** 48 56 * RemoteControl protocol version. Change minor number for compatible … … 145 153 try { 146 154 OutputStream raw = new BufferedOutputStream(request.getOutputStream()); 147 out = new OutputStreamWriter(raw, StandardCharsets.UTF_8);155 out = new OutputStreamWriter(raw, RESPONSE_CHARSET); 148 156 BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), "ASCII")); 149 157 … … 269 277 private static void sendError(Writer out) throws IOException { 270 278 sendHeader(out, "500 Internal Server Error", "text/html", true); 271 out.write("<HTML>\r\n"); 272 out.write("<HEAD><TITLE>Internal Error</TITLE>\r\n"); 273 out.write("</HEAD>\r\n"); 274 out.write("<BODY>"); 275 out.write("<H1>HTTP Error 500: Internal Server Error</H1>\r\n"); 276 out.write("</BODY></HTML>\r\n"); 279 out.write(String.format( 280 RESPONSE_TEMPLATE, 281 "<title>Internal Error</title>", 282 "<h1>HTTP Error 500: Internal Server Error</h1>" 283 )); 277 284 out.flush(); 278 285 } … … 288 295 private static void sendNotImplemented(Writer out) throws IOException { 289 296 sendHeader(out, "501 Not Implemented", "text/html", true); 290 out.write("<HTML>\r\n"); 291 out.write("<HEAD><TITLE>Not Implemented</TITLE>\r\n"); 292 out.write("</HEAD>\r\n"); 293 out.write("<BODY>"); 294 out.write("<H1>HTTP Error 501: Not Implemented</h2>\r\n"); 295 out.write("</BODY></HTML>\r\n"); 297 out.write(String.format( 298 RESPONSE_TEMPLATE, 299 "<title>Not Implemented</title>", 300 "<h1>HTTP Error 501: Not Implemented</h1>" 301 )); 296 302 out.flush(); 297 303 } … … 309 315 private static void sendForbidden(Writer out, String help) throws IOException { 310 316 sendHeader(out, "403 Forbidden", "text/html", true); 311 out.write("<HTML>\r\n"); 312 out.write("<HEAD><TITLE>Forbidden</TITLE>\r\n"); 313 out.write("</HEAD>\r\n"); 314 out.write("<BODY>"); 315 out.write("<H1>HTTP Error 403: Forbidden</h2>\r\n"); 316 if (help != null) { 317 out.write(help); 318 } 319 out.write("</BODY></HTML>\r\n"); 317 out.write(String.format( 318 RESPONSE_TEMPLATE, 319 "<title>Forbidden</title>", 320 "<h1>HTTP Error 403: Forbidden</h1>" + 321 (help == null ? "" : "<p>"+Utils.escapeReservedCharactersHTML(help) + "</p>") 322 )); 320 323 out.flush(); 321 324 } 322 325 323 326 /** 324 * Sends a 40 3error:forbidden327 * Sends a 400 error: bad request 325 328 * 326 329 * @param out … … 333 336 private static void sendBadRequest(Writer out, String help) throws IOException { 334 337 sendHeader(out, "400 Bad Request", "text/html", true); 335 out.write("<HTML>\r\n"); 336 out.write("<HEAD><TITLE>Bad Request</TITLE>\r\n"); 337 out.write("</HEAD>\r\n"); 338 out.write("<BODY>"); 339 out.write("<H1>HTTP Error 400: Bad Request</h2>\r\n"); 340 if (help != null) { 341 out.write(help); 342 } 343 out.write("</BODY></HTML>\r\n"); 338 out.write(String.format( 339 RESPONSE_TEMPLATE, 340 "<title>Bad Request</title>", 341 "<h1>HTTP Error 400: Bad Request</h1>" + 342 (help == null ? "" : ("<p>" + Utils.escapeReservedCharactersHTML(help) + "</p>")) 343 )); 344 344 out.flush(); 345 345 } … … 362 362 boolean endHeaders) throws IOException { 363 363 out.write("HTTP/1.1 " + status + "\r\n"); 364 Date now = new Date(); 365 out.write("Date: " + now + "\r\n"); 364 out.write("Date: " + new Date() + "\r\n"); 366 365 out.write("Server: JOSM RemoteControl\r\n"); 367 out.write("Content-type: " + contentType + "\r\n"); 366 out.write("Content-type: " + contentType + "; charset=" + RESPONSE_CHARSET.name().toLowerCase(Locale.ENGLISH) + "\r\n"); 368 367 out.write("Access-Control-Allow-Origin: *\r\n"); 369 368 if (endHeaders) -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r9732 r10587 247 247 if (error) { 248 248 throw new RequestHandlerBadRequestException( 249 "The following keys are mandatory, but have not been provided: "250 +Utils.join(", ", missingKeys));249 tr("The following keys are mandatory, but have not been provided: {0}", 250 Utils.join(", ", missingKeys))); 251 251 } 252 252 }
Note:
See TracChangeset
for help on using the changeset viewer.