Record Class Exchange

java.lang.Object
java.lang.Record
de.craftsblock.craftsnet.api.http.Exchange
All Implemented Interfaces:
BaseExchange, AutoCloseable

public record Exchange(@NotNull ProtocolVersion protocolVersion, @NotNull Request request, @NotNull Response response, @NotNull Session session) extends Record implements BaseExchange
Represents the exchange of data between the client (request) and the server (response). This record holds both the request and response objects for handling HTTP communication.

The Exchange object encapsulates the incoming request data (headers, parameters, cookies, body) as a Request object, and the outgoing response data (headers, status code, body) as a Response object.

Since:
1.0.0-SNAPSHOT
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Exchange(@NotNull ProtocolVersion protocolVersion, @NotNull Request request, @NotNull Response response, @NotNull Session session)
    Creates an instance of a Exchange record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Performs last actions before the exchange is closed.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Deprecated, for removal: This API element is subject to removal in a future version.
    in favor of Request.getRawUrl().
    Returns the value of the protocolVersion record component.
    Gets the Request object associated with this exchange holding information about the request.
    Gets the Response object associated with this exchange used for managing the response to the request.
    Get the Session object associated with this exchange holding information from the session.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface de.craftsblock.craftsnet.api.BaseExchange

    scheme
  • Constructor Details

    • Exchange

      public Exchange(@NotNull @NotNull ProtocolVersion protocolVersion, @NotNull @NotNull Request request, @NotNull @NotNull Response response, @NotNull @NotNull Session session)
      Creates an instance of a Exchange record class.
      Parameters:
      protocolVersion - the value for the protocolVersion record component
      request - the value for the request record component
      response - the value for the response record component
      session - the value for the session record component
  • Method Details

    • request

      public Request request()
      Gets the Request object associated with this exchange holding information about the request.
      Returns:
      The Request object.
    • response

      public Response response()
      Gets the Response object associated with this exchange used for managing the response to the request.
      Returns:
      The Response object.
    • session

      public Session session()

      Get the Session object associated with this exchange holding information from the session.

      Can be made persistent by using Session.startSession(). Must be called prior to the first call of Response.print(Object).

      If the session is not persistent the data stored will be discarded after the request was handled or the websocket was closed.

      Returns:
      The session object.
    • close

      public void close() throws Exception
      Performs last actions before the exchange is closed.
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • path

      @Deprecated(since="3.3.2-SNAPSHOT", forRemoval=true) public String path()
      Deprecated, for removal: This API element is subject to removal in a future version.
      in favor of Request.getRawUrl().
      A wrapper method for Request.getRawUrl() retrieved from the request().

      This method is used for backwards compatibility with older versions of CraftsNet.

      Returns:
      The raw url.
      Since:
      3.3.2-SNAPSHOT
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • protocolVersion

      @NotNull public @NotNull ProtocolVersion protocolVersion()
      Returns the value of the protocolVersion record component.
      Specified by:
      protocolVersion in interface BaseExchange
      Returns:
      the value of the protocolVersion record component