protected SdkHttpFullRequest toSignableRequest()

in src/main/java/com/amazonaws/neptune/auth/NeptuneApacheHttpSigV4Signer.java [117:193]


    protected SdkHttpFullRequest toSignableRequest(final HttpUriRequest request)
            throws NeptuneSigV4SignerException {

        // make sure the request is not null and contains the minimal required set of information
        checkNotNull(request, "The request must not be null");
        checkNotNull(request.getURI(), "The request URI must not be null");
        checkNotNull(request.getMethod(), "The request method must not be null");

        // convert the headers to the internal API format
        final Header[] headers = request.getAllHeaders();

        final Map<String, List<String>> headersInternal = new HashMap<>();
        for (final Header header : headers) {
            // Skip adding the Host header as the signing process will add one.
            if (!header.getName().equalsIgnoreCase(HOST)) {
                headersInternal.put(header.getName(), Arrays.asList(header.getValue()));
            }
        }

        // convert the parameters to the internal API format
        final String queryStr = request.getURI().getRawQuery();
        final Map<String, List<String>> parametersInternal = extractParametersFromQueryString(queryStr);

        // carry over the entity (or an empty entity, if no entity is provided)
        final InputStream content;
        try {

            HttpEntity httpEntity = null;
            if (request instanceof HttpEntityEnclosingRequest) {
                httpEntity = ((HttpEntityEnclosingRequest) request).getEntity();
            }

            // fallback: if we either have an HttpEntityEnclosingRequest without entity or
            //           say a GET request (which does not carry an entity), set the content
            //           to be an empty StringEntity as per the SigV4 spec
            if (httpEntity == null) {
                httpEntity = new StringEntity("");
            }
            content = httpEntity.getContent();

        } catch (final UnsupportedEncodingException e) {

            throw new NeptuneSigV4SignerException("Encoding of the input string failed", e);

        } catch (final IOException e) {

            throw new NeptuneSigV4SignerException("IOException while accessing entity content", e);

        }

        final URI uri = request.getURI();

        // http://example.com:8182 is the endpoint in http://example.com:8182/test/path
        URI endpoint;

        // /test/path is the resource path in http://example.com:8182/test/path
        String resourcePath;

        if (uri.getHost() != null) {
            endpoint = URI.create(uri.getScheme() + "://" + uri.getAuthority());
            resourcePath = uri.getPath();
        } else if (request instanceof HttpRequestWrapper) {
            final String host = ((HttpRequestWrapper) request).getTarget().toURI();
            endpoint = URI.create(host);
            resourcePath = uri.getPath();
        } else {
            throw new NeptuneSigV4SignerException(
                    "Unable to extract host information from the request uri, required for SigV4 signing: " + uri);
        }
        return convertToSignableRequest(
                request.getMethod(),
                endpoint,
                resourcePath,
                headersInternal,
                parametersInternal,
                content);
    }