java spring restful-url with semi-colon

2019-07-14 11:47发布

问题:

I am currently working on a project that requires the use of a semi-colon in our restful-url scheme.

As you can imagine, we're having issues pulling this off - the underlying Java HTTPServletRequest isn't playing nicely.

Is there a way to work around this issue?

example restulf-URL:

http://service/BOB;MIKE/

Looks like Spring is only working on /service/bob - the ;MIKE gets truncated.

We've tried %3B (or %3F something like that) and it doesn't work.

Thanks in advance!

ct

回答1:

this is the list of all the delimiters you can legally use in a URI:

! $ & ( ) * , ; = + ' : @ / ?

try each and see which works for you.

apparently Spring robs you of the ;. I'm not sure if that's a Servlet thing, but in any case, it sucks. A web framework should allow developers to construct ANY legal URIs.



回答2:

While @Amos M. Carpenter answer is correct, here is the required configuration to turn this behavior off :

@Configuration
@EnableWebMvc
public class WebMvcConfiguration extends WebMvcConfigurerAdapter 
{
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer)
    {  
        configurer.getUrlPathHelper().setRemoveSemicolonContent(false);
    }
}


回答3:

Seems this is intentional on Spring's part, but at least it's configurable.

You need to tell your handler mapping to setRemoveSemicolonContent(false) (default is true). See the Javadoc for more details.

The reason why this was done is because they apparently wanted to remove the ;jsessionid=... suffix from URIs.



标签: java spring rest