Class RequestBodyHandler
java.lang.Object
io.clientcore.annotation.processor.utils.RequestBodyHandler
Utility class for handling request bodies in HTTP requests.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddBinaryDataRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Adds a BinaryData request body to the HTTP request.static voidaddByteArrayRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Adds a byte array request body to the HTTP request.static voidaddByteBufferRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Adds a ByteBuffer request body to the HTTP request.static voidaddStringRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Adds a String request body to the HTTP request.static booleanconfigureRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, HttpRequestContext requestContext, ProcessingEnvironment processingEnv) Configures the request with the body content and content type.static voidhandleRequestBodySerialization(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Handles the serialization of the request body based on the content type.static booleanisBinaryDataType(TypeMirror parameterType, Elements elementUtils, Types typeUtils) Checks if the given parameter type is BinaryData.static booleanisByteArray(TypeMirror parameterType) Checks if the given parameter type is a byte array.static booleanisByteBufferType(TypeMirror parameterType, Elements elementUtils, Types typeUtils) Checks if the given parameter type is a ByteBuffer.static booleanisStringType(TypeMirror parameterType, Elements elementUtils, Types typeUtils) Checks if the given parameter type is a String.static voidsetContentTypeHeader(com.github.javaparser.ast.stmt.BlockStmt body, String contentType) Sets the Content-Type header for the HTTP request.
-
Method Details
-
configureRequestBody
public static boolean configureRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, HttpRequestContext requestContext, ProcessingEnvironment processingEnv) Configures the request with the body content and content type. Determines the content type if not explicitly set, and adds the appropriate request body statements.- Parameters:
body- The BlockStmt to which the statements are added.requestContext- The request body context containing parameter type and content type.processingEnv- The processing environment providing utility methods for operating on program elements and types.- Returns:
- true if a serialization format is set and used in the request body, false otherwise.
-
isBinaryDataType
public static boolean isBinaryDataType(TypeMirror parameterType, Elements elementUtils, Types typeUtils) Checks if the given parameter type is BinaryData.- Parameters:
parameterType- The type of the parameter.elementUtils- Utility methods for operating on program elements.typeUtils- Utility methods for operating on types.- Returns:
- true if the parameter type is BinaryData, false otherwise.
-
addBinaryDataRequestBody
public static void addBinaryDataRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Adds a BinaryData request body to the HTTP request.- Parameters:
body- The block statement to which the request body is added.parameterName- The name of the parameter.
-
isByteArray
Checks if the given parameter type is a byte array.- Parameters:
parameterType- The type of the parameter.- Returns:
- true if the parameter type is a byte array, false otherwise.
-
addByteArrayRequestBody
public static void addByteArrayRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Adds a byte array request body to the HTTP request.- Parameters:
body- The block statement to which the request body is added.parameterName- The name of the parameter.
-
isStringType
public static boolean isStringType(TypeMirror parameterType, Elements elementUtils, Types typeUtils) Checks if the given parameter type is a String.- Parameters:
parameterType- The type of the parameter.elementUtils- Utility methods for operating on program elements.typeUtils- Utility methods for operating on types.- Returns:
- true if the parameter type is a String, false otherwise.
-
addStringRequestBody
public static void addStringRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Adds a String request body to the HTTP request.- Parameters:
body- The block statement to which the request body is added.parameterName- The name of the parameter.
-
isByteBufferType
public static boolean isByteBufferType(TypeMirror parameterType, Elements elementUtils, Types typeUtils) Checks if the given parameter type is a ByteBuffer.- Parameters:
parameterType- The type of the parameter.elementUtils- Utility methods for operating on program elements.typeUtils- Utility methods for operating on types.- Returns:
- true if the parameter type is a ByteBuffer, false otherwise.
-
addByteBufferRequestBody
public static void addByteBufferRequestBody(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Adds a ByteBuffer request body to the HTTP request.- Parameters:
body- The block statement to which the request body is added.parameterName- The name of the parameter.
-
setContentTypeHeader
public static void setContentTypeHeader(com.github.javaparser.ast.stmt.BlockStmt body, String contentType) Sets the Content-Type header for the HTTP request.- Parameters:
body- The block statement to which the Content-Type header is added.contentType- The content type to set.
-
handleRequestBodySerialization
public static void handleRequestBodySerialization(com.github.javaparser.ast.stmt.BlockStmt body, String parameterName) Handles the serialization of the request body based on the content type. It checks the serialization format from the HTTP request headers and sets the request body using the appropriate serializer (XML or JSON).- Parameters:
body- The BlockStmt to which the serialization statements are added.parameterName- The name of the parameter to be serialized.
-