SMSLib:收到NO_ROUTE后,我该怎么办?

时间:2013-11-14 19:23:43

标签: java smslib jsmpp

我有一个网络服务,可以收到一条短信。一条SMS =一条HTTP呼叫。

那是: http://.../my-ws/?to=56998180333&body=blabla

此Web服务使用SMSLib,并附加了JSMPPGateway:

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

        Service.getInstance().addGateway(gateway);

这样做一次,因为getInstance()就像一个单例。

当我发送短信时,我这样做:

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");
    }
}

这通常可以正常工作 连接始终保持打开状态,并通过该方法传递SMS。如果应用程序空闲时间太长,它将以新的http请求开始,连接将再次打开。没问题。

问题是当outboundMessage在sendMessage()之后没有refNo时 不会抛出任何异常,它会返回此日志:

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

发生错误后,以下所有SMS都会抛出相同的NO_ROUTE错误(所有发送调用)

我通过重新启动应用程序解决了这个问题(也就是说,Service的实例再次启动,JSMPPGateway又被创建并附加了,等等。)

还有其他更好的解决方法吗?,例如,以编程方式重新启动JSMPPGateway连接。

0 个答案:

没有答案