Ignore:
Timestamp:
2010-07-28T22:23:53+02:00 (14 years ago)
Author:
stephankn
Message:

'Added version info capable of jsonp. Also made header CORS aware'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/remotecontrol/src/org/openstreetmap/josm/plugins/remotecontrol/RequestProcessor.java

    r21433 r22472  
    4343public class RequestProcessor extends Thread
    4444{
     45        /**
     46         * RemoteControl protocol version.
     47         * Change minor number for compatible interface extensions. Change major number in case of incompatible changes.
     48         */
     49        public static final String PROTOCOLVERSION = "{\"protocolversion\": {\"major\": 1, \"minor\": 0}, \"application\": \"JOSM RemoteControl\"}";
     50
     51       
    4552    /** The socket this processor listens on */
    4653    private Socket request;
     
    8087        try
    8188        {
     89                        String content = "OK\r\n";
     90                        String contentType = "text/plain";
     91                       
    8292            OutputStream raw = new BufferedOutputStream( request.getOutputStream());
    8393            out = new OutputStreamWriter(raw);
     
    278288                }
    279289                // TODO: select/zoom to downloaded
    280             }
    281             sendHeader(out, "200 OK", "text/plain", false);
    282             out.write("Content-length: 4\r\n");
     290            } else if (command.equals("/version")) {
     291                                content = RequestProcessor.PROTOCOLVERSION;
     292                                contentType = "application/json";
     293                                if (args.containsKey("jsonp")) {
     294                                        content = args.get("jsonp")+ " && " + args.get("jsonp") + "(" + content + ")";
     295                                }
     296                        }
     297            sendHeader(out, "200 OK", contentType, false);
     298            out.write("Content-length: "+content.length()+"\r\n");
    283299            out.write("\r\n");
    284             out.write("OK\r\n");
     300            out.write(content);
    285301            out.flush();
    286302        }
     
    409425        out.write("Server: JOSM RemoteControl\r\n");
    410426        out.write("Content-type: " + contentType + "\r\n");
     427                out.write("Access-Control-Allow-Origin: *\r\n");
    411428        if (endHeaders)
    412429            out.write("\r\n");
Note: See TracChangeset for help on using the changeset viewer.