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 Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable); String name = sessionConfig.getName(); thread.setName("EnquireLink-" + name); return thread; } });
protected SmppSessionConfiguration createSessionConfiguration(BaseBind bindRequest) { SmppSessionConfiguration sessionConfiguration = new SmppSessionConfiguration(); sessionConfiguration.setName("SmppServerSession." + bindRequest.getSystemId() + "." + bindRequest.getSystemType()); sessionConfiguration.setSystemId(bindRequest.getSystemId()); sessionConfiguration.setPassword(bindRequest.getPassword()); sessionConfiguration.setSystemType(bindRequest.getSystemType()); sessionConfiguration.setBindTimeout(server.getConfiguration().getBindTimeout()); sessionConfiguration.setAddressRange(bindRequest.getAddressRange()); sessionConfiguration.setHost(ChannelUtil.getChannelRemoteHost(channel)); sessionConfiguration.setPort(ChannelUtil.getChannelRemotePort(channel)); sessionConfiguration.setInterfaceVersion(bindRequest.getInterfaceVersion()); sessionConfiguration.setLoggingOptions(loggingOptions); sessionConfiguration.setType(SmppBindType.TRANSCEIVER); } else if (bindRequest instanceof BindReceiver) { sessionConfiguration.setType(SmppBindType.RECEIVER); } else if (bindRequest instanceof BindTransmitter) { sessionConfiguration.setType(SmppBindType.TRANSMITTER); sessionConfiguration.setWindowSize(server.getConfiguration().getDefaultWindowSize()); sessionConfiguration.setWindowWaitTimeout(server.getConfiguration().getDefaultWindowWaitTimeout()); sessionConfiguration.setWindowMonitorInterval(server.getConfiguration().getDefaultWindowMonitorInterval()); sessionConfiguration.setRequestExpiryTimeout(server.getConfiguration().getDefaultRequestExpiryTimeout()); sessionConfiguration.setCountersEnabled(server.getConfiguration().isDefaultSessionCountersEnabled());
try { SmppSessionConfiguration config0 = new SmppSessionConfiguration(); config0.setWindowSize(esme.getWindowSize()); config0.setName(esme.getSystemId()); config0.setType(esme.getSmppBindType()); config0.setBindTimeout(esme.getClientBindTimeout()); config0.setHost(esme.getHost()); config0.setPort(esme.getPort()); config0.setConnectTimeout(esme.getConnectTimeout()); config0.setSystemId(esme.getSystemId()); config0.setPassword(esme.getPassword()); config0.setSystemType(esme.getSystemType()); config0.getLoggingOptions().setLogBytes(true); config0.setRequestExpiryTimeout(esme.getRequestExpiryTimeout()); config0.setWindowMonitorInterval(esme.getWindowMonitorInterval()); config0.setCountersEnabled(esme.isCountersEnabled()); config0.setAddressRange(addressRangeObj); SslConfiguration sslConfiguration = esme.getWrappedSslConfig(); config0.setUseSsl(true); config0.setSslConfiguration(sslConfiguration);
this.clientBootstrap = new DefaultSmppClient(Executors.newCachedThreadPool(), 1, this.monitorExecutor); this.sessionHandler = new ClientSmppSessionHandler(); this.smppConfig = new SmppSessionConfiguration(); this.smppConfig.setWindowSize(1); this.smppConfig.setName("SMSLib.Session.0"); this.smppConfig.setType(SmppBindType.TRANSCEIVER); this.smppConfig.setHost(this.hostAddress); this.smppConfig.setPort(this.hostPort); this.smppConfig.setConnectTimeout(this.timeout); this.smppConfig.setSystemId(this.username); this.smppConfig.setPassword(this.password); this.smppConfig.getLoggingOptions().setLogBytes(true); this.smppConfig.setRequestExpiryTimeout(30000); this.smppConfig.setWindowMonitorInterval(15000); this.smppConfig.setCountersEnabled(true); this.smppSession = this.clientBootstrap.bind(this.smppConfig, this.sessionHandler); this.enquireLinkResp = this.smppSession.enquireLink(new EnquireLink(), this.timeout);
protected DefaultSmppSession createSession(Channel channel, SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, InterruptedException { DefaultSmppSession session = new DefaultSmppSession(SmppSession.Type.CLIENT, config, channel, sessionHandler, monitorExecutor); logger.debug("Creating session with esme " + config.getSystemId()); if (config.isUseSsl()) { SslConfiguration sslConfig = config.getSslConfiguration(); if (sslConfig == null) throw new IllegalStateException("sslConfiguration must be set"); try { if (config.getName() != null) { channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_THREAD_RENAMER_NAME, new SmppSessionThreadRenamer(config.getName())); } else { logger.warn("Session configuration did not have a name set - skipping threadRenamer in pipeline"); SmppSessionLogger loggingHandler = new SmppSessionLogger(DefaultSmppSession.class.getCanonicalName(), config.getLoggingOptions()); channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_LOGGER_NAME, loggingHandler); if (config.getWriteTimeout() > 0) { WriteTimeoutHandler writeTimeoutHandler = new WriteTimeoutHandler(writeTimeoutTimer, config.getWriteTimeout(), TimeUnit.MILLISECONDS); channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_WRITE_TIMEOUT_NAME, writeTimeoutHandler);
public static void main(String[] args) throws SmppInvalidArgumentException { SmppSessionConfiguration sessionConfig = new SmppSessionConfiguration(); sessionConfig.setType(SmppBindType.TRANSCEIVER); sessionConfig.setHost("127.0.0.1"); sessionConfig.setPort(2775); sessionConfig.setSystemId("smppclient1"); sessionConfig.setPassword("password"); sessionConfig.setLoggingOptions(loggingOptions);
synchronized (this) { if (logger.isInfoEnabled()) { logger.info(String.format("Session created: Name=%s SystemId=%s", session.getConfiguration().getName(), session.getConfiguration().getSystemId())); Esme esme = this.esmeManagement.getEsmeByName(sessionConfiguration.getName()); sessionConfiguration.getSystemId(), sessionConfiguration.getHost(), sessionConfiguration.getPort(), sessionConfiguration.getType())); throw new SmppProcessingException(SmppConstants.STATUS_BINDFAIL); session.getConfiguration().getLoggingOptions().setLogBytes(false); session.getConfiguration().getLoggingOptions().setLogPdu(false);
protected BaseBind createBindRequest(SmppSessionConfiguration config) throws UnrecoverablePduException { BaseBind bind = null; if (config.getType() == SmppBindType.TRANSCEIVER) { bind = new BindTransceiver(); } else if (config.getType() == SmppBindType.RECEIVER) { bind = new BindReceiver(); } else if (config.getType() == SmppBindType.TRANSMITTER) { bind = new BindTransmitter(); } else { throw new UnrecoverablePduException("Unable to convert SmppSessionConfiguration into a BaseBind request"); } bind.setSystemId(config.getSystemId()); bind.setPassword(config.getPassword()); bind.setSystemType(config.getSystemType()); bind.setInterfaceVersion(config.getInterfaceVersion()); bind.setAddressRange(config.getAddressRange()); return bind; }
sessionConfiguration.getHost(), sessionConfiguration.getPort(), smppBindType); bindRequest.getSystemId(), sessionConfiguration.getHost(), sessionConfiguration.getPort(), smppBindType)); throw new SmppProcessingException(SmppConstants.STATUS_INVSYSID); sessionConfiguration.setAddressRange(bindRequestAddressRange); sessionConfiguration.setCountersEnabled(esme.isCountersEnabled()); sessionConfiguration.setName(esme.getName()); sessionConfiguration.setWriteTimeout(SmppManagement.getInstance().getSmppServerManagement().getWriteTimeout());
byte interfaceVersion = this.autoNegotiateInterfaceVersion(config.getInterfaceVersion()); threadRenamer.setThreadName(config.getName()); SmppSessionLogger loggingHandler = new SmppSessionLogger(DefaultSmppSession.class.getCanonicalName(), config.getLoggingOptions()); channel.getPipeline().addAfter(SmppChannelConstants.PIPELINE_SESSION_THREAD_RENAMER_NAME, SmppChannelConstants.PIPELINE_SESSION_LOGGER_NAME, loggingHandler); if (config.getWriteTimeout() > 0) { WriteTimeoutHandler writeTimeoutHandler = new WriteTimeoutHandler(writeTimeoutTimer, config.getWriteTimeout(), TimeUnit.MILLISECONDS); channel.getPipeline().addAfter(SmppChannelConstants.PIPELINE_SESSION_LOGGER_NAME, SmppChannelConstants.PIPELINE_SESSION_WRITE_TIMEOUT_NAME, writeTimeoutHandler);
@Override public void disableLogPdu() { this.configuration.getLoggingOptions().setLogPdu(false); } }
if (monitorExecutor != null && configuration.getWindowMonitorInterval() > 0) { this.sendWindow = new Window<Integer,PduRequest,PduResponse>(configuration.getWindowSize(), monitorExecutor, configuration.getWindowMonitorInterval(), this, configuration.getName() + ".Monitor"); } else { this.sendWindow = new Window<Integer,PduRequest,PduResponse>(configuration.getWindowSize()); this.serverSessionId = null; this.preparedBindResponse = null; if (configuration.isCountersEnabled()) { this.counters = new DefaultSmppSessionCounters();
future = sendWindow.offer(pdu.getSequenceNumber(), pdu, timeoutMillis, configuration.getRequestExpiryTimeout(), synchronous); } catch (DuplicateKeyException e) { throw new UnrecoverablePduException(e.getMessage(), e); if (configuration.getLoggingOptions().isLogPduEnabled()) { if (synchronous) { logger.info("sync send PDU: {}", pdu);
@Override public String getSystemId() { return this.configuration.getSystemId(); }
public void sessionDestroyed(SmppSession session) { synchronized (this) { if (logger.isInfoEnabled()) { logger.info(String.format("Session destroyed: %s", session.getConfiguration().getSystemId())); } // print out final stats if (session.hasCounters()) { logger.info(String.format("final session rx-submitSM: %s", session.getCounters().getRxSubmitSM())); } // remove esmeServer out of enquire list String esmeName = session.getConfiguration().getName(); Esme esmeServer = this.esmeManagement.getEsmeByName(esmeName); esmeServer.setServerBound(false); esmeServer.resetEnquireLinkFail(); this.smppServerOpsThread.removeEnquireList(esmeName); DefaultSmppSession defaultSession = (DefaultSmppSession) session; // firing of onPduRequestTimeout() for sent messages for which we do not have responses Window<Integer, PduRequest, PduResponse> wind = defaultSession.getSendWindow(); Map<Integer, WindowFuture<Integer, PduRequest, PduResponse>> futures = wind.createSortedSnapshot(); for (WindowFuture<Integer, PduRequest, PduResponse> future : futures.values()) { this.logger.warn("Firing of onPduRequestTimeout from DefaultSmppServerHandler.sessionDestroyed(): " + future.getRequest().toString()); defaultSession.expired(future); } // make sure it's really shutdown session.destroy(); } }
@Override public SmppSession bind(SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, SmppBindException, UnrecoverablePduException, InterruptedException { DefaultSmppSession session = null; try { // connect to the remote system and create the session logger.debug("Connecting to remote system " + config.getName() + " host " + config.getHost() + ":" + config.getPort()); session = doOpen(config, sessionHandler); // try to bind to the remote system (may throw an exception) logger.debug("Binding to remote system " + config.getName()); doBind(session, config, sessionHandler); logger.debug("Successfully bound to " + config.getName()); } finally { // close the session if we weren't able to bind correctly if (session != null && !session.isBound()) { // make sure that the resources are always cleaned up try { logger.debug("Closing session - not able to bind to " + config.getName()); session.close(); } catch (Exception e) { logger.debug("Exception while trying to close connection to " + config.getName(), e); } } } return session; }
@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()); }
protected void doBind(DefaultSmppSession session, SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, SmppBindException, UnrecoverablePduException, InterruptedException { // create the bind request we'll use (may throw an exception) BaseBind bindRequest = createBindRequest(config); BaseBindResp bindResp = null; try { // attempt to bind to the SMSC // session implementation handles error checking, version negotiation, and can be discarded bindResp = session.bind(bindRequest, config.getBindTimeout()); logger.debug("Bound to esme systemId=" + config.getSystemId()); } catch (RecoverablePduException e) { // if a bind fails, there really is no recovery... throw new UnrecoverablePduException(e.getMessage(), e); } }
@Override public void sessionBindRequested(Long sessionId, SmppSessionConfiguration sessionConfiguration, final BaseBind bindRequest) throws SmppProcessingException { if (this.frm.getSmppSession() != null) { throw new SmppProcessingException(SmppConstants.STATUS_INVBNDSTS); } // sessionConfiguration.setAddressRange(bindRequestAddressRange); // // sessionConfiguration.setCountersEnabled(esme.isCountersEnabled()); sessionConfiguration.setName("Test SMPP session"); }