public void doIt() throws Exception { OutboundNotification outboundNotification = new OutboundNotification(); InboundNotification inboundNotification = new InboundNotification(); System.out.println("Example: Send message from a serial gsm modem."); System.out.println(Library.getLibraryDescription()); System.out.println("Version: " + Library.getLibraryVersion()); SerialModemGateway gateway = new SerialModemGateway("modem.com5", "COM5", 460800, "MobiData", ""); gateway.setInbound(true); gateway.setOutbound(true); gateway.setSimPin(""); // Explicit SMSC address set is required for some modems. // Below is for VODAFONE GREECE - be sure to set your own!--- i set my own gateway.setSmscNumber("+8801700000600"); Service.getInstance().setOutboundMessageNotification(outboundNotification); Service.getInstance().setInboundMessageNotification(inboundNotification); Service.getInstance().addGateway(gateway); Service.getInstance().startService(); System.out.println(); System.out.println("Modem Information:"); System.out.println(" Manufacturer: " + gateway.getManufacturer()); System.out.println(" Model: " + gateway.getModel()); System.out.println(" Serial No: " + gateway.getSerialNo()); System.out.println(" SIM IMSI: " + gateway.getImsi()); System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm"); System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%"); System.out.println(); // Send a message synchronously. // OutboundMessage msg = new OutboundMessage("+8801718847772", "Hello from SMSLib!"); // Service.getInstance().sendMessage(msg); System.out.println("log1"); // System.out.println(msg); System.out.println("log2"); // Or, send out a WAP SI message. // OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000", new // URL("http://www.smslib.org/"), "Visit SMSLib now!"); // Service.getInstance().sendMessage(wapMsg); // System.out.println(wapMsg); // You can also queue some asynchronous messages to see how the callbacks // are called... // msg = new OutboundMessage("309999999999", "Wrong number!"); // srv.queueMessage(msg, gateway.getGatewayId()); // msg = new OutboundMessage("308888888888", "Wrong number!"); // srv.queueMessage(msg, gateway.getGatewayId()); System.out.println("Now Sleeping - Hit <enter> to terminate."); System.in.read(); Service.getInstance().stopService(); }
public void doIt() throws Exception { System.out.println("Example: Send an encrypted message from a serial gsm modem."); System.out.println(Library.getLibraryDescription()); System.out.println("Version: " + Library.getLibraryVersion()); SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM5", 57600, "Nokia", "E60"); gateway.setInbound(true); gateway.setOutbound(true); gateway.setSimPin("0000"); Service.getInstance().addGateway(gateway); Service.getInstance().startService(); System.out.println(); System.out.println("Modem Information:"); System.out.println(" Manufacturer: " + gateway.getManufacturer()); System.out.println(" Model: " + gateway.getModel()); System.out.println(" Serial No: " + gateway.getSerialNo()); System.out.println(" SIM IMSI: " + gateway.getImsi()); System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm"); System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%"); System.out.println(); // Create a new AES Key with a known key value. // Register it in KeyManager in order to keep it active. SMSLib will then automatically // encrypt / decrypt all messages send to / received from this number. Service.getInstance() .getKeyManager() .registerKey( "+306948494037", new AESKey(new SecretKeySpec("0011223344556677".getBytes(), "AES"))); OutboundEncryptedMessage msg = new OutboundEncryptedMessage("+306948494037", "Hello (encrypted) from SMSLib!".getBytes()); Service.getInstance().sendMessage(msg); System.out.println(msg); System.out.println("Now Sleeping - Hit <enter> to terminate."); System.in.read(); Service.getInstance().stopService(); }
// <editor-fold defaultstate="collapsed" desc=" Load Configuration from DHIS2 HOME "> private String loadConfiguration() throws Exception { String configFile = System.getenv("DHIS2_HOME") + File.separator + "SMSServer.conf"; if (new File(configFile).exists()) { Collection<AGateway> existingGateways = new ArrayList<AGateway>(); existingGateways.addAll(Service.getInstance().getGateways()); // Remove all existing gateways for (AGateway gateway : existingGateways) { Service.getInstance().removeGateway(gateway); } // Load properties from configuration file FileInputStream f = new FileInputStream(configFile); this.props = new Properties(); getProperties().load(f); f.close(); // Add gateway to service based on configuration file // <editor-fold defaultstate="collapsed" desc=" Get Gateway & Configuration "> for (int i = 0; i < Integer.MAX_VALUE; i++) { try { String propName = "gateway." + i; String propValue = getProperties().getProperty(propName, "").trim(); if (propValue.length() == 0) { break; } String modemName = propValue.split("\\,")[0].trim(); if (modemName.contains("bulksms")) { String username = getProperties().getProperty("bulksms.username"); String password = getProperties().getProperty("bulksms.password"); BulkSmsHTTPGateway gateway = new BulkSmsHTTPGateway("bulksms.http.1", username, password); gateway.setOutbound(true); gateway.setInbound(true); Service.getInstance().addGateway(gateway); } else if (modemName.contains("clickatell")) { String username = getProperties().getProperty("clickatell.username"); String password = getProperties().getProperty("clickatell.password"); String api_id = getProperties().getProperty("clickatell.api_id"); DhisClickatellGateway gateway = new DhisClickatellGateway("clickatell.http.1", api_id, username, password); gateway.setOutbound(true); gateway.setInbound(true); Service.getInstance().addGateway(gateway); } else { String port = getProperties().getProperty(modemName + ".port"); int baudRate = Integer.parseInt(getProperties().getProperty(modemName + ".baudrate")); String manufacturer = getProperties().getProperty(modemName + ".manufacturer"); String model = getProperties().getProperty(modemName + ".model"); String protocol = getProperties().getProperty(modemName + ".protocol"); String pin = getProperties().getProperty(modemName + ".pin"); String inbound = getProperties().getProperty(modemName + ".inbound"); String outbound = getProperties().getProperty(modemName + ".outbound"); String simMemLocation = getProperties().getProperty(modemName + ".simMemLocation"); // TODO: DETECT MODEM CLASS AND INSTANTIATE SerialModemGateway gateway = new SerialModemGateway(modemName, port, baudRate, manufacturer, model); if (simMemLocation != null && !simMemLocation.equals("-")) { gateway.getATHandler().setStorageLocations(simMemLocation); } if (protocol != null && protocol.equalsIgnoreCase("PDU")) { gateway.setProtocol(Protocols.PDU); } else { if (protocol != null && protocol.equalsIgnoreCase("TEXT")) { gateway.setProtocol(Protocols.TEXT); } else { gateway.setProtocol(Protocols.PDU); } } if (pin != null) { gateway.setSimPin(pin); } if (inbound.equalsIgnoreCase("yes")) { gateway.setInbound(true); } else { gateway.setInbound(false); } if (outbound.equalsIgnoreCase("yes")) { gateway.setOutbound(true); } else { gateway.setOutbound(false); } Service.getInstance().addGateway(gateway); } Logger.getInstance() .logInfo("Load Configuration: added gateway " + i + " / ", null, null); } catch (Exception e) { Logger.getInstance() .logError( "Load Configuration: Unknown Gateway in configuration file!, " + e.getMessage(), null, null); } } // </editor-fold> return "SUCCESSFULLY STARTED SERVICE"; } else { return "ERROR LOADING CONFIGURATION FILE"; } }