Changeset 4834 in josm
- Timestamp:
- 2012-01-21T12:07:57+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/remotecontrol
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
r4833 r4834 11 11 import java.io.Writer; 12 12 import java.net.Socket; 13 import java.util.Arrays; 13 14 import java.util.Date; 14 15 import java.util.HashMap; 16 import java.util.Map; 17 import java.util.Map.Entry; 15 18 import java.util.StringTokenizer; 19 import java.util.TreeMap; 20 import java.util.TreeSet; 16 21 17 22 import org.openstreetmap.josm.io.remotecontrol.handler.AddNodeHandler; … … 26 31 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerForbiddenException; 27 32 import org.openstreetmap.josm.io.remotecontrol.handler.VersionHandler; 33 import org.openstreetmap.josm.tools.Utils; 28 34 29 35 /** … … 49 55 * can extend this list by using @see addRequestHandler 50 56 */ 51 private static HashMap<String, Class<? extends RequestHandler>> handlers = new HashMap<String, Class<? extends RequestHandler>>();57 private static Map<String, Class<? extends RequestHandler>> handlers = new TreeMap<String, Class<? extends RequestHandler>>(); 52 58 53 59 /** … … 174 180 175 181 // find a handler for this command 176 Class<? extends RequestHandler> handlerClass = handlers 177 .get(command); 182 Class<? extends RequestHandler> handlerClass = handlers.get(command); 178 183 if (handlerClass == null) { 179 184 // no handler found 180 sendBadRequest(out); 185 StringBuilder usage = new StringBuilder(1024); 186 for (Entry<String, Class<? extends RequestHandler>> handler : handlers.entrySet()) { 187 String[] mandatory = handler.getValue().newInstance().getMandatoryParams(); 188 usage.append("<li>"); 189 usage.append(handler.getKey()); 190 if (mandatory != null) { 191 usage.append("<br/>mandatory parameter: ").append(Utils.join(", ", Arrays.asList(mandatory))); 192 } 193 usage.append("</li>"); 194 } 195 String help = "No command specified! The following commands are available:<ul>" 196 + usage.toString() 197 + "</ul>"; 198 sendBadRequest(out, help); 181 199 } else { 182 200 // create handler object … … 196 214 sendError(out); 197 215 } catch (RequestHandlerBadRequestException ex) { 198 sendBadRequest(out );216 sendBadRequest(out, ex.getMessage()); 199 217 } catch (RequestHandlerForbiddenException ex) { 200 218 sendForbidden(out); … … 282 300 * If the error can not be written 283 301 */ 284 private void sendBadRequest(Writer out ) throws IOException {302 private void sendBadRequest(Writer out, String help) throws IOException { 285 303 sendHeader(out, "400 Bad Request", "text/html", true); 286 304 out.write("<HTML>\r\n"); … … 289 307 out.write("<BODY>"); 290 308 out.write("<H1>HTTP Error 400: Bad Request</h2>\r\n"); 309 if (help != null) { 310 out.write(help); 311 } 291 312 out.write("</BODY></HTML>\r\n"); 292 313 out.flush(); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
r4833 r4834 27 27 28 28 @Override 29 p rotectedString[] getMandatoryParams()29 public String[] getMandatoryParams() 30 30 { 31 31 return new String[] { "lat", "lon" }; -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
r4833 r4834 22 22 23 23 @Override 24 p rotectedString[] getMandatoryParams() {24 public String[] getMandatoryParams() { 25 25 return new String[]{"way"}; 26 26 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java
r3720 r4834 26 26 27 27 @Override 28 p rotectedString[] getMandatoryParams()28 public String[] getMandatoryParams() 29 29 { 30 30 return new String[] { "url" }; -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java
r3707 r4834 32 32 33 33 @Override 34 p rotectedString[] getMandatoryParams()34 public String[] getMandatoryParams() 35 35 { 36 36 return new String[] { "url" }; -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java
r4795 r4834 50 50 51 51 @Override 52 p rotectedString[] getMandatoryParams()52 public String[] getMandatoryParams() 53 53 { 54 54 return new String[] { "bottom", "top", "left", "right" }; -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java
r4833 r4834 20 20 21 21 @Override 22 p rotectedString[] getMandatoryParams() {22 public String[] getMandatoryParams() { 23 23 return new String[]{"objects"}; 24 24 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r4191 r4834 5 5 6 6 import java.util.HashMap; 7 import java.util.LinkedList; 8 import java.util.List; 7 9 import java.util.StringTokenizer; 8 10 … … 11 13 import org.openstreetmap.josm.Main; 12 14 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 15 import org.openstreetmap.josm.tools.Utils; 13 16 14 17 /** … … 91 94 } 92 95 93 protected String[] getMandatoryParams() 94 { 96 public String[] getMandatoryParams() { 95 97 return null; 96 98 } … … 169 171 if(mandatory == null) return; 170 172 173 List<String> missingKeys = new LinkedList<String>(); 171 174 boolean error = false; 172 175 for (int i = 0; i < mandatory.length; ++i) { … … 176 179 error = true; 177 180 System.out.println("'" + myCommand + "' remote control request must have '" + key + "' parameter"); 181 missingKeys.add(key); 178 182 } 179 183 } 180 if (error) 181 throw new RequestHandlerBadRequestException(); 184 if (error) { 185 throw new RequestHandlerBadRequestException( 186 "The following keys are mandatory, but have not been provided: " 187 + Utils.join(", ", missingKeys)); 188 } 182 189 } 183 190 … … 204 211 205 212 public static class RequestHandlerException extends Exception { 213 214 public RequestHandlerException(String message) { 215 super(message); 216 } 217 218 public RequestHandlerException() { 219 } 206 220 } 207 221 … … 210 224 211 225 public static class RequestHandlerBadRequestException extends RequestHandlerException { 226 227 public RequestHandlerBadRequestException(String message) { 228 super(message); 229 } 212 230 } 213 231
Note:
See TracChangeset
for help on using the changeset viewer.