Class HttpRequest
java.lang.Object
org.apache.tinkerpop.gremlin.driver.HttpRequest
Represents the HTTP request that will be sent to the server. It is passed through the
RequestInterceptor chain where interceptors can modify headers, body, URI, and method.
The body starts as a RequestMessage and can be serialized to JSON bytes via serializeBody().
After all interceptors run, if the body is still a RequestMessage, the driver will call
serializeBody() automatically before sending.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBody()Get the body of the request.Get the HTTP method of the request.getUri()Get the URI of the request.headers()Get the headers of the request.byte[]Serialize the body to JSON bytes if it is still aRequestMessage.Set the HTTP body of the request.Set the HTTP method of the request.Set the URI of the request.
-
Constructor Details
-
HttpRequest
Constructor that defaults the method toPOST. -
HttpRequest
Full constructor.
-
-
Method Details
-
headers
Get the headers of the request.- Returns:
- a map of headers. This can be used to directly update the entries.
-
getBody
Get the body of the request.- Returns:
- an Object representing the body (
RequestMessageorbyte[]).
-
getUri
Get the URI of the request.- Returns:
- the request URI.
-
getMethod
Get the HTTP method of the request. The standard/gremlinendpoint only supportsPOST.- Returns:
- the HTTP method.
-
setBody
Set the HTTP body of the request.- Returns:
- this HttpRequest for method chaining.
-
setMethod
Set the HTTP method of the request.- Returns:
- this HttpRequest for method chaining.
-
setUri
Set the URI of the request.- Returns:
- this HttpRequest for method chaining.
-
serializeBody
public byte[] serializeBody()Serialize the body to JSON bytes if it is still aRequestMessage. If the body is alreadybyte[], this method is idempotent and returns the existing bytes. This method also sets theContent-Typeheader toapplication/jsonand theContent-Lengthheader to the byte length of the serialized body.Interceptors that need the serialized payload (e.g., for computing a signature hash) should call this method rather than serializing independently.
- Returns:
- the serialized body bytes
- Throws:
IllegalStateException- if the body is neither aRequestMessagenorbyte[]
-