/** Populates the header with information received via socket */
  public void readHeader() throws IOException {
    if (this.socket != null) {
      final ByteBuffer cb = getCommBuffer();
      synchronized (cb) {
        fetchHeader();
        final int type = cb.getInt();
        final int numParts = cb.getInt();
        final int txid = cb.getInt();
        cb.clear();
        if (!MessageType.validate(type)) {
          throw new IOException(
              LocalizedStrings.ChunkedMessage_INVALID_MESSAGE_TYPE_0_WHILE_READING_HEADER
                  .toLocalizedString(Integer.valueOf(type)));
        }

        // Set the header and payload fields only after receiving all the
        // socket data, providing better message consistency in the face
        // of exceptional conditions (e.g. IO problems, timeouts etc.)
        this.msgType = type;
        this.numberOfParts = numParts; // Already set in setPayloadFields via setNumberOfParts
        this.transactionId = txid;
      }
    } else {
      throw new IOException(LocalizedStrings.ChunkedMessage_DEAD_CONNECTION.toLocalizedString());
    }
  }
  @Override
  public void cmdExecute(Message msg, ServerConnection servConn, long start) throws IOException {
    // requiresResponse = true; NOT NEEDED... ALWAYS SEND ERROR RESPONSE

    logger.fatal(
        LocalizedMessage.create(
            LocalizedStrings.Default_0_UNKNOWN_MESSAGE_TYPE_1_WITH_TX_2_FROM_3,
            new Object[] {
              servConn.getName(),
              MessageType.getString(msg.getMessageType()),
              Integer.valueOf(msg.getTransactionId()),
              servConn.getSocketString()
            }));
    writeErrorResponse(msg, MessageType.UNKNOWN_MESSAGE_TYPE_ERROR, servConn);
    // responded = true; NOT NEEDED... ALWAYS SEND ERROR RESPONSE
  }
 protected Object processResponse(Connection cnx, Message msg) throws Exception {
   byte[] bytes = null;
   Part part = msg.getPart(0);
   final int msgType = msg.getMessageType();
   long userId = -1;
   if (msgType == MessageType.RESPONSE) {
     bytes = (byte[]) part.getObject();
     if (bytes.length == 0) {
       cnx.getServer().setRequiresCredentials(false);
     } else {
       cnx.getServer().setRequiresCredentials(true);
       byte[] decrypted = ((ConnectionImpl) cnx).getHandShake().decryptBytes(bytes);
       DataInputStream dis = new DataInputStream(new ByteArrayInputStream(decrypted));
       userId = dis.readLong();
     }
     if (this.needsServerLocation) {
       return new Object[] {cnx.getServer(), userId};
     } else {
       return userId;
     }
   } else if (msgType == MessageType.EXCEPTION) {
     Object result = part.getObject();
     String s = "While performing a remote authenticate";
     if (result instanceof AuthenticationFailedException) {
       final AuthenticationFailedException afe = (AuthenticationFailedException) result;
       if ("REPLY_REFUSED".equals(afe.getMessage())) {
         throw new AuthenticationFailedException(s, afe.getCause());
       } else {
         throw new AuthenticationFailedException(s, afe);
       }
     } else if (result instanceof AuthenticationRequiredException) {
       throw new AuthenticationRequiredException(s, (AuthenticationRequiredException) result);
     } else if (result instanceof NotAuthorizedException) {
       throw new NotAuthorizedException(s, (NotAuthorizedException) result);
     } else {
       throw new ServerOperationException(s, (Throwable) result);
     }
     // Get the exception toString part.
     // This was added for c++ thin client and not used in java
     // Part exceptionToStringPart = msg.getPart(1);
   } else if (isErrorResponse(msgType)) {
     throw new ServerOperationException(part.getString());
   } else {
     throw new InternalGemFireError("Unexpected message type " + MessageType.getString(msgType));
   }
 }