Package org.smslib

Examples of org.smslib.GatewayException


    // Return a new generated message
    this.counter++;
    if ((this.failCycle > 0) && (this.counter >= this.failCycle))
    {
      this.counter = 0;
      throw new GatewayException("*** READ ERROR ***");
    }
    return generateIncomingMessage();
  }
View Full Code Here


        getModemDriver().write("AT+CMGS=\"_1_\"\r".replaceAll("\"_1_\"", "" + size));
        Thread.sleep(Service.getInstance().getSettings().AT_WAIT_CGMS);
        while (!getModemDriver().dataAvailable())
        {
          responseRetries++;
          if (responseRetries == Service.getInstance().getSettings().OUTBOUND_RETRIES) throw new GatewayException("Gateway is not responding, max number of retries reached.");
          Logger.getInstance().logWarn("ATHandler().SendMessage(): Still waiting for response (I) (" + responseRetries + ")...", null, getGateway().getGatewayId());
          Thread.sleep(Service.getInstance().getSettings().OUTBOUND_RETRY_WAIT);
        }
        responseRetries = 0;
        getModemDriver().clearBuffer();
        getModemDriver().write(pdu);
        getModemDriver().write((char) 26);
        response = getModemDriver().getResponse();
        while (response.length() == 0)
        {
          responseRetries++;
          if (responseRetries == Service.getInstance().getSettings().OUTBOUND_RETRIES) throw new GatewayException("Gateway is not responding, max number of retries reached.");
          Logger.getInstance().logWarn("ATHandler().SendMessage(): Still waiting for response (II) (" + responseRetries + ")...", null, getGateway().getGatewayId());
          Thread.sleep(Service.getInstance().getSettings().OUTBOUND_RETRY_WAIT);
          response = getModemDriver().getResponse();
        }
        if (getModemDriver().getLastError() == 0)
View Full Code Here

            response = getGateway().getATHandler().getSimStatus();
          }
          if (response.indexOf("SIM PIN2") >= 0)
          {
            Logger.getInstance().logDebug("SIM requesting PIN2.", null, getGateway().getGatewayId());
            if ((getGateway().getSimPin2() == null) || (getGateway().getSimPin2().length() == 0)) throw new GatewayException("The GSM modem requires SIM PIN2 to operate.");
            if (!getGateway().getATHandler().enterPin(getGateway().getSimPin2())) throw new GatewayException("SIM PIN2 provided is not accepted by the GSM modem.");
            Thread.sleep(Service.getInstance().getSettings().AT_WAIT_SIMPIN);
            continue;
          }
          else if (response.indexOf("SIM PIN") >= 0)
          {
            Logger.getInstance().logDebug("SIM requesting PIN.", null, getGateway().getGatewayId());
            if ((getGateway().getSimPin() == null) || (getGateway().getSimPin().length() == 0)) throw new GatewayException("The GSM modem requires SIM PIN to operate.");
            if (!getGateway().getATHandler().enterPin(getGateway().getSimPin())) throw new GatewayException("SIM PIN provided is not accepted by the GSM modem.");
            Thread.sleep(Service.getInstance().getSettings().AT_WAIT_SIMPIN);
            continue;
          }
          else if (response.indexOf("READY") >= 0) break;
          else if (response.indexOf("OK") >= 0) break;
          else if (response.indexOf("ERROR") >= 0)
          {
            Logger.getInstance().logWarn("Erroneous CPIN response, proceeding with defaults.", null, getGateway().getGatewayId());
            break;
          }
          Logger.getInstance().logWarn("Cannot understand SIMPIN response: " + response + ", will wait for a while...", null, getGateway().getGatewayId());
          Thread.sleep(Service.getInstance().getSettings().AT_WAIT_SIMPIN);
        }
        getGateway().getATHandler().echoOff();
        getGateway().getATHandler().init();
        getGateway().getATHandler().echoOff();
        if (!waitForNetworkRegistration()) Logger.getInstance().logWarn("Network Registration failed, proceeding with defaults.", null, getGateway().getGatewayId());
        getGateway().getATHandler().setVerboseErrors();
        if (getGateway().getATHandler().getStorageLocations().length() == 0)
        {
          try
          {
            getGateway().getATHandler().readStorageLocations();
            Logger.getInstance().logInfo("MEM: Storage Locations Found: " + getGateway().getATHandler().getStorageLocations(), null, getGateway().getGatewayId());
          }
          catch (Exception e)
          {
            getGateway().getATHandler().setStorageLocations("--");
            Logger.getInstance().logWarn("Storage locations could *not* be retrieved, will proceed with defaults.", e, getGateway().getGatewayId());
          }
        }
        if (!getGateway().getATHandler().setIndications())
        {
          Logger.getInstance().logWarn("Callback indications were *not* set succesfully!", null, getGateway().getGatewayId());
          getCnmiEmulationProcessor().enable();
        }
        else
        {
          if (getGateway().getATHandler().getIndications().getMode().equals("0")) getCnmiEmulationProcessor().enable();
        }
        if (getGateway().getProtocol() == Protocols.PDU)
        {
          if (!getGateway().getATHandler().setPduProtocol()) throw new GatewayException("The GSM modem does not support the PDU protocol.");
        }
        else if (getGateway().getProtocol() == Protocols.TEXT)
        {
          if (!getGateway().getATHandler().setTextProtocol()) throw new GatewayException("The GSM modem does not support the TEXT protocol.");
        }
      }
      catch (TimeoutException t)
      {
        try
View Full Code Here

            else if (m.group(1).equals("CMS"))
            {
              int code = Integer.parseInt(m.group(2));
              setLastError(6000 + code);
            }
            else throw new GatewayException("Invalid error response: " + m.group(1));
          }
          catch (NumberFormatException e)
          {
            Logger.getInstance().logDebug("Error on number conversion while interpreting response: ", null, getGateway().getGatewayId());
            throw new GatewayException("Cannot convert error code number.");
          }
        }
        else throw new GatewayException("Cannot match error code. Should never happen!");
      }
      else if (response.matches(rxPlainError)) setLastError(9000);
      else if (response.indexOf("OK") >= 0) setLastError(0);
      else setLastError(10000);
      Logger.getInstance().logDebug("RECV :" + formatLog(buffer.toString()), null, getGateway().getGatewayId());
