java.lang.Object
edu.internet2.ndt.Protocol

public class Protocolextends Object
Class aggregating operations that can be performed for sending/receiving/reading Protocol messages.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final InputStream
    Control messages read from the test server.
    private final OutputStream
    Control messages sent to the test server.
    private boolean
    True when the server supports JSON output.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Protocol(Socket ctlSocketParam)
    Constructor that accepts socket over which to communicate as parameter.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    void
    Method to close open Streams.
    int
    readn(Message msgParam, int iParamAmount)
    Populate Message byte array with specific number of bytes of data from socket input stream.
    int
    recv_msg(Message msgParam)
    Receive message at end-point of socket.
    void
    send_json_login_msg(byte bParamType, byte[] bParamToSend)
    Send protocol messages given their type and data byte array.
    void
    send_json_msg(byte bParamType, byte bParamToSend)
    Send message given its Type and data byte.
    void
    send_json_msg(byte bParamType, byte[] bParamToSend)
    Send protocol messages given their type and data byte array.
    void
    send_msg(byte bParamType, byte bParamToSend)
    Send message given its Type and data byte.
    void
    send_msg(byte bParamType, byte[] bParamToSend)
    Send protocol messages given their type and data byte array.
    void
    setJsonSupport(boolean jsonSupport)
    Choose whether parameter maps are sent as JSON objects or as length-prefixed base64 blobs.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _ctlInStream

      private final InputStream _ctlInStream
      Control messages read from the test server.
    • _ctlOutStream

      private final OutputStream _ctlOutStream
      Control messages sent to the test server.
    • jsonSupport

      private boolean jsonSupport
      True when the server supports JSON output.
  • Constructor Details

    • Protocol

      public Protocol(Socket ctlSocketParam) throws IOException
      Constructor that accepts socket over which to communicate as parameter.
      Parameters:
      ctlSocketParam - socket used to send the protocol messages over
      Throws:
      IOException - if Input/Output streams cannot be read from/written into correctly
  • Method Details

    • send_msg

      public void send_msg(byte bParamType, byte bParamToSend) throws IOException
      Send message given its Type and data byte.
      Parameters:
      bParamType - Control Message Type
      bParamToSend - Data value to send
      Throws:
      IOException - If data cannot be successfully written to the Output Stream
    • send_json_msg

      public void send_json_msg(byte bParamType, byte bParamToSend) throws IOException
      Send message given its Type and data byte.
      Parameters:
      bParamType - Control Message Type
      bParamToSend - Data value to send
      Throws:
      IOException - If data cannot be successfully written to the Output Stream
    • send_json_msg

      public void send_json_msg(byte bParamType, byte[] bParamToSend) throws IOException
      Send protocol messages given their type and data byte array.
      Parameters:
      bParamType - Control Message Type
      bParamToSend - Data value array to send
      Throws:
      IOException - If data cannot be successfully written to the Output Stream
    • send_json_login_msg

      public void send_json_login_msg(byte bParamType, byte[] bParamToSend) throws IOException
      Send protocol messages given their type and data byte array.
      Parameters:
      bParamType - Control Message Type
      bParamToSend - Data value array to send
      Throws:
      IOException - If data cannot be successfully written to the Output Stream
    • send_msg

      public void send_msg(byte bParamType, byte[] bParamToSend) throws IOException
      Send protocol messages given their type and data byte array.
      Parameters:
      bParamType - Control Message Type
      bParamToSend - Data value array to send
      Throws:
      IOException - If data cannot be successfully written to the Output Stream
    • readn

      public int readn(Message msgParam, int iParamAmount) throws IOException
      Populate Message byte array with specific number of bytes of data from socket input stream.
      Parameters:
      msgParam - Message object to be populated
      iParamAmount - specified number of bytes to be read
      Returns:
      integer number of bytes populated
      Throws:
      IOException - If data cannot be successfully read from the Input Stream
    • recv_msg

      public int recv_msg(Message msgParam) throws IOException
      Receive message at end-point of socket.
      Parameters:
      msgParam - Message object
      Returns:
      integer with values:

      a) Success:

      • value=0 : successfully read expected number of bytes.

      b) Error:

      • value= 1 : Error reading ctrl-message length and data type itself, since NDTP-control packet has to be at the least 3 octets long
      • value= 3 : Error, mismatch between "length" field of ctrl-message and actual data read
      Throws:
      IOException - if the read fails
    • close

      public void close()
      Method to close open Streams.
    • setJsonSupport

      public void setJsonSupport(boolean jsonSupport)
      Choose whether parameter maps are sent as JSON objects or as length-prefixed base64 blobs. Defaults to true.
      Parameters:
      jsonSupport - whether to enable JSON support