Search in sources :

Example 1 with SmppTimeoutException

use of com.cloudhopper.smpp.type.SmppTimeoutException in project smscgateway by RestComm.

the class TestSmppClient method createSession.

protected DefaultSmppSession createSession(Channel channel, SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, InterruptedException {
    TestSmppSession session = new TestSmppSession(SmppSession.Type.CLIENT, config, channel, sessionHandler, monitorExecutor);
    // add SSL handler
    if (config.isUseSsl()) {
        SslConfiguration sslConfig = config.getSslConfiguration();
        if (sslConfig == null)
            throw new IllegalStateException("sslConfiguration must be set");
        try {
            SslContextFactory factory = new SslContextFactory(sslConfig);
            SSLEngine sslEngine = factory.newSslEngine();
            sslEngine.setUseClientMode(true);
            channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_SSL_NAME, new SslHandler(sslEngine));
        } catch (Exception e) {
            throw new SmppChannelConnectException("Unable to create SSL session]: " + e.getMessage(), e);
        }
    }
    // add the thread renamer portion to the pipeline
    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");
    }
    // create the logging handler (for bytes sent/received on wire)
    SmppSessionLogger loggingHandler = new SmppSessionLogger(DefaultSmppSession.class.getCanonicalName(), config.getLoggingOptions());
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_LOGGER_NAME, loggingHandler);
    // add a writeTimeout handler after the logger
    if (config.getWriteTimeout() > 0) {
        WriteTimeoutHandler writeTimeoutHandler = new WriteTimeoutHandler(new org.jboss.netty.util.HashedWheelTimer(), /* writeTimeoutTimer */
        config.getWriteTimeout(), TimeUnit.MILLISECONDS);
        channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_WRITE_TIMEOUT_NAME, writeTimeoutHandler);
    }
    // add a new instance of a decoder (that takes care of handling frames)
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_PDU_DECODER_NAME, new SmppSessionPduDecoder(session.getTranscoder()));
    // create a new wrapper around a session to pass the pdu up the chain
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_WRAPPER_NAME, new SmppSessionWrapper(session));
    return session;
}
Also used : SmppSessionThreadRenamer(com.cloudhopper.smpp.channel.SmppSessionThreadRenamer) SSLEngine(javax.net.ssl.SSLEngine) SmppSessionPduDecoder(com.cloudhopper.smpp.channel.SmppSessionPduDecoder) SmppSessionWrapper(com.cloudhopper.smpp.channel.SmppSessionWrapper) WriteTimeoutHandler(org.jboss.netty.handler.timeout.WriteTimeoutHandler) DefaultSmppSession(com.cloudhopper.smpp.impl.DefaultSmppSession) SslHandler(org.jboss.netty.handler.ssl.SslHandler) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) SmppTimeoutException(com.cloudhopper.smpp.type.SmppTimeoutException) SmppChannelConnectException(com.cloudhopper.smpp.type.SmppChannelConnectException) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SmppSessionLogger(com.cloudhopper.smpp.channel.SmppSessionLogger) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) SmppChannelConnectException(com.cloudhopper.smpp.type.SmppChannelConnectException)

Example 2 with SmppTimeoutException

use of com.cloudhopper.smpp.type.SmppTimeoutException in project smscgateway by RestComm.

the class TestSmppSession method sendRequestPdu.

public WindowFuture<Integer, PduRequest, PduResponse> sendRequestPdu(PduRequest pdu, long timeoutMillis, boolean synchronous) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException {
    // assign the next PDU sequence # if its not yet assigned
    if (!pdu.hasSequenceNumberAssigned()) {
        pdu.setSequenceNumber(this.getSequenceNumber().next());
    }
    // encode the pdu into a buffer
    ChannelBuffer buffer;
    if (this.malformedPacket) {
        this.malformedPacket = false;
        buffer = this.testPduTranscoder.encode(pdu);
    } else {
        buffer = this.getTranscoder().encode(pdu);
    }
    WindowFuture<Integer, PduRequest, PduResponse> future = null;
    try {
        future = this.getSendWindow().offer(pdu.getSequenceNumber(), pdu, timeoutMillis, this.getConfiguration().getRequestExpiryTimeout(), synchronous);
    } catch (DuplicateKeyException e) {
        throw new UnrecoverablePduException(e.getMessage(), e);
    } catch (OfferTimeoutException e) {
        throw new SmppTimeoutException(e.getMessage(), e);
    }
    if (this.sessionHandler instanceof SmppSessionListener) {
        if (!((SmppSessionListener) this.sessionHandler).firePduDispatch(pdu)) {
            // logger.info("dispatched request PDU discarded: {}", pdu);
            // @todo probably throwing exception here is better solution?
            future.cancel();
            return future;
        }
    }
    // during the encoding process such as looking up the result message
    if (this.getConfiguration().getLoggingOptions().isLogPduEnabled()) {
        if (synchronous) {
        // logger.info("sync send PDU: {}", pdu);
        } else {
        // logger.info("async send PDU: {}", pdu);
        }
    }
    // write the pdu out & wait timeout amount of time
    ChannelFuture channelFuture = this.getChannel().write(buffer).await();
    // check if the write was a success
    if (!channelFuture.isSuccess()) {
        // the write failed, make sure to throw an exception
        throw new SmppChannelException(channelFuture.getCause().getMessage(), channelFuture.getCause());
    }
    return future;
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) PduRequest(com.cloudhopper.smpp.pdu.PduRequest) SmppTimeoutException(com.cloudhopper.smpp.type.SmppTimeoutException) PduResponse(com.cloudhopper.smpp.pdu.PduResponse) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) OfferTimeoutException(com.cloudhopper.commons.util.windowing.OfferTimeoutException) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) DuplicateKeyException(com.cloudhopper.commons.util.windowing.DuplicateKeyException) SmppSessionListener(com.cloudhopper.smpp.SmppSessionListener) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

SmppChannelException (com.cloudhopper.smpp.type.SmppChannelException)2 SmppTimeoutException (com.cloudhopper.smpp.type.SmppTimeoutException)2 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)2 DuplicateKeyException (com.cloudhopper.commons.util.windowing.DuplicateKeyException)1 OfferTimeoutException (com.cloudhopper.commons.util.windowing.OfferTimeoutException)1 SmppSessionListener (com.cloudhopper.smpp.SmppSessionListener)1 SmppSessionLogger (com.cloudhopper.smpp.channel.SmppSessionLogger)1 SmppSessionPduDecoder (com.cloudhopper.smpp.channel.SmppSessionPduDecoder)1 SmppSessionThreadRenamer (com.cloudhopper.smpp.channel.SmppSessionThreadRenamer)1 SmppSessionWrapper (com.cloudhopper.smpp.channel.SmppSessionWrapper)1 DefaultSmppSession (com.cloudhopper.smpp.impl.DefaultSmppSession)1 PduRequest (com.cloudhopper.smpp.pdu.PduRequest)1 PduResponse (com.cloudhopper.smpp.pdu.PduResponse)1 SslConfiguration (com.cloudhopper.smpp.ssl.SslConfiguration)1 SslContextFactory (com.cloudhopper.smpp.ssl.SslContextFactory)1 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)1 SmppChannelConnectException (com.cloudhopper.smpp.type.SmppChannelConnectException)1 SSLEngine (javax.net.ssl.SSLEngine)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1