View Full Code Here

      }
      switch (answer)
      {
        case 0:
          Logger.getInstance().logError("GSM: Auto-registration disabled!", null, getGateway().getGatewayId());
          throw new GatewayException("GSM Network Auto-Registration disabled!");
        case 1:
          Logger.getInstance().logInfo("GSM: Registered to home network.", null, getGateway().getGatewayId());
          return true;
        case 2:
          Logger.getInstance().logWarn("GSM: Not registered, searching for network...", null, getGateway().getGatewayId());
          if (++retries == 6) throw new GatewayException("GSM Network Registration failed, give up trying!");
          break;
        case 3:
          Logger.getInstance().logError("GSM: Network registration denied!", null, getGateway().getGatewayId());
          throw new GatewayException("GSM Network Registration denied!");
        case 4:
          Logger.getInstance().logError("GSM: Unknown registration error!", null, getGateway().getGatewayId());
          throw new GatewayException("GSM Network Registration error!");
        case 5:
          Logger.getInstance().logInfo("GSM: Registered to foreign network (roaming).", null, getGateway().getGatewayId());
          return true;
        case -1:
          Logger.getInstance().logInfo("GSM: Invalid CREG response.", null, getGateway().getGatewayId());
          throw new GatewayException("GSM: Invalid CREG response.");
      }
      Thread.sleep(Service.getInstance().getSettings().AT_WAIT_NETWORK);
    }
  }
View Full Code Here

      this.out = this.tc.getOutputStream();
      this.peeker = new Peeker();
    }
    catch (InvalidTelnetOptionException e)
    {
      throw new GatewayException("Unsupported telnet option for the selected IP connection.");
    }
  }
View Full Code Here

  public float queryBalance() throws TimeoutException, GatewayException, IOException, InterruptedException
  {
    URL url;
    List<HttpHeader> request = new ArrayList<HttpHeader>();
    List<String> response;
    if (this.sessionId == null) throw new GatewayException("Internal Clickatell Gateway error.");
    url = new URL((this.secure ? this.HTTPS : this.HTTP) + this.URL_BALANCE);
    request.add(new HttpHeader("session_id", this.sessionId, false));
    synchronized (this.SYNC_Commander)
    {
      response = HttpPost(url, request);
View Full Code Here

  public boolean queryCoverage(OutboundMessage msg) throws TimeoutException, GatewayException, IOException, InterruptedException
  {
    URL url;
    List<HttpHeader> request = new ArrayList<HttpHeader>();
    List<String> response;
    if (this.sessionId == null) throw new GatewayException("Internal Clickatell Gateway error.");
    url = new URL((this.secure ? this.HTTPS : this.HTTP) + this.URL_COVERAGE);
    request.add(new HttpHeader("session_id", this.sessionId, false));
    if (msg.getRecipient().charAt(0) == '+') request.add(new HttpHeader("msisdn", msg.getRecipient().substring(1), false));
    else request.add(new HttpHeader("msisdn", msg.getRecipient(), false));
    synchronized (this.SYNC_Commander)
View Full Code Here

  {
    URL url;
    List<HttpHeader> request = new ArrayList<HttpHeader>();
    List<String> response;
    int pos;
    if (this.sessionId == null) throw new GatewayException("Internal Clickatell Gateway error.");
    url = new URL((this.secure ? this.HTTPS : this.HTTP) + this.URL_QUERYMSG);
    request.add(new HttpHeader("session_id", this.sessionId, false));
    request.add(new HttpHeader("apimsgid", refNo, false));
    synchronized (this.SYNC_Commander)
    {
View Full Code Here

  void connect() throws GatewayException, IOException
  {
    try
    {
      if (!authenticate()) throw new GatewayException("Cannot authenticate to Clickatell.");
    }
    catch (MalformedURLException e)
    {
      throw new GatewayException("Internal Clickatell Gateway error.");
    }
  }
View Full Code Here

TOP

Related Classes of org.smslib.GatewayException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.