package server;

/** 
 * Server class for XML-RPC communication
 * @author Tinsae Ghilay
 *         from the example on
 *         https://www.tutorialspoint.com/xml-rpc/xml_rpc_examples.htm
 */

// import the org.apache.xmlrpc package
// it contains classes for XML-RPC client (and server) implementation
import org.apache.xmlrpc.webserver.WebServer;
import java.net.URL;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;

public class Server {

    private static String TAG = "Server";

    public static void main(String[] args) {

        try {

            // start XML-RPC server at port 8080
            WebServer server = new WebServer(8080);

            XmlRpcServer xmlRpcServer = server.getXmlRpcServer();

            PropertyHandlerMapping phm = new PropertyHandlerMapping();

            phm.addHandler("calculator", Executor.class);

            xmlRpcServer.setHandlerMapping(phm);

            server.start();

            System.out.println(TAG + ": Server started successfully.");

            System.out.println("Accepting requests. (Halt program to stop.)");

        } catch (Exception e) { // catch exceptions if problems occur
            System.err.println(TAG + ": " + e.getMessage());
        }
    }

}
