Changeset 22472 in osm


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'

Location:
applications/editors/josm/plugins/remotecontrol
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/remotecontrol/.project

    r9417 r22472  
    44        <comment></comment>
    55        <projects>
     6                <project>JOSM</project>
    67        </projects>
    78        <buildSpec>
  • applications/editors/josm/plugins/remotecontrol/CONTRIBUTION

    r9417 r22472  
    11Originally developed by Frederik Ramm <frederik@remote.org>. Add yourself
    22if you contribute.
     3
     4Stephan Knauss <osm@stephans-server.de>:
     5   added /version command to return protocol version
     6   added CORS headers for modern browsers, legacy browsers can use jsonp
  • applications/editors/josm/plugins/remotecontrol/build.xml

    r21706 r22472  
    2828       
    2929        <!-- set before publising -->
    30         <property name="commit.message" value="Changed the constructor signature of the plugin main class" />           
     30        <property name="commit.message" value="Added version info capable of jsonp. Also made header CORS aware" />             
    3131        <property name="plugin.main.version" value="2830" />
    3232       
  • 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.