Emails in restful spring Get request url - spring

I am having a problem with passing emails in http url using spring. My url looks as follows
http://localhost:8080/users/{email}
I am using spring mvc to handle this GET request.
Using my browser url bar or using Postman when I do the following
http://localhost:8080/users/sampleEmail#gmail.com
I only see sampleEmail#gmail in the spring controller code. For some reason the ".com" part is stripped out. Would anyone know if I am doing something wrong? Thanks

It is because Spring truncates whatever is coming after DOT(.) assuming it to be an extension.
Refer this:
Spring MVC #PathVariable with dot (.) is getting truncated
Is there a requirement that you need to use only GET? If not then switch to POST and send JSON Object with required parameters such as {email: "abc#xyz.com"}

Related

How to access http headers for Spring Data auditing in WebFlux

I'm trying to make use of http headers to audit my Spring Repository, as mentioned here https://docs.spring.io/spring-data/commons/docs/current/reference/html/#auditing.reactive-auditor-aware
But the challenge I face is that I don't use Spring Security, my userId comes in as plain text in http header.
I got as far as working out that in WebFlux case I need to use Reactor Context, and if I understand it correctly there already is a filter that does it: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/filter/reactive/ServerWebExchangeContextFilter.html, but I struggle to write the code to extract it.
Does any one know of any articles/blogs/snippets that could point me in the right direction?

Need to change GET mapping name on Swagger UI

I am working with Java Spring Boot Application.
My Current GET method in RestController is below .
GetMapping on RestController
After launching my swagger looks like below
Swgger UI
Is there any way, i can still use "/v1/person" in Controller , but on swagger i only want to display "/person".
I don't want "/v1/person" on swagger
Firstly, It is not possible to do that.
I think you are looking at it completely wrong. Swagger is meant to be like a contract that you expose to the client(who ever is calling your API). This should have details about what the endpoint is all about, how a client can call your endpoint, with what arguments and what the client can expect in return.
If you use /v1/person in your controller, that means it can only be called with url http://......./v1/person.
Now if you (somehow) display /person in Swagger, then the client cannot call your endpoint and the basic idea of Swagger is destroyed.
Hope its clear.

springfox swagger api: Can't get OAuth 2.0 working

I'm using Spring security OAuth 2.0 authorization in a Spring Boot REST API. It works as expected in Postman tests but I don't succeed to make it working from Swagger "Try out". I'm using this post here: How to configure oAuth2 with password flow with Swagger ui in spring boot rest application. This is supposed to work but it doesn't in my case. I just need some clarification on the following method:
private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.ant("/user/**"))
.build();
}
What the /user/** URL stands for ? Does it means that the defined security context should apply on all URL matching the pattern ? Or does it mean that this URL shall be called to get the user details ?
My code is exactly as the one in the post, however, after I fill in the dialog box with the user credentials and scopes, etc. I get "Auth ErrorTypeError: Failed to fetch" and whatever I do I can't get any usefull log message.
It might have something to do with CORS as the HTTP filters, which are called when I'm doing Postman tests, aren't called in this case.
Any suggestion please ?
Many thanks in advance.
Kind regards,
Nicolas
I confirm that the code mentioned in the article works as expected. I was mistaken while performing tests with wrong URLs, etc. Sorry for the smalltalk.
Kind regards,
Nicolas

spring boot rest versioned request and select controller dynamically

We are planning to apply versioning to our REST API. We do not want to change the URL so the idea that we are going with is to have a X-API-VERSION in the HTTP header. When this header value is present the request is forwarded to correct versioned rest controller.
e.g. we have two controller for the same resource i.e. Person resource
PersonController
Person_Version_1_5_Controller
If X-API-VERSION is NOT present in the HTTP Header then spring by default will call the PersonController.
If X-API-VERSION is PRESENT in the HTTP Header then it should call Person_Version_1_5_Controller.
So how can we achieve this switching between controllers using spring boot?
Looking at Spring's documentation, it looks like the header parameter of RequestMapping might be useful in such cases:
#RequestMapping(value = "/something", headers = "X-API-VERSION=...")
I think you're approaching this from the wrong angle.
Instead of keeping controllers for different versions in the same application deployment (Person_Version_1_5_Controller is not a pretty name, by the way), you could split them in separate JARs / application deployments, e.g. app-v1.jar and app-v2.jar. You could do the routing on a higher level in your stack, using a HTTP-header based load-balancer that would forward the request to the correct version of the app depending on the version header specified in the request.

How force PUT request from a POST with Spring?

I have a service with routes on PUT and I want to make a SDK implementing those routes in Unity3D. The problem is WWW don't accept PUT request.
The service is based on Spring Framework.
From the SDK, I try to call the route in POST with an additional parameter _method set to PUT but it doesn't work.
There is a way to simulate a PUT request with a POST call in Spring Framework?
Thanks in advance for your help.
Have you configured HiddenHttpMethodFilter filter in your springframework, its required at server side to convert post request with _method parameter to put request

Resources