package ru.headhunter.smsengine.server;
import org.apache.log4j.Logger;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.ServletHttpContext;
import ru.headhunter.smsengine.SerialPortSMSTransport;
/**
* <p>The launcher class for SMS Engine service.<p>
* <p>Usage: <code>SMSEngineServer <comm-port> <http-port></code></p>
* <p><comm-port> - communication port at which GSM modem connected<br/>
* <http-port> - HTTP port of SMS service</p>
* <p>The URL of Hessian service: <code>http://host:http-port/sms-engine/service</code>
* Also there is URL of controller page: <code>http://host:http-port/sms-engine/controller</code></p>
* @author alsor
*/
public class SMSEngineServer {
private static Logger log = Logger.getLogger(SMSEngineServer.class);
private static Server server;
private static SerialPortSMSTransport engine;
public static SerialPortSMSTransport getEngine() {
return engine;
}
public static void main (String[] args) throws Exception {
if (args.length < 2) {
System.out.println("Usage: SMSEngineServer comm-port http-port");
return;
}
engine = new SerialPortSMSTransport(args[0]);
try {
engine.openPort ();
} catch (Exception e) {
return;
}
engine.start();
server = new Server();
server.addListener(args[1]);
ServletHttpContext context = (ServletHttpContext)server.getContext("/sms-engine");
context.addServlet("SMSEngineServiceController", "/controller", "ru.headhunter.smsengine.server.SMSEngineServiceController");
context.addServlet("SMSEngineService", "/service", "ru.headhunter.smsengine.server.SMSEngineService");
server.start();
}
public static void shutdown() {
engine.shutdown();
try {
server.stop();
} catch (InterruptedException e) {
log.warn("Jetty server stop exception", e);
}
}
}