Class SignatureContext.Builder

java.lang.Object
net.visma.autopay.http.signature.SignatureContext.Builder
Enclosing class:
SignatureContext

public static class SignatureContext.Builder extends Object
Builder class to build SignatureContext objects
  • Method Details

    • status

      public SignatureContext.Builder status(int status)
      Sets HTTP status code
      Parameters:
      status - Status code
      Returns:
      This builder
    • method

      public SignatureContext.Builder method(String method)
      Sets HTTP method name

      Method is internally converted to uppercase

      Parameters:
      method - HTTP method.
      Returns:
      This builder
    • targetUri

      public SignatureContext.Builder targetUri(URI targetUri)
      Sets target URI

      targetUri is not the same as servlet's requestUri

      Parameters:
      targetUri - Target URI given as URI object
      Returns:
      This builder
    • targetUri

      public SignatureContext.Builder targetUri(String targetUri)
      Sets target URI

      targetUri is not the same as servlet's requestUri.

      Parameters:
      targetUri - Target URI given as String
      Returns:
      This builder
    • targetUri

      public SignatureContext.Builder targetUri(StringBuffer requestUrl, String queryString)
      Sets target URI

      Method offers compatibility with HttpServletRequest methods. targetUri is not the same as servlet's requestUri.

      Example:

       SignatureContext.builder()
           ...
           .targetUri(request.getRequestURL(), request.getQueryString())
           ...
           .build();
       
      Parameters:
      requestUrl - request URL
      queryString - query string
      Returns:
      This builder
    • header

      public SignatureContext.Builder header(String headerName, Object headerValue)
      Adds an HTTP header of given name and value

      Internally, the name is converted to lowercase, and the value is converted to its toString() representation. When called multiple times with the same headerName, header values are concatenated by using a single space and a single comma, with stripped leading and trailing whitespaces.

      Parameters:
      headerName - HTTP header (field) name
      headerValue - Header value
      Returns:
      This builder
      See Also:
    • headers

      public SignatureContext.Builder headers(Map<String,?> headers)
      Adds HTTP headers from given map

      Map keys are header names. Map values are header values. Internally, names is converted to lowercase, and values are converted to their toString() representation.

      If the value is an instance of Iterable, like List or Set, it's treated as multiple values of the header. This way, multimap header holders, like javax.ws.rs.core.MultivaluedMap, can be used directly. Multiple header values are concatenated by using a single space and a single comma, with stripped leading and trailing whitespaces.

      Parameters:
      headers - A map of HTTP header names and values
      Returns:
      This builder
      See Also:
    • headers

      public SignatureContext.Builder headers(Enumeration<String> headerNames, Function<String,Enumeration<String>> headersGetter)
      Adds HTTP headers.

      Method offers compatibility with HttpServletRequest methods.

      Example:

       SignatureContext.builder()
           ...
           .headers(request.getHeaderNames(), request::getHeaders)
           ...
           .build();
       
      Parameters:
      headerNames - enumeration of HTTP servlet request header names
      headersGetter - getter of HTTP servlet request headers enumeration
      Returns:
      This builder
    • headers

      public SignatureContext.Builder headers(Collection<String> headerNames, Function<String,Collection<String>> headersGetter)
      Adds HTTP headers.

      Method offers compatibility with HttpServletResponse methods.

      Example:

       SignatureContext.builder()
           ...
           .headers(response.getHeaderNames(), response::getHeaders)
           ...
           .build();
       
      Parameters:
      headerNames - collection of HTTP servlet response header names
      headersGetter - getter of HTTP servlet response headers collection
      Returns:
      This builder
    • trailer

      public SignatureContext.Builder trailer(String trailerName, Object trailerValue)
      Adds an HTTP trailer of given name and value

      Internally, the name is converted to lowercase, and the value is converted to its toString() representation. When called multiple times with the same trailerName, trailer values are concatenated by using a single space and a single comma, with stripped leading and trailing whitespaces.

      Parameters:
      trailerName - HTTP trailer (field) name
      trailerValue - Trailer value
      Returns:
      This builder
      See Also:
    • trailers

      public SignatureContext.Builder trailers(Map<String,?> trailers)
      Adds HTTP trailers from given map

      Map keys are trailer names. Map values are trailer values. Internally, names is converted to lowercase, and values are converted to their toString() representation.

      If the value is an instance of Iterable, like List or Set, it's treated as multiple values of the trailer. This way, multimap trailer holders, like javax.ws.rs.core.MultivaluedMap, can be used directly. Multiple trailer values are concatenated by using a single space and a single comma, with stripped leading and trailing whitespaces.

      Parameters:
      trailers - A map of HTTP trailer names and values
      Returns:
      This builder
      See Also:
    • relatedRequest

      public SignatureContext.Builder relatedRequest(SignatureContext relatedRequestContext)
      Sets Signature Context of the Related Request (request that triggered generated response)
      Parameters:
      relatedRequestContext - Related Request's Signature Context
      Returns:
      This builder
    • build

      public SignatureContext build()
      Constructs PublicKeyInfo object from this builder
      Returns:
      SignatureContext object