如何使用CloudHopper异步发送deliverSmResp。

huangapple go评论113阅读模式
英文:

how to send deliverSmResp with cloudhopper asynchrous

问题

希望大家在这个大流行病中都安好。

我收到了一个来自短信中心的短信,我想发送一个 deliver_sm_resp 给它。

我尝试像这样实现它:

@Override
public PduResponse firePduRequestReceived(PduRequest pduRequest) {
    logger.warn("***** BIND RECEIVER *****");
    DeliverSm sms = null;

    if ((pduRequest != null) && pduRequest.getName().equals("deliver_sm")) {
        sms = (DeliverSm) pduRequest;
    }	
    if ((pduRequest != null) && pduRequest.getName().equals("enquire_link")) {
        return pduRequest.createResponse();
    }
    if (sms != null && (int)sms.getDataCoding() == 0) {
        //message content is English
        logger.warn("***** New Message Received *****");
        logger.warn("From: " + sms.getSourceAddress().getAddress());
        logger.warn("To: " + sms.getDestAddress().getAddress());
        logger.warn("Content: " + new String(sms.getShortMessage()));

        DeliverSm deliver = new DeliverSm();
        deliver.setSourceAddress(sms.getSourceAddress());
        deliver.setDestAddress(sms.getDestAddress());
        deliver.setDataCoding(sms.getDataCoding());
        try {
            deliver.setShortMessage(sms.getShortMessage());
        } catch (SmppInvalidArgumentException e) {
            e.printStackTrace();
        }
        deliver.setSequenceNumber(sms.getSequenceNumber());
        //deliver.setCommandLength(sms.getCommandLength());
        deliver.setCommandStatus(sms.getCommandStatus());

        runDeliverSmRespSmppSessionHandler(session, deliver);

    }
    return super.firePduRequestReceived(pduRequest);
}

我异步调用 runDeliverSmRespSmppSessionHandler,像这样:

public class RunDeliverSmRespSmppSessionHandler extends DefaultSmppSessionHandler implements Runnable {
    .
    .
    .
    public void run() {        
        logger.info("welcome to deliver TestSmppSessionHandler RUN");

        sendRequestPdu(session, deliver);
    }
    private void sendRequestPdu(SmppSession session, DeliverSm deliver) {
        logger.info("welcome to deliver TestSmppSessionHandler sendRequestPdu");

        try {
            WindowFuture<Integer, PduRequest, PduResponse> future = session.sendRequestPdu(deliver, 10000, false);
            if (!future.await()) {
                logger.error("Failed to receive deliver_sm_resp within specified time");
            } else if (future.isSuccess()) {
                DeliverSmResp deliverSmResp = (DeliverSmResp) future.getResponse();
                logger.info("deliver_sm_resp: commandStatus [" + deliverSmResp.getCommandStatus() + "=" + deliverSmResp.getResultMessage() + "]");
            } else {
                logger.error("Failed to properly receive deliver_sm_resp: " + future.getCause());
            }
        } catch (Exception e) {
            logger.error("message catched in smDeliver : " + e.getMessage() + " get stackTrace : " + e.getStackTrace());
        }
    }
}

不幸的是,在 sendRequestPdu() 中,我遇到了这个错误:

04-04-2020 23:15:41 ERROR TestSmppSessionHandler:61 - Failed to receive deliver_sm_resp within specified time
04-04-2020 23:16:06 WARN  EnquireLinkTask:37 - Enquire link failed, executing reconnect: 
com.cloudhopper.smpp.type.SmppTimeoutException: Unable to accept offer within [10000 ms] (window full)
at com.cloudhopper.smpp.impl.DefaultSmppSession.sendRequestPdu(DefaultSmppSession.java:508)
at com.cloudhopper.smpp.impl.DefaultSmppSession.sendRequestAndGetResponse(DefaultSmppSession.java:464)

谢谢您的帮助。

英文:

hope everyone is fine with this pandemic.

I receive a sms from a SMSC, and i would like to send him a deliver_sm_resp.

I try to implement it like that :

@Override
public PduResponse firePduRequestReceived(PduRequest pduRequest) {
logger.warn(&quot;***** BIND RECEIVER *****&quot;);
DeliverSm sms = null;
if ((pduRequest != null) &amp;&amp; pduRequest.getName().equals(&quot;deliver_sm&quot;)) {
sms = (DeliverSm) pduRequest;
}	
if ((pduRequest != null) &amp;&amp; pduRequest.getName().equals(&quot;enquire_link&quot;)) {
return pduRequest.createResponse();
}
if ( sms !=null &amp;&amp; (int)sms.getDataCoding() == 0 ) {
//message content is English
logger.warn(&quot;***** New Message Received *****&quot;);
logger.warn(&quot;From: &quot; + sms.getSourceAddress().getAddress());
logger.warn(&quot;To: &quot; + sms.getDestAddress().getAddress());
logger.warn(&quot;Content: &quot; + new String(sms.getShortMessage()));
DeliverSm deliver = new DeliverSm();
deliver.setSourceAddress(sms.getSourceAddress());
deliver.setDestAddress(sms.getDestAddress());
deliver.setDataCoding(sms.getDataCoding());
try {
deliver.setShortMessage(sms.getShortMessage());
} catch (SmppInvalidArgumentException e) {
e.printStackTrace();
}
deliver.setSequenceNumber(sms.getSequenceNumber());
//deliver.setCommandLength(sms.getCommandLength());
deliver.setCommandStatus(sms.getCommandStatus());
runDeliverSmRespSmppSessionHandler(session, deliver);
}
return super.firePduRequestReceived(pduRequest);
}

i call runDeliverSmRespSmppSessionHandler asynchrously, like that :

    public class RunDeliverSmRespSmppSessionHandler extends DefaultSmppSessionHandler implements Runnable {
.
.
.
public void run() {        
logger.info(&quot;welcome to deliver TestSmppSessionHandler RUN&quot;);
sendRequestPdu(session, deliver);
}
private void sendRequestPdu(SmppSession session, DeliverSm deliver) {
logger.info(&quot;welcome to deliver TestSmppSessionHandler sendRequestPdu&quot;);
try {
WindowFuture&lt;Integer,PduRequest,PduResponse&gt; future = session.sendRequestPdu(deliver, 10000, false);
if (!future.await()) {
logger.error(&quot;Failed to receive deliver_sm_resp within specified time&quot;);
} else if (future.isSuccess()) {
DeliverSmResp deliverSmResp = (DeliverSmResp)future.getResponse();
logger.info(&quot;deliver_sm_resp: commandStatus [&quot; + deliverSmResp.getCommandStatus() + &quot;=&quot; + deliverSmResp.getResultMessage() + &quot;]&quot;);
} else {
logger.error(&quot;Failed to properly receive deliver_sm_resp: &quot; + future.getCause());
}
} catch (Exception e) {
logger.error(&quot;message catched in smDeliver : &quot;+e.getMessage()+&quot; get stackTrace : &quot;+e.getStackTrace());
}
}

Unfortunally, i had this error in sendRequestPdu():

04-04-2020 23:15:41 ERROR TestSmppSessionHandler:61 - Failed to receive deliver_sm_resp within specified time
04-04-2020 23:16:06 WARN  EnquireLinkTask:37 - Enquire link failed, executing reconnect: 
com.cloudhopper.smpp.type.SmppTimeoutException: Unable to accept offer within [10000 ms] (window full)
at com.cloudhopper.smpp.impl.DefaultSmppSession.sendRequestPdu(DefaultSmppSession.java:508)
at com.cloudhopper.smpp.impl.DefaultSmppSession.sendRequestAndGetResponse(DefaultSmppSession.java:464)

Thank you for your helping

答案1

得分: 0

发送响应以通知短信中心您已收到短信,您需要使用以下代码:
```java
private void sendResponsePdu(SmppSession session, DeliverSmResp deliver) {
logger.info("欢迎来到DeliverTestSmppSessionHandlerV2的sendResponsePdu");
try {
session.sendResponsePdu(deliver);
logger.info("成功发送消息交付响应!!!");
} catch (Exception e) {
logger.error("在smDeliver中捕获的消息:" + e.getMessage() + "获取堆栈跟踪:" + e.getStackTrace());
}

关于DeliverSmResp deliver,您可以像这样初始化:

            DeliverSmResp deliver_sm_resp = new DeliverSmResp();
            
            deliver_sm_resp.setCommandLength(17);
            deliver_sm_resp.setCommandStatus(sms.getCommandStatus());
            deliver_sm_resp.setSequenceNumber(sms.getSequenceNumber());
            deliver_sm_resp.setMessageId("");

<details>
<summary>英文:</summary>
to send a response to inform the SMSC than you received your SMS, you have to use 

private void sendResponsePdu(SmppSession session, DeliverSmResp deliver) {
logger.info("welcome to deliver TestSmppSessionHandlerV2 sendRequestPdu");

      try {
session.sendResponsePdu(deliver);
logger.info(&quot;message deliver response sent successfully !!!&quot;);
} catch (Exception e) {
logger.error(&quot;message catched in smDeliver : &quot;+e.getMessage()+&quot; get stackTrace : &quot;+e.getStackTrace());
}

About `DeliverSmResp deliver`, you can initialize like that :
        DeliverSmResp deliver_sm_resp = new DeliverSmResp();
deliver_sm_resp.setCommandLength(17);
deliver_sm_resp.setCommandStatus(sms.getCommandStatus());
deliver_sm_resp.setSequenceNumber(sms.getSequenceNumber());
deliver_sm_resp.setMessageId(&quot;&quot;);

</details>

huangapple
  • 本文由 发表于 2020年4月5日 05:23:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/61034979.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定