private void destroySession() { if (smppSession != null) { LOGGER.info("Cleaning up SMPP session... "); smppSession.destroy(); smppSession = null; } }
@Override public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable); String name = sessionConfig.getName(); thread.setName("EnquireLink-" + name); return thread; } });
@Override public void run() { SmppSession smppSession = smppClient.getSession(); if (smppSession != null && smppSession.isBound()) { try { smppSession.enquireLink(new EnquireLink(), enquireLinkTimeout); } catch (SmppTimeoutException | SmppChannelException | RecoverablePduException | UnrecoverablePduException error) { LOGGER.warn("Enquire link failed, executing reconnect: ", error); smppClient.scheduleReconnect(); } catch (InterruptedException error) { LOGGER.info("Enquire link interrupted, probably killed by reconnecting"); } } else { LOGGER.warn("Enquire link running while session is not connected"); } }
public SmppClient() { sessionConfig.setName("Traccar.smppSession"); sessionConfig.setInterfaceVersion( (byte) Context.getConfig().getInteger("sms.smpp.version", SmppConstants.VERSION_3_4)); sessionConfig.setType(SmppBindType.TRANSCEIVER); sessionConfig.setHost(Context.getConfig().getString("sms.smpp.host", "localhost")); sessionConfig.setPort(Context.getConfig().getInteger("sms.smpp.port", 2775)); sessionConfig.setSystemId(Context.getConfig().getString("sms.smpp.username", "user")); sessionConfig.setSystemType(Context.getConfig().getString("sms.smpp.systemType", null)); sessionConfig.setPassword(Context.getConfig().getString("sms.smpp.password", "password")); sessionConfig.getLoggingOptions().setLogBytes(false); sessionConfig.getLoggingOptions().setLogPdu(Context.getConfig().getBoolean("sms.smpp.logPdu"));
@Override public synchronized void sendMessageSync(String destAddress, String message, boolean command) throws MessageException, InterruptedException, IllegalStateException { if (getSession() != null && getSession().isBound()) { try { SubmitSm submit = new SubmitSm(); byte[] textBytes; textBytes = CharsetUtil.encode(message, command ? commandsCharsetName : notificationsCharsetName); submit.setDataCoding(command ? commandsDataCoding : notificationsDataCoding); if (requestDlr) { submit.setRegisteredDelivery(SmppConstants.REGISTERED_DELIVERY_SMSC_RECEIPT_REQUESTED); submit.addOptionalParameter(new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, textBytes, "message_payload")); } else { submit.setShortMessage(textBytes); submit.setSourceAddress(command ? new Address(commandSourceTon, commandSourceNpi, commandSourceAddress) : new Address(sourceTon, sourceNpi, sourceAddress)); submit.setDestAddress(new Address(destTon, destNpi, destAddress)); SubmitSmResp submitResponce = getSession().submit(submit, submitTimeout); if (submitResponce.getCommandStatus() == SmppConstants.STATUS_OK) { LOGGER.info("SMS submitted, message id: " + submitResponce.getMessageId()); } else { throw new IllegalStateException(submitResponce.getResultMessage()); throw new MessageException(new SmppChannelException("SMPP session is not connected"));
@SuppressWarnings("rawtypes") @Override public void sessionBindRequested(Long sessionId, SmppSessionConfiguration sessionConfiguration, final BaseBind bindRequest) throws SmppProcessingException { // test name change of sessions // this name actually shows up as thread context.... sessionConfiguration.setName("Application.SMPP." + sessionConfiguration.getSystemId()); }
@Override public void sessionDestroyed(Long sessionId, SmppServerSession session) { this.frm.addMessage("Session destroyed", session.getConfiguration().getSystemId()); this.frm.setSmppSession(null); session.destroy(); }
@Override public String getSystemId() { return this.configuration.getSystemId(); }
protected byte autoNegotiateInterfaceVersion(byte requestedInterfaceVersion) { if (!this.configuration.isAutoNegotiateInterfaceVersion()) { return requestedInterfaceVersion; } else { if (requestedInterfaceVersion >= SmppConstants.VERSION_3_4) { return SmppConstants.VERSION_3_4; } else { // downgrade to 3.3 return SmppConstants.VERSION_3_3; } } }
@Override public void firePduRequestExpired(PduRequest pduRequest) { this.wrappedSmppSessionHandler.firePduRequestExpired(pduRequest); }
public void setSslConfiguration(SslConfiguration value) { this.sslConfiguration = value; setUseSsl(true); }
@Override public int getMaxConnectionSize() { return this.configuration.getMaxConnectionSize(); }
@Override public boolean isWindowMonitorEnabled() { return (this.monitorExecutor != null && this.configuration.getWindowMonitorInterval() > 0); }
@Override public long getWindowWaitTimeout() { return this.configuration.getWindowWaitTimeout(); }
@Override public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable); String name = sessionConfig.getName(); thread.setName("Reconnection-" + name); return thread; } });
protected byte autoNegotiateInterfaceVersion(byte requestedInterfaceVersion) { if (!this.configuration.isAutoNegotiateInterfaceVersion()) { return requestedInterfaceVersion; } else { if (requestedInterfaceVersion >= SmppConstants.VERSION_3_4) { return SmppConstants.VERSION_3_4; } else { // downgrade to 3.3 return SmppConstants.VERSION_3_3; } } }
@Override public int getMaxConnectionSize() { return this.configuration.getMaxConnectionSize(); }
@Override public long getWindowMonitorInterval() { return this.configuration.getWindowMonitorInterval(); }
protected byte autoNegotiateInterfaceVersion(byte requestedInterfaceVersion) { if (!this.configuration.isAutoNegotiateInterfaceVersion()) { return requestedInterfaceVersion; } else { if (requestedInterfaceVersion >= SmppConstants.VERSION_3_4) { return SmppConstants.VERSION_3_4; } else { // downgrade to 3.3 return SmppConstants.VERSION_3_3; } } }
protected byte autoNegotiateInterfaceVersion(byte requestedInterfaceVersion) { if (!this.configuration.isAutoNegotiateInterfaceVersion()) { return requestedInterfaceVersion; } else { if (requestedInterfaceVersion >= SmppConstants.VERSION_3_4) { return SmppConstants.VERSION_3_4; } else { // downgrade to 3.3 return SmppConstants.VERSION_3_3; } } }