Class HttpBindingIndex

  • All Implemented Interfaces:
    KnowledgeIndex

    public final class HttpBindingIndex
    extends java.lang.Object
    implements KnowledgeIndex
    Computes and indexes the explicit and implicit HTTP bindings of a model.

    This index makes it easy to understand how members of the input or output of a request/response are bound to an HTTP message by providing all of the bindings in the model as a normalized HttpBinding object. This can be used to validate the bindings of an operation, generate code to [de]serialize shapes, diff models to ensure backward compatibility at the wire level, etc.

    This index does not perform validation of the underlying model.

    • Constructor Detail

      • HttpBindingIndex

        public HttpBindingIndex​(Model model)
    • Method Detail

      • hasHttpRequestBindings

        public static boolean hasHttpRequestBindings​(Shape shape)
        Returns true if a shape has any HTTP request trait bindings.
        Parameters:
        shape - Shape to check.
        Returns:
        Returns true if the shape is bound to an HTTP header, payload, prefix headers, query string, or label.
      • hasHttpResponseBindings

        public static boolean hasHttpResponseBindings​(Shape shape)
        Returns true if a shape has any HTTP response trait bindings.
        Parameters:
        shape - Shape to check.
        Returns:
        Returns true if the shape is bound to an HTTP header, payload, of prefix headers.
      • getResponseCode

        public int getResponseCode​(ToShapeId shapeOrId)
        Gets the computed status code of an operation or error structure.
        Parameters:
        shapeOrId - Operation or error structure shape ID.
        Returns:
        Returns the computed HTTP status code.
        Throws:
        java.lang.IllegalArgumentException - if the given shape is not an operation or an error structure.
      • getRequestBindings

        public java.util.Map<java.lang.String,​HttpBinding> getRequestBindings​(ToShapeId operationShapeOrId)
        Gets the request bindings of an operation as a map of member name to the binding.
        Parameters:
        operationShapeOrId - Operation to get the request bindings for.
        Returns:
        Map of unmodifiable bindings.
      • getRequestBindings

        public java.util.List<HttpBinding> getRequestBindings​(ToShapeId operationShapeOrId,
                                                              HttpBinding.Location requestLocation)
        Gets the request bindings of an operation as a map of member name to the binding for a specific location type.
        Parameters:
        operationShapeOrId - Operation to get the request bindings for.
        requestLocation - Location of the binding.
        Returns:
        Map of unmodifiable bindings.
      • getResponseBindings

        public java.util.Map<java.lang.String,​HttpBinding> getResponseBindings​(ToShapeId shapeOrId)
        Gets the computed HTTP message response bindings for an operation or structure with an error trait.
        Parameters:
        shapeOrId - Operation or error structure shape or ID.
        Returns:
        Map of unmodifiable bindings.
      • getResponseBindings

        public java.util.List<HttpBinding> getResponseBindings​(ToShapeId shapeOrId,
                                                               HttpBinding.Location bindingLocation)
        Gets the computed HTTP message response bindings for an operation or structure with an error trait for a specific binding type.
        Parameters:
        shapeOrId - Operation or error structure shape or ID.
        bindingLocation - Binding location type.
        Returns:
        List of found bindings.
        Throws:
        java.lang.IllegalArgumentException - if the given shape is not an operation or error structure.
      • determineTimestampFormat

        public TimestampFormatTrait.Format determineTimestampFormat​(ToShapeId member,
                                                                    HttpBinding.Location location,
                                                                    TimestampFormatTrait.Format defaultFormat)
        Determines the appropriate timestamp format for a member shape bound to a specific location.
        Parameters:
        member - Member to derive the timestamp format.
        location - Location the member is bound to.
        defaultFormat - The format to use for the body or a default.
        Returns:
        Returns the determined timestamp format.
      • determineRequestContentType

        public java.util.Optional<java.lang.String> determineRequestContentType​(ToShapeId operation,
                                                                                java.lang.String documentContentType)
        Returns the expected request Content-Type of the given operation.

        See determineRequestContentType(ToShapeId, String, String) for documentation on how the content-type is resolved.

        Parameters:
        operation - Operation to determine the content-type of.
        documentContentType - Content-Type to use for protocol documents.
        Returns:
        Returns the optionally resolved content-type of the request.
      • determineRequestContentType

        public java.util.Optional<java.lang.String> determineRequestContentType​(ToShapeId operation,
                                                                                java.lang.String documentContentType,
                                                                                java.lang.String eventStreamContentType)
        Returns the expected request Content-Type of the given operation.

        If members are sent in the "document" body, then the default documentContentType value is returned. If a member is bound to the payload, then the following checks are made:

        • If the payload has the StreamingTrait, then the eventStreamContentType is returned.
        • If the targeted shape is a structure or document type, then the documentContentType is returned.
        • If the targeted shape has the MediaTypeTrait, then the value of the trait is returned.
        • If the targeted shape is a blob, then "application/octet-stream" is returned.
        • If the targeted shape is a string, then "text/plain" is returned.

        If no members are sent in the payload, an empty Optional is returned.

        Parameters:
        operation - Operation to determine the content-type of.
        documentContentType - Content-Type to use for protocol documents.
        eventStreamContentType - Content-Type to use for event streams.
        Returns:
        Returns the optionally resolved content-type of the request.
      • determineResponseContentType

        public java.util.Optional<java.lang.String> determineResponseContentType​(ToShapeId operationOrError,
                                                                                 java.lang.String documentContentType)
        Returns the expected response Content-Type of the given operation or error.

        See determineResponseContentType(ToShapeId, String, String) for documentation on how the content-type is resolved.

        Parameters:
        operationOrError - Operation or error to determine the content-type of.
        documentContentType - Content-Type to use for protocol documents.
        Returns:
        Returns the optionally resolved content-type of the response.
      • determineResponseContentType

        public java.util.Optional<java.lang.String> determineResponseContentType​(ToShapeId operationOrError,
                                                                                 java.lang.String documentContentType,
                                                                                 java.lang.String eventStreamContentType)
        Returns the expected response Content-Type of the given operation or error.

        If members are sent in the "document" body, then the default documentContentType value is returned. If a member is bound to the payload, then the following checks are made:

        • If the payload has the StreamingTrait, then the eventStreamContentType is returned.
        • If the targeted shape is a structure or document type, then the documentContentType is returned.
        • If the targeted shape has the MediaTypeTrait, then the value of the trait is returned.
        • If the targeted shape is a blob, then "application/octet-stream" is returned.
        • If the targeted shape is a string, then "text/plain" is returned.

        If no members are sent in the payload, an empty Optional is returned.

        Parameters:
        operationOrError - Operation or error to determine the content-type of.
        documentContentType - Content-Type to use for protocol documents.
        eventStreamContentType - Content-Type used for event streams.
        Returns:
        Returns the optionally resolved content-type of the response.
      • hasRequestBody

        public boolean hasRequestBody​(ToShapeId operation)
        Returns true if the request has a modeled body.
        Parameters:
        operation - Operation to check.
        Returns:
        Returns true if the operation has document or payload bindings.
      • hasResponseBody

        public boolean hasResponseBody​(ToShapeId operation)
        Returns true if the response has a modeled body.
        Parameters:
        operation - Operation to check.
        Returns:
        Returns true if the operation has document or payload bindings.