/** * Initializes the gateway by starting the smslib service with a modem * gateway configured with the set properties. It is called after properties * are wired in. * * @throws Exception */ @PostConstruct void init() throws Exception { service = new Service(); modemGateway = new SerialModemGateway(modemId, comPort, baudRate, manufacturer, model); modemGateway.setOutbound(acceptOutgoing); if (acceptOutgoing) { service.setOutboundMessageNotification(this); } modemGateway.setInbound(acceptIncoming); if (acceptIncoming) { service.setInboundMessageNotification(this); } service.addGateway(modemGateway); service.startService(); }
/** * Tears down the gateway. This is called before the application shuts down. * * @throws Exception */ @PreDestroy void shutdown() throws Exception { service.stopService(); }
public void queueMessage(List<String> recipients, final String message) { for (String recipient : recipients) { OutboundMessage outboundMessage = getOutboundMessage(message, recipient); smslibService.queueMessage(outboundMessage); } }
private void registerListeners() { log.info("Register listeners"); smslibService.setOutboundMessageNotification(outboundMessageNotification); smslibService.setInboundMessageNotification(inboundMessageNotification); }
public void sendSMS(SMSMessage sm) throws AxisFault { if (service == null && !serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) { service = new Service(); gateway = new SerialModemGateway(gsmTransportOutDetails.getGatewayId(), gsmTransportOutDetails.getComPort(), gsmTransportOutDetails.getBaudRate(), gsmTransportOutDetails.getManufacturer(), try { this.service.addGateway(gateway); this.service.startService(); service.sendMessage(msg); } catch (Exception e) { throw new AxisFault(e.getMessage(), e);
return; service = new Service(); this.service.addGateway(gateway); this.service.startService(); serviceRepo.addService(gsmTransportInDetails.getGatewayId(), service); dispatcher = new GSMDispatcher(service , smsInManeger);
if (getStatus() == Status.Stopped) setStatus(Status.Terminated); this.httpServer.stop(); DequeueMasterQueue(); while (getCallbackManager().getQueueLoad() > 0) getCallbackManager().stop(); try
@PostConstruct public void connect() throws SMSLibException, IOException, InterruptedException { log.info("Start SMS Lib Service"); try { smslibService.startService(); } catch (SMSLibException | IOException | InterruptedException e) { log.error(e.getMessage()); } }
public void run() { while(keepPolling) { List<InboundMessage> arrayList = new ArrayList<InboundMessage>(); try { service.readMessages(arrayList, InboundMessage.MessageClasses.UNREAD) ; for(InboundMessage msg : arrayList) { SMSMessage sms =null; synchronized (this) { sms= new SMSMessage(msg.getOriginator(),null,msg.getText() ,SMSMessage.IN_MESSAGE); } smsManager.dispatchToAxis2(sms); //delete the message form inbox service.deleteMessage(msg); } } catch (Exception ex) { log.error("Error Occured while reading messages",ex); } try { Thread.sleep(pollInterval); } catch (InterruptedException e) { } } }
private void registerGateway() { log.info("Register JSMPP gateway"); try { JSMPPGateway jsmppGateway = new JSMPPGateway(GATEWAY_ID, jsmppMapper.getHost(), jsmppMapper.getPort(), jsmppMapper.getBindAttributes()); jsmppGateway.setSourceAddress(jsmppMapper.getSourceAddress()); jsmppGateway.setDestinationAddress(jsmppMapper.getDestinationAddress()); smslibService.addGateway(jsmppGateway); } catch (Exception e) { // This should never really happen as SmsLib service will always be in STOPPED state at this point. log.warn("Smpp gateway connection failed", e); } }
/** * Called when an incoming message is detected. It is responsible for * handing off incoming messages to the inbound message processor and * removing the message from the modem's memory. */ public void process(String gatewayId, MessageTypes msgType, InboundMessage msg) { // No requestId for inbound messages, using smslib id long msgId = msg.getMessageId(); if (log.isDebugEnabled()) log.debug("receiving inbound message: id=" + msgId); if (acceptIncoming && inboundService != null) { try { inboundService.processRequest(msg.getText(), msg .getOriginator(), false); service.deleteMessage(msg); if (log.isDebugEnabled()) log.debug("removed inbound message: id=" + msgId); } catch (Throwable t) { log.error("inbound message failure: id=" + msgId, t); } } }
@PreDestroy public void disconnect() throws SMSLibException, IOException, InterruptedException { log.info("Stop SMS Lib Service"); smslibService.stopService(); }
@SuppressWarnings("unchecked") public Set<GatewayResponse> sendMessage(GatewayRequest messageDetails) { String requestId = messageDetails.getRequestId(); if (log.isDebugEnabled()) log.debug("queueing outbound message: id=" + requestId); if (acceptOutgoing) { OutboundMessage message = new OutboundMessage(messageDetails .getRecipientsNumber(), messageDetails.getMessage()); // Use requestId for message id rather than generating another message.setId(requestId); service.queueMessage(message); String response = getSMSLibMessageStatus(message); Set<GatewayResponse> responses = messageHandler .parseMessageResponse(messageDetails, response); GatewayResponse responseObj = responses.iterator().next(); // Update status store with response status of sent message statusStore.updateStatus(requestId, responseObj.getResponseText()); return responses; } return null; }
public void stop() { try { dispatcher.stopPolling(); service.stopService(); if(serviceRepo.gatewayInUse(gsmTransportInDetails.getGatewayId())) { serviceRepo.removeService(gsmTransportInDetails.getGatewayId()); } if(serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) { serviceRepo.removeService(gsmTransportOutDetails.getGatewayId()); } } catch (Exception e) { log.error(e); } }