Package org.servalproject.servaldna

Examples of org.servalproject.servaldna.ServalDInterfaceException


  {
    try {
      return manifest.toTextFormat();
    }
    catch (RhizomeManifestSizeException e) {
      throw new ServalDInterfaceException("manifest text overflow", e);
    }
  }
View Full Code Here


      json.consume("rows");
      json.consume(JSONTokeniser.Token.COLON);
      json.consume(JSONTokeniser.Token.START_ARRAY);
    }
    catch (JSONInputException e) {
      throw new ServalDInterfaceException(e);
    }
  }
View Full Code Here

          (SubscriberId)row.get(".author"),
          (Integer)row.get(".fromhere")
        );
    }
    catch (JSONInputException e) {
      throw new ServalDInterfaceException(e);
    }
  }
View Full Code Here

  }

  protected static JSONTokeniser receiveRestfulResponse(HttpURLConnection conn, int[] expected_response_codes) throws IOException, ServalDInterfaceException, MeshMSException
  {
    if (!"application/json".equals(conn.getContentType()))
      throw new ServalDInterfaceException("unexpected HTTP Content-Type: " + conn.getContentType());
    if (conn.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
      JSONTokeniser json = new JSONTokeniser(new InputStreamReader(conn.getErrorStream(), "US-ASCII"));
      Status status = decodeRestfulStatus(json);
      throwRestfulResponseExceptions(status, conn.getURL());
      throw new ServalDInterfaceException("unexpected MeshMS status = " + status.meshms_status_code + ", \"" + status.meshms_status_message + "\"");
    }
    for (int code: expected_response_codes) {
      if (conn.getResponseCode() == code) {
        JSONTokeniser json = new JSONTokeniser(new InputStreamReader(conn.getInputStream(), "US-ASCII"));
        return json;
      }
    }
    throw new ServalDInterfaceException("unexpected HTTP response code: " + conn.getResponseCode());
  }
View Full Code Here

      json.consume(JSONTokeniser.Token.END_OBJECT);
      json.consume(JSONTokeniser.Token.EOF);
      return status;
    }
    catch (JSONInputException e) {
      throw new ServalDInterfaceException("malformed JSON status response", e);
    }
  }
View Full Code Here

              boolean read,
              long timestamp,
              Long ack_offset) throws ServalDInterfaceException
  {
    if (my_sid == null)
      throw new ServalDInterfaceException("my_sid is null");
    if (their_sid == null)
      throw new ServalDInterfaceException("their_sid is null");
    if (type != Type.ACK_RECEIVED && text == null)
      throw new ServalDInterfaceException("text is null");
    if (token == null)
      throw new ServalDInterfaceException("token is null");
    if (type == Type.ACK_RECEIVED && ack_offset == null)
      throw new ServalDInterfaceException("ack_offset is null");
    this._rowNumber = rowNumber;
    this.type = type;
    this.mySid = my_sid;
    this.theirSid = their_sid;
    this.offset = offset;
View Full Code Here

      json.consume("rows");
      json.consume(JSONTokeniser.Token.COLON);
      json.consume(JSONTokeniser.Token.START_ARRAY);
    }
    catch (JSONInputException e) {
      throw new ServalDInterfaceException(e);
    }
  }
View Full Code Here

      else if (typesym.equals("<"))
        type = MeshMSMessage.Type.MESSAGE_RECEIVED;
      else if (typesym.equals("ACK"))
        type = MeshMSMessage.Type.ACK_RECEIVED;
      else
        throw new ServalDInterfaceException("invalid column value: type=" + typesym);
      return new MeshMSMessage(
              rowCount++,
              type,
              (SubscriberId)row.get("my_sid"),
              (SubscriberId)row.get("their_sid"),
              (Long)row.get("offset"),
              (String)row.get("token"),
              (String)row.get("text"),
              (Boolean)row.get("delivered"),
              (Boolean)row.get("read"),
              (Long)row.get("timestamp"),
              (Long)row.get("ack_offset")
            );
    }
    catch (JSONInputException e) {
      throw new ServalDInterfaceException(e);
    }
  }
View Full Code Here

      json.consume("header");
      json.consume(JSONTokeniser.Token.COLON);
      headers = new Vector<String>();
      json.consumeArray(headers, String.class);
      if (headers.size() < 1)
        throw new ServalDInterfaceException("empty JSON headers array");
      for (int i = 0; i < headers.size(); ++i) {
        String header = headers.get(i);
        if (header.equals("_id"))
          columnIndex__id = i;
        else if (header.equals("my_sid"))
          columnIndex_my_sid = i;
        else if (header.equals("their_sid"))
          columnIndex_their_sid = i;
        else if (header.equals("read"))
          columnIndex_read = i;
        else if (header.equals("last_message"))
          columnIndex_last_message = i;
        else if (header.equals("read_offset"))
          columnIndex_read_offset = i;
      }
      if (columnIndex__id == -1)
        throw new ServalDInterfaceException("missing JSON column: _id");
      if (columnIndex_my_sid == -1)
        throw new ServalDInterfaceException("missing JSON column: my_sid");
      if (columnIndex_their_sid == -1)
        throw new ServalDInterfaceException("missing JSON column: their_sid");
      if (columnIndex_read == -1)
        throw new ServalDInterfaceException("missing JSON column: read");
      if (columnIndex_last_message == -1)
        throw new ServalDInterfaceException("missing JSON column: last_message");
      if (columnIndex_read_offset == -1)
        throw new ServalDInterfaceException("missing JSON column: read_offset");
      json.consume(JSONTokeniser.Token.COMMA);
      json.consume("rows");
      json.consume(JSONTokeniser.Token.COLON);
      json.consume(JSONTokeniser.Token.START_ARRAY);
    }
    catch (JSONInputException e) {
      throw new ServalDInterfaceException(e);
    }
  }
View Full Code Here

      SubscriberId my_sid;
      try {
        my_sid = new SubscriberId(JSONTokeniser.narrow(row[columnIndex_my_sid], String.class));
      }
      catch (SubscriberId.InvalidHexException e) {
        throw new ServalDInterfaceException("invalid column value: my_sid", e);
      }
      SubscriberId their_sid;
      try {
        their_sid = new SubscriberId(JSONTokeniser.narrow(row[columnIndex_their_sid], String.class));
      }
      catch (SubscriberId.InvalidHexException e) {
        throw new ServalDInterfaceException("invalid column value: their_sid", e);
      }
      boolean is_read = JSONTokeniser.narrow(row[columnIndex_read], Boolean.class);
      long last_message = JSONTokeniser.narrow(row[columnIndex_last_message], Long.class);
      long read_offset = JSONTokeniser.narrow(row[columnIndex_read_offset], Long.class);
      return new MeshMSConversation(rowCount++, _id, my_sid, their_sid, is_read, last_message, read_offset);
    }
    catch (JSONInputException e) {
      throw new ServalDInterfaceException(e);
    }
  }
View Full Code Here

TOP

Related Classes of org.servalproject.servaldna.ServalDInterfaceException

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.