0

Path variable = "476%3B"

In a delete API, in path variable value, the character ';' is included in Id and is encoded as '%3B' The id is passed as a string and later on in the app, it is parsed as an integer using Integer.parseInt("476%3B") When this Id value goes thru the API gateway, somehow, the character ';' is getting stripped and using "476" instead of "476%3B" for Id. On execution of the app, I am expecting http code 400 (bad request) But I am getting 404 (not found) The Id can only be integer. Can someone explain the reason behind this?

2
  • You would possibly get 400 bad request if you use id as RequestParam instead of path variable. When you are using it as path variable, it becomes part of the API endpoint URL itself so calling the API with ; will result as 404 NOT FOUND. 1 - URL endpoint with path variable = localhost:8080/user/123 2 - URL with request param = localhost:8080/user?123 Notice that in case 1, base URL will change if you append anything to the integer value (semi colon in your case) but in case 2, base url stays same and only the param value is changing Commented Mar 7, 2023 at 12:46
  • This ("476%3B") id value for the path variable is working fine in the local environment It is not working correctly in dev and test environment where API gateway is used Commented Mar 7, 2023 at 14:51

1 Answer 1

0

You could look at this UrlPathHelper::setRemoveSemicolonContent. By default it is true.

Remove ";" (semicolon) content from the given request URI

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/UrlPathHelper.html#removeSemicolonContent(java.lang.String)

And you can configure it.

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        UrlPathHelper urlPathHelper = new UrlPathHelper();
        urlPathHelper.setRemoveSemicolonContent(false);
        configurer.setUrlPathHelper(urlPathHelper);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.