How to validate header parameters while calling REST services in spring mvc? - spring

I want to validate header parameters that I am going to send while calling REST of spring MVC. The validating class should return JSon object depending on result of validation. how can I do that?

Related

How can I fill the common http header once in swag-go?

Each method of my REST api accepts an Authorization header. Now I need to fill out the header for each API method in Swagger UI.
How can I write Swagger annotation so I can fill the Authorization header once and then all my API methods can use it?
Thanks.

Spring MVC interceptor

I need inputs related to Spring MVC, I have a URL to which a client will send a post request with an xml as the pay load. I plan to have a controller method which maps to the requested url, I want that xml to be validated/converted to an object using jaxb before controller method is executed. And also, the controller method should have only the object as the parameter to its methods and no httprequest etc.
So, how do I achieve this? Will interceptor be helpful? If yes, how will it be done?
I plan to use Spring 3.
Simply use #RequestBody in conjunction with #Valid on a method argument and that is all you need.
public void myRequestHandlingMethod(#Valid #RequestBody YourJaxbObject jaxbObject) { … }
I strongly suggest you take a look at the Spring reference guide

Serialize POJO to application/x-www-form-urlencoded representation of the object

I am using Spring/SpringMVC and I want to serialize a POJO to application/x-www-form-urlencoded representation - the very same representation that a Spring #Controller would be able to bind to a POJO if submitted via a POST request for example.
Anyone has an idea in which Spring Components should I be looking?
Have a look at this HTTP message converter implementation. Register that in Spring MVC configuration on the server-side or a RestTemplate on the client side.

Spring get request data in Dao or service layer

I m sing spring data MongoDb. in controller #requestBody User user.
So There is no data in request now. After take it from the request body.
Is there any Way in spring to get the request body data after take it from the request Object in dao layer.. Please help me out. Thx in advance/..
Spring doesn't magically store it anywhere, so you have to read it yourself in the controller layer and pass it around as a regular parameter or store somewhere yourself.

ServiceStack Receiving posts without entity

I've a scenario where I get changing post content. So I can't map it to an entity.
I need is to get the json body of the post.
I would like to create an entity with a Property "JSON" so if the url for this entity is called the body is filled.
Is there a way to do this ? or any other way fo have a generic endpoint for posts?
In WebAPI I created a parameterless method on a controller and analysed the body on my own.
See this section on Reading in and De-Serializing ad-hoc custom requests in ServiceStack's wiki.
E.g. you can use a custom request binder or get your Request DTO to implement IRequiresRequestStream to tell ServiceStack to skip the deserialization of the request DTO and directly retrieve the stream without populating the request DTO.

Resources