0

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.

DT7
  • 1,615
  • 12
  • 25
sports
  • 6,889
  • 11
  • 61
  • 121
  • I suppose you can just restart the gateway. Get the instance of you gateway at the catch block. `AGateway gateway = Service.getInstance().getGateway("Your Gateway");` Then you can call `gateway.stopGateway();` and `gateway.startGateway();`. If recall correctly the messages will be at the Service queue to be resent when the gateway is available. Can you confirm this? :-) – André Nov 14 '13 at 19:43
  • I will try with stopGateway and startGateway, but when I get NO_ROUTE my code exists through the return line and not through the exceptions. Respect to your question, smslib lets you send using sendMessage(outboundMessage) or using queueMessage(outboundMessage), which is async. Thank you :) – sports Nov 14 '13 at 19:46
  • Oh, pardon me, mixed your code with my code. Good luck with start/stop :) – André Nov 14 '13 at 19:53
  • In my previous comment, by "exists" I meant "exits" – sports Nov 14 '13 at 19:57

0 Answers0