Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultRequest toString adds space between endpoint and resourcePath #2962

Closed
SmarMykel opened this issue Apr 17, 2023 · 4 comments
Closed
Assignees
Labels
bug This issue is a bug.

Comments

@SmarMykel
Copy link

Describe the bug

@Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append(getHttpMethod()).append(" ");
        builder.append(getEndpoint()).append(" ");
        String resourcePath = getResourcePath();

        if (resourcePath == null) {
            builder.append("/");
        }
        else {
            if (!resourcePath.startsWith("/")) {
                builder.append("/");
            }
            builder.append(resourcePath);
        }

        return builder.toString();
    }

In aws-sdk-java/aws-java-sdk-core/src/main/java/com/amazonaws/DefaultRequest.java toString method does this. I have been trying to understand why this necessary but can't understand.

There a space appended after the getEndpoint() ?.
Specifically builder.append(" ") after builder.append(getEndpoint())

If my endpoint is Endpoint: https://api.example.com and Resource Path: /users/123, then I will get GET https://api.example.com /users/123 with a space between the endpoint and resource path

Expected Behavior

DefaultRequest toString() returns for

Endpoint = https://api.example.com
Resource Path = /users/123

https://api.example.com/users/123 with no space between the endpoint and resource path

Current Behavior

DefaultRequest toString() returns for

Endpoint = https://api.example.com
Resource Path = /users/123

https://api.example.com /users/123 with a space between the endpoint and resource path

Reproduction Steps

val endpoint = "https://api.example.com"
val path = "/users/123"
val httpMethodNameValue = "GET"

val awsRequest = DefaultRequest<Any>("execute-api")

awsRequest.endpoint = URI.create(endpoint)
awsRequest.resourcePath = "/$path"
awsRequest.httpMethod = httpMethodNameValue

// put breakpoint after this code and see the DefaultRequest

println()

Possible Solution

@Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append(getHttpMethod()).append(" ");
        builder.append(getEndpoint());
        String resourcePath = getResourcePath();

        if (resourcePath == null) {
            builder.append("/");
        }
        else {
            if (!resourcePath.startsWith("/")) {
                builder.append("/");
            }
            builder.append(resourcePath);
        }

        return builder.toString();
    }

Additional Information/Context

No response

AWS Java SDK version used

2.20.47

JDK version used

openjdk 17.0.6 2023-01-17 LTS

Operating System and version

MacOS Ventura 13.3

@SmarMykel SmarMykel added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 17, 2023
@debora-ito
Copy link
Member

@SmarMykel thank you for reaching out.

What is your use case?
How do you use DefaultRequest#toString?

@debora-ito debora-ito removed the needs-triage This issue or PR still needs to be triaged. label May 2, 2023
@debora-ito debora-ito self-assigned this May 2, 2023
@debora-ito debora-ito added the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label May 2, 2023
@SmarMykel
Copy link
Author

SmarMykel commented May 3, 2023

@debora-ito I use it as a SignableRequest<?> request so I can generate a request that can be signed using the public AWS4Signer() class.

A colleague of mine has told me maybe DefaultRequest wasn't intended to be used as SignableRequest but thats what I am using it for as of today

@github-actions github-actions bot removed the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label May 4, 2023
@debora-ito
Copy link
Member

Yes, as a good practice we don't recommend your code logic to rely on the String representation of an object. The toString method should be used in situations like logging and debugging.

Closing as this is not a bug. Feel free to reach out if you have any other question.

@debora-ito debora-ito closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2023
@github-actions
Copy link

github-actions bot commented May 4, 2023

COMMENT VISIBILITY WARNING

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants