Support Questions

Find answers, ask questions, and share your expertise
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

Java to Groovy for ExecuteScript processor

Hello forum,

I have Java code and I want to include it within the ExecuteScript processor,

This is the Java code, import
import java.util.Date
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeoutException
import org.apache.log4j.BasicConfigurator
import org.jsmpp.PDUStringException
import org.jsmpp.SMPPConstant
import org.jsmpp.bean.CancelSm
import org.jsmpp.bean.DataCoding
import org.jsmpp.bean.DataSm
import org.jsmpp.bean.DeliveryReceipt
import org.jsmpp.bean.ESMClass
import org.jsmpp.bean.GSMSpecificFeature
import org.jsmpp.bean.MessageMode
import org.jsmpp.bean.MessageType
import org.jsmpp.bean.NumberingPlanIndicator
import org.jsmpp.bean.QuerySm
import org.jsmpp.bean.RegisteredDelivery
import org.jsmpp.bean.ReplaceSm
import org.jsmpp.bean.SMSCDeliveryReceipt
import org.jsmpp.bean.SubmitMulti
import org.jsmpp.bean.SubmitMultiResult
import org.jsmpp.bean.SubmitSm
import org.jsmpp.bean.TypeOfNumber
import org.jsmpp.extra.ProcessRequestException
import org.jsmpp.session.BindRequest
import org.jsmpp.session.DataSmResult
import org.jsmpp.session.QuerySmResult
import org.jsmpp.session.SMPPServerSession
import org.jsmpp.session.SMPPServerSessionListener
import org.jsmpp.session.ServerMessageReceiverListener
import org.jsmpp.session.ServerResponseDeliveryAdapter
import org.jsmpp.session.Session
import org.jsmpp.util.DeliveryReceiptState
import org.jsmpp.util.MessageIDGenerator
import org.jsmpp.util.MessageId
import org.jsmpp.util.RandomMessageIDGenerator
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.jsmpp.*
import jsmpp.*
public class SMPPServerSimulator extends ServerResponseDeliveryAdapter implements Runnable, ServerMessageReceiverListener {
    private static final Integer DEFAULT_PORT = 8057
    private static final Logger logger = LoggerFactory.getLogger(SMPPServerSimulator.class)
    private final ExecutorService execService = Executors.newFixedThreadPool(5)
    private final ExecutorService execServiceDelReciept = Executors.newFixedThreadPool(100)
    private final MessageIDGenerator messageIDGenerator = new RandomMessageIDGenerator()
    private int port
    public SMPPServerSimulator(int port) {
        this.port = port
    public void run() {
        try {
            SMPPServerSessionListener sessionListener = new SMPPServerSessionListener(port)
  "Listening on port {}", port)
            while (true) {
                SMPPServerSession serverSession = sessionListener.accept()
      "Accepting connection for session {}", serverSession.getSessionId())
                execService.execute(new WaitBindTask(serverSession))
        } catch (IOException e) {
            logger.error("IO error occured", e)
    public QuerySmResult onAcceptQuerySm(QuerySm querySm,
        SMPPServerSession source) throws ProcessRequestException {"Accepting query sm, but not implemented")
        return null
    public MessageId onAcceptSubmitSm(SubmitSm submitSm,
        SMPPServerSession source) throws ProcessRequestException {
        MessageId messageId = messageIDGenerator.newMessageId()
        logger.debug("\nReceiving submit_sm {}, and return message id {}\n", new String(submitSm.getShortMessage()), messageId.getValue())
        if (SMSCDeliveryReceipt.SUCCESS.containedIn(submitSm.getRegisteredDelivery()) || SMSCDeliveryReceipt.SUCCESS_FAILURE.containedIn(submitSm.getRegisteredDelivery())) {
            execServiceDelReciept.execute(new DeliveryReceiptTask(source, submitSm, messageId))
         flowFile = session.create()
        flowFile = session.putAttribute(flowFile, 'myAttr', new String(submitSm.getShortMessage()))
        session.transfer(flowFile, REL_SUCCESS)

        System.out.println("Message Recieved: " +  new String(submitSm.getShortMessage()))
        return messageId
    public void onSubmitSmRespSent(MessageId messageId,
        SMPPServerSession source) {
        logger.debug("submit_sm_resp with message_id {} has been sent", messageId)
    public SubmitMultiResult onAcceptSubmitMulti(SubmitMulti submitMulti,
        SMPPServerSession source) throws ProcessRequestException {
        return null
    public DataSmResult onAcceptDataSm(DataSm dataSm, Session source)
    throws ProcessRequestException {
        return null
    public void onAcceptCancelSm(CancelSm cancelSm, SMPPServerSession source)
    throws ProcessRequestException {
    public void onAcceptReplaceSm(ReplaceSm replaceSm, SMPPServerSession source)
    throws ProcessRequestException {
    private class WaitBindTask implements Runnable {
        private final SMPPServerSession serverSession
        public WaitBindTask(SMPPServerSession serverSession) {
            this.serverSession = serverSession
        public void run() {
            try {
                BindRequest bindRequest = serverSession.waitForBind(1000)
      "Accepting bind for session {}", serverSession.getSessionId())
                try {
                } catch (PDUStringException e) {
                    logger.error("Invalid system id", e)
            } catch (IllegalStateException e) {
                logger.error("System error", e)
            } catch (TimeoutException e) {
                logger.warn("Wait for bind has reach timeout", e)
            } catch (IOException e) {
                logger.error("Failed accepting bind request for session {}", serverSession.getSessionId())
    private class DeliveryReceiptTask implements Runnable {
        private final SMPPServerSession session
        private final SubmitSm submitSm
        private MessageId messageId
        public DeliveryReceiptTask(SMPPServerSession session,
            SubmitSm submitSm, MessageId messageId) {
            this.session = session
            this.submitSm = submitSm
            this.messageId = messageId
        public void run() {
            try {
            } catch (InterruptedException e1) {
            String stringValue = Integer.valueOf(messageId.getValue(), 16).toString()
            try {
                DeliveryReceipt delRec = new DeliveryReceipt(stringValue, 1, 1, new Date(), new Date(), DeliveryReceiptState.DELIVRD, null, new String(submitSm.getShortMessage()))
                    new ESMClass(MessageMode.DEFAULT, MessageType.SMSC_DEL_RECEIPT, GSMSpecificFeature.DEFAULT),
                    (byte) 0,
                    (byte) 0,
                    new RegisteredDelivery(0),
                logger.debug("Sending delivery reciept for message id " + messageId + ":" + stringValue)
            } catch (Exception e) {
                logger.error("Failed sending delivery_receipt for message id " + messageId + ":" + stringValue, e)
    public static void main(String[] args) {
        int port
        try {
            port = Integer.parseInt(System.getProperty("jsmpp.simulator.port", DEFAULT_PORT.toString()))
        } catch (NumberFormatException e) {
            port = DEFAULT_PORT
        SMPPServerSimulator smppServerSim = new SMPPServerSimulator(port)


Processor is running with no errors but the results of the script is not as expected, (port 8057 should become ready to bind, Code acts as SMS GW server)

Any help please ?

Note that the above script is working if I execute it as groovy code from Netbeans IDE !


any help goros 🙂

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.