Java SMSLib:在没有路线之后,我该怎么办?

Java SMSLib:在没有路线之后,我该怎么办?,java,smslib,jsmpp,Java,Smslib,Jsmpp,我有一个Web服务,它接收一条要发送的短信。一条短信=一个HTTP呼叫 即: http://.../my-ws/?to=56998180333&body=blabla 此Web服务使用SMSLib,并附带一个JSMPPGateway: JSMPPGateway gateway = new JSMPPGateway(systemType, ip, port, new BindAttributes(username, password, "cp", BindType.TRANSMIT

我有一个Web服务,它接收一条要发送的短信。一条短信=一个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");
    }
}
这通常效果很好。
连接始终保持打开状态,短信通过该方法发送。如果应用程序空闲时间过长,它将启动一个新的http请求,连接将再次打开。没问题

问题在于sendMessage()之后outboundMessage没有refNo。
不会引发任何异常,它会随此日志返回:

ERR: Sending error. No RefNo was assigned after calling sendMessage<br>
getFailureCause(): NO_ROUTE<br>
getMessageStatus(): FAILED
ERR:发送错误。调用sendMessage后未分配参考号
getFailureCause():没有路由
getMessageStatus():失败
在该错误发生后,所有后续SMS都会抛出相同的NO_路由错误(所有发送调用)

我通过重新启动应用程序来解决这个问题(即,服务实例再次启动,JSMPPGateway再次创建和连接,等等)


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

我想您可以重新启动网关。在catch块获取网关的实例
AGateway gateway=Service.getInstance().getGateway(“您的网关”)gateway.stopGateway()
网关.startGateway()。如果调用正确,则当网关可用时,消息将位于要重新发送的服务队列中。你能确认一下吗?:-)我将尝试使用stopGateway和startGateway,但当我没有路由时,我的代码通过返回行存在,而不是通过异常存在。关于您的问题,smslib允许您使用sendMessage(outboundMessage)或queueMessage(outboundMessage)进行发送,这是异步的。谢谢:)哦,对不起,把你的密码和我的密码混在一起了。祝开始/停止好运:)在我之前的评论中,我所说的“存在”是指“退出”