Class ResponseHandler

java.lang.Object
com.example.server.handler.ResponseHandler
All Implemented Interfaces:
MessageHandler<BodyMessage>

public class ResponseHandler extends Object implements MessageHandler<BodyMessage>
This class is responsible for handling outgoing responses to be sent to clients. It receives a BodyMessage object containing the response message, and uses a ChatInterface and TransportFactory to create a connection and send the response to the specified client.
  • Constructor Details

    • ResponseHandler

      public ResponseHandler(ChatInterface chatInterface, TransportFactory transportFactory)
      Constructor for ResponseHandler class.
      Parameters:
      chatInterface - The interface for managing client communication in the server.
      transportFactory - The factory for creating TransportConnections.
  • Method Details

    • handle

      public void handle(BodyMessage message)
      Handles the outgoing response message to be sent to a client. It creates a TransportConnection using the TransportFactory, and sends the response message to the client. If there is an IOException, it logs an error message and removes the user from the chatInterface.
      Specified by:
      handle in interface MessageHandler<BodyMessage>
      Parameters:
      message - The BodyMessage object containing the response message, IP, and port.