private OutboundMessage getOutboundMessage(String message, String recipient) { OutboundMessage outboundMessage = new OutboundMessage(); outboundMessage.setRecipient(recipient); outboundMessage.setStatusReport(Boolean.valueOf(smppSettings.getProperty(DELIVERY_REPORTS))); outboundMessage.setText(message); outboundMessage.setGatewayId(GATEWAY_ID); return outboundMessage; } }
@Override public void process(AGateway gateway, OutboundMessage msg) { log.info(String.format("[%s] Outbound notification for (%s) with message (%s) received from gateway (%s)", msg.getMessageStatus().toString(), msg.getRecipient(), msg.getText(), gateway.getGatewayId())); DateTime sentTime = newDateTime(msg.getDate()); if (sendingFailed(msg)) { if (msg.getRetryCount() >= maxRetries) { raiseFailureEvent(msg, sentTime); } else if (msg.getRetryCount() < maxRetries) { smsAuditService.log(new SmsRecord(OUTBOUND, msg.getRecipient(), msg.getText(), sentTime, KEEPTRYING, msg.getRefNo())); } } else { smsAuditService.log(new SmsRecord(SMSType.OUTBOUND, msg.getRecipient(), msg.getText(), sentTime, DeliveryStatus.DISPATCHED, msg.getRefNo())); } }
PingRequest(PingRequestId id, long timeout, int retries, Logger logger, PingResponseCallback cb) { m_id = id; m_retries = retries; m_timeout = timeout; m_log = logger; m_callback = cb; m_expiration = System.currentTimeMillis() + timeout; m_request = new OutboundMessage(id.getDestination(), "ping"); m_request.setSrcPort(6996); m_request.setValidityPeriod(1); }
/** * <p>sendSms</p> * * @param gatewayId a {@link java.lang.String} object. * @param recipient a {@link java.lang.String} object. * @param text a {@link java.lang.String} object. * @param validityPeriodInHours a int. * @param responseHandler a {@link org.opennms.sms.reflector.smsservice.MobileMsgResponseHandler} object. */ public void sendSms(String gatewayId, String recipient, String text, int validityPeriodInHours, MobileMsgResponseHandler responseHandler) { MobileMsgRequest request = null; try { OutboundMessage msg = new OutboundMessage(substitute(recipient), substitute(text)); msg.setGatewayId(substitute(gatewayId)); msg.setValidityPeriod(validityPeriodInHours); request = m_tracker.sendSmsRequest(msg, getTimeout(), getRetries(), responseHandler, responseHandler); } catch (Throwable e) { responseHandler.handleError(request, e); } }
private void sendPong(AGateway gateway, InboundMessage msg) { String pongResponse = (isCanonicalPingRequest(msg)) ? "pong" : getPseudoPongResponse(msg); LOG.debug("SmsPonger.sendPong: sending string '{}'", pongResponse); try { OutboundMessage pong = new OutboundMessage(msg.getOriginator(), pongResponse); pong.setGatewayId(gateway.getGatewayId()); if (!gateway.sendMessage(pong)) { LOG.error("Failed to send pong request to {}", msg.getOriginator()); } } catch (TimeoutException e) { LOG.error("Timeout sending pong request to {}", msg.getOriginator(), e); } catch (GatewayException e) { LOG.error("Gateway exception sending pong request to {}", msg.getOriginator(), e); } catch (IOException e) { LOG.error("IOException sending pong request to {}", msg.getOriginator(), e); } catch (InterruptedException e) { LOG.error("InterruptedException sending poing request to {}", msg.getOriginator(), e); } }
@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; }
OutboundMessage msg = new OutboundMessage(sm.getReceiver(), sm.getContent()); try {
/** * Converts the state of an SMSLib message to a string that can be mapped to * the motech-mobile MStatus values. * * @param msg * @return */ private String getSMSLibMessageStatus(OutboundMessage msg) { MessageStatuses msgStatus = msg.getMessageStatus(); String responseString = msgStatus.toString(); if (msgStatus == MessageStatuses.FAILED) { responseString = "ERROR_" + msg.getFailureCause().toString(); } return responseString; }
private boolean sendingFailed(OutboundMessage msg) { return msg.getMessageStatus().equals(OutboundMessage.MessageStatuses.FAILED); } }