SMSLib: After getting NO_ROUTE, what should I do?

[亡魂溺海] 提交于 2020-01-06 13:54:12

问题


I have a webservice that receives one SMS to be delivered. One SMS = one HTTP call.

That is: http://.../my-ws/?to=56998180333&body=blabla

This webservice uses SMSLib, with a JSMPPGateway attached to it:

        JSMPPGateway gateway = new JSMPPGateway(systemType, ip, port, new BindAttributes(username, password, "cp", BindType.TRANSMITTER));

        Service.getInstance().addGateway(gateway);

This is done once, because getInstance() acts like a singleton.

When I send SMS, I do it this way:

public void send(String toMobile, String body) {    
    if ( Service.getInstance().getServiceStatus() != ServiceStatus.STARTED ) {
        myLog.append("ERR: Sending error. Failed to get instance\n");
        return;
    }

    try  {
        OutboundMessage outboundMessage = new OutboundMessage(toMobile, body);
        Service.getInstance().sendMessage(outboundMessage);

        if (outboundMessage.getRefNo().equals("")){
            myLog.append("ERR: Sending error. No RefNo was assigned after calling sendMessage\n");
            myLog.append("getFailureCause(): "+ outboundMessage.getFailureCause() +"\n");
            myLog.append("getMessageStatus(): "+ outboundMessage.getMessageStatus() +"\n");

            return;
        }

        myLog.append("OK: sent, refNo "+ outboundMessage.getRefNo() +"\n");

    } catch (GatewayException e)  {
        myLog.append("ERR: Sending error. GatewayException: "+ e +"\n");
    }  catch (TimeoutException e) {
        myLog.append("ERR: Sending error. TimeoutException: "+ e +"\n");
    }  catch (IOException e) {
        myLog.append("ERR: Sending error. IOException: "+ e +"\n");
    } catch (InterruptedException e) {
        myLog.append("ERR: Sending error. InterruptedException: "+ e +"\n");
    } catch (Exception e) {
        myLog.append("ERR: Sending error. Exception: "+ e +"\n");
    }
}

This usually works fine.
The connection stays open all the time and SMS are delivered through that method. If the app is idle too long, it will start with a new http request and the connection will open again. No problem there.

The problem is when the outboundMessage has no refNo after sendMessage().
No exceptions are thrown and it returns with this log:

ERR: Sending error. No RefNo was assigned after calling sendMessage<br>
getFailureCause(): NO_ROUTE<br>
getMessageStatus(): FAILED

After that error happends, all following SMS throw the same NO_ROUTE error (all send invocations)

I solve this by rebooting the application (that is, the Service's instance starts again and the JSMPPGateway is created and attached again, etc).

Is there other better way of solving this? for example, rebooting only the JSMPPGateway connection, programatically.

来源:https://stackoverflow.com/questions/19986505/smslib-after-getting-no-route-what-should-i-do

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!