special characters in path variables in spring boot API - spring

I have a URL like /api/department/{code}
The {code} value can be ITS/ITIS, with such types of codes my request is failing.
what can be the solution.

Related

How to map path elements to method parameter in spring cloud function web

I'm working on a Microservice that receives webhooks, the idea is to use path variables for some processing down stream,
/webhooks/{foo}/{bar}/{baz}
for example
/webhooks/sony/pony/tony would populate foo=sony; bar=pony; baz=tony.
Can't figure how to make it work in spring cloud function web.
This was never the purpose of spring-cloud-function to replace spring-mvc etc.
Also, Function has only one argument, so what you can do is have Function<Message, ...> and we translate HTTP request into Message where body will turn into payload and HTTP headers will turn into Message headers.

Does Spring Boot Support Multiple Content Negotiation Strategies Base On URL Pattern

Our Spring Boot webapp consists of a couple of URL strategies. The /api URL's are for REST services and content negotiation is consistent with best practices (headers or request parameters). The /web URLS are for a legacy Freemarker application which uses URL extensions for mapping content type (.html, .json, etc). A recent change by Spring has caused the problem (https://github.com/spring-projects/spring-framework/issues/24179).
The content negotiation for the two URL's are different and I was wondering if we could define multiple content negotiation strategies...using URL's to select between them.
Yes, content negotiation is possible in the Spring Boot application as you can use Request parameter or header values to return different content-type based on your requirement for example. You can use the same URL pattern and use content-type request parameter to get the desired type and return the content like .html or.json but make sure you are adding marking as #RequestMapping(value = "sign_in", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_HTML_VALUE})

How can I ingore placeholders in property file in spring boot?

I have urls like localhost:8080/boot/${task}/say
in property file, I am reading this url in my code using poprerty placeholder, problem is here spring boot trying to search placeholder in url. I want to ingore that and send complete url with that placeholder into response.
I have already declared bean of PropertySourcePlaceholderConfigure and setIgoreUnresolvablePlaceholders as true but still it asking for value of placeholder.
You need to escape $ sign.
localhost:8080/boot/#{'$'}{task}/say

How to define explicit mapping for swagger-ui.html in spring boot application

I have an issue integrating swagger-ui (swagger2) into my spring-boot application. It seems as though the default location for swagger-ui being on the root is conflicting with an endpoint.
For example, my base path is foobar (full url: locahost:8080/foobar/). One of my endpoints has a path variable that can be any number (making the endpoint url: localhost:8080/foobar/{number} or localhost:8080/foobar/123 as an example). This seems to conflict with swagger-ui.html, as when I then try to hit locahost:8080/foobar/swagger-ui.html, spring complains, thinking 'swagger-ui.html' is the path variable for that endpoint.
I was curious if there was a way to define an explicit mapping for swagger-ui, so that spring won't think that I'm just inputting a path variable to the other endpoint? I ideally don't want to modify the foobar/{number} path at all, and would like to either make an explicit mapping for swagger-ui, or change the path for swagger-ui itself. Any help is appreciated. Thanks!

Why is plus(+) decoded to space ( ) in url path with springboot rest controller?

When calling GET http://localhost:8080/things/ZhaD2lk27XQPRJtwrABltd+UTWXcbnY%2FTrpxGP7VDVo= my Spring Boot application RestController with a request handler like this:
#RequestMapping("/things/{thingId}")
public ResponseEntity<Thing> getThing(
#PathVariable String thingId) {
System.out.println("thingId=" + thingId);
...
results in the following being printed ZhaD2lk27XQPRJtwrABltd UTWXcbnY/TrpxGP7VDVo= instead of what I would have expected ZhaD2lk27XQPRJtwrABltd+UTWXcbnY/TrpxGP7VDVo=.
As you can see, the plus is being turned into a space. This should not happen with the path part, only the query part. This is why the Spring UriComponentsBuilder.build().encode() I'm using to build the URL doesn't turn the plus into %2B.
I needed to tweak the application already to get the encoded slash (/) to work. See REST Endpoint unreachable if ID in URL contains %2F for details.
I'm using SpringBoot 1.4.4.RELEASE which uses Tomcat embed 8.5.11.
I have tried calling the service from Spring RestTemplate, Postman and Chrome. Same results in all cases, the plus is turned into a space
I was able to resolve after identifying that my IDE had automagically added spring-boot-starter-undertow to the POM file. I did not exclude spring-boot-starter-tomcat from spring-boot-starter-web so I'm not sure what was happening under the covers but removing the spring-boot-starter-undertow dependency fixed the issue.

Resources