Class RequestBodyHandler

java.lang.Object
io.clientcore.annotation.processor.utils.RequestBodyHandler

public final class RequestBodyHandler extends Object
Utility class for handling request bodies in HTTP requests.
  • 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

      public static boolean isByteArray(TypeMirror parameterType)
      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.