Example #1
0
  /**
   * Decodes the provided ASN.1 element as a status request message.
   *
   * @param messageID The message ID to use for this message.
   * @param element The ASN.1 element containing the StatusRequest sequence.
   * @return The status request message decoded from the ASN.1 element.
   * @throws SLAMDException If the provided ASN.1 element cannot be decoded as a status request
   *     message.
   */
  public static StatusRequestMessage decodeStatusRequest(int messageID, ASN1Element element)
      throws SLAMDException {
    ASN1Sequence requestSequence = null;
    try {
      requestSequence = element.decodeAsSequence();
    } catch (ASN1Exception ae) {
      throw new SLAMDException(
          "Could not decode the provided ASN.1 element " + "as a sequence", ae);
    }

    ASN1Element[] elements = requestSequence.getElements();
    if (elements.length == 0) {
      return new StatusRequestMessage(messageID);
    } else if (elements.length != 1) {
      throw new SLAMDException("A status request may have at most one element");
    }

    String jobID = null;
    try {
      jobID = elements[0].decodeAsOctetString().getStringValue();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("Could not decode the first element as an " + "octet string", ae);
    }

    return new StatusRequestMessage(messageID, jobID);
  }
Example #2
0
  /**
   * Decodes the provided ASN.1 element as a stop client response message.
   *
   * @param messageID The message ID to use for this message.
   * @param element The ASN.1 element containing the StopClientResponse sequence.
   * @return The stop client response message decoded from the ASN.1 element.
   * @throws SLAMDException If the provided ASN.1 element cannot be decoded as a stop client
   *     response message.
   */
  public static StopClientResponseMessage decodeStopClientResponse(
      int messageID, ASN1Element element) throws SLAMDException {
    ASN1Sequence responseSequence = null;
    try {
      responseSequence = element.decodeAsSequence();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("Could not decode ASN.1 element as a sequence", ae);
    }

    ASN1Element[] elements = responseSequence.getElements();
    if (elements.length != 2) {
      throw new SLAMDException("A stop client response message must have " + "two elements");
    }

    int responseCode = 0;
    try {
      responseCode = elements[0].decodeAsInteger().getIntValue();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("Could not decode the first element as an " + "integer", ae);
    }

    String responseMessage = null;
    try {
      responseMessage = elements[1].decodeAsOctetString().getStringValue();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("Could not decode the second element as an " + "octet string", ae);
    }

    return new StopClientResponseMessage(messageID, responseCode, responseMessage);
  }
Example #3
0
  /**
   * Encodes this message into an ASN.1 element. A status request message has the following syntax:
   * <br>
   * <br>
   * <CODE>StatusRequest ::= [APPLICATION 8] SEQUENCE {</CODE> <CODE>
   *     jobID           OCTET STRING OPTIONAL }</CODE> <br>
   *
   * @return An ASN.1 encoded representation of this message.
   */
  @Override()
  public ASN1Element encode() {
    ASN1Integer messageIDElement = new ASN1Integer(messageID);
    ASN1Sequence statusRequestSequence = new ASN1Sequence(ASN1_TYPE_STATUS_REQUEST);

    if (!((jobID == null) || (jobID.length() == 0))) {
      statusRequestSequence.addElement(new ASN1OctetString(jobID));
    }

    ASN1Element[] messageElements = new ASN1Element[] {messageIDElement, statusRequestSequence};

    return new ASN1Sequence(messageElements);
  }