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
ConstructorsConstructorDescriptionExchange(@NotNull ProtocolVersion protocolVersion, @NotNull Request request, @NotNull Response response, @NotNull Session session) Creates an instance of aExchangerecord class. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Performs last actions before the exchange is closed.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.path()Deprecated, for removal: This API element is subject to removal in a future version.@NotNull ProtocolVersionReturns the value of theprotocolVersionrecord component.request()Gets theRequestobject associated with this exchange holding information about the request.response()Gets theResponseobject associated with this exchange used for managing the response to the request.session()Get theSessionobject associated with this exchange holding information from the session.final StringtoString()Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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 aExchangerecord class.- Parameters:
protocolVersion- the value for theprotocolVersionrecord componentrequest- the value for therequestrecord componentresponse- the value for theresponserecord componentsession- the value for thesessionrecord component
-
-
Method Details
-
request
Gets theRequestobject associated with this exchange holding information about the request.- Returns:
- The
Requestobject.
-
response
Gets theResponseobject associated with this exchange used for managing the response to the request.- Returns:
- The
Responseobject.
-
session
Get the
Sessionobject 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 ofResponse.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
Performs last actions before the exchange is closed.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
path
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofRequest.getRawUrl().A wrapper method forRequest.getRawUrl()retrieved from therequest().This method is used for backwards compatibility with older versions of CraftsNet.
- Returns:
- The raw url.
- Since:
- 3.3.2-SNAPSHOT
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
protocolVersion
Returns the value of theprotocolVersionrecord component.- Specified by:
protocolVersionin interfaceBaseExchange- Returns:
- the value of the
protocolVersionrecord component
-
Request.getRawUrl().