private AwsRequest setNextToken()

in src/main/java/com/awslabs/resultsiterator/implementations/ResultsIteratorAbstract.java [234:263]


    private AwsRequest setNextToken(AwsRequest request, String nextToken) {
        if (clientGetMethodReturningString.isEmpty()) {
            throw new UnsupportedOperationException("Trying to set the next token on a method that does not support pagination, this should never happen.");
        }

        if (clientSetMethodAcceptingString == null) {
            // Look for a public method that takes a string and returns a builder class that matches our list of expected names.  If zero or more than one exists, fail.
            Class<? extends AwsRequest.Builder> builderClass = request.toBuilder().getClass();
            clientSetMethodAcceptingString = reflectionHelper.getMethodWithParameterReturnTypeAndNames(builderClass, String.class, builderClass, primaryTokenMethodNames);

            if (clientSetMethodAcceptingString.isEmpty()) {
                // Only look for these methods if the first search fails
                clientSetMethodAcceptingString = reflectionHelper.getMethodWithParameterReturnTypeAndNames(builderClass, String.class, builderClass, secondaryTokenMethodNames);
            }
        }

        if (clientSetMethodAcceptingString.isEmpty()) {
            throw new UnsupportedOperationException("Failed to find the set next token method, this should never happen.");
        }

        try {
            AwsRequest.Builder builder = request.toBuilder();
            clientSetMethodAcceptingString.get().setAccessible(true);
            clientSetMethodAcceptingString.get().invoke(builder, nextToken);
            return builder.build();
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
            throw new UnsupportedOperationException(e);
        }
    }