I want to understand why in PATCH/UPDATE methods I need to use repository.saveAndFlush() and not .save() in order to get back validation errors. If I don’t use saveAndFlush and I send a bean without some mandatory data, I got a HTTP 500 and not a HTTP 400.
Related
My spring boot app has a feign client that POST a payload to external endpoint.
There is requirement to audit all the calls, especially when any errors occurs in calling the endpoint (connection, unauthorized etc), after retry are exhausted. To audit,
need some information from original payload
http status
underlying exception message,
backup original payload for reference
endpoint
I tried below approaches (for error handling), but still unable to find a solution that covers all above
feign Fallbackfactory - it has handle to exception, but unable to effectively capture feign response/original payload
fallbackMethod with resilence4j - here i get access to original payload and exception, but again unable to capture actual response status (401, 503 etc)
CustomErrorDecoder - Here able to get access to feign Response, but then have to map response body (any request body/payload). Also have to map exception
Appreciate any suggestion/ advise?
In Spring Boot in #ControllerAdvice error handler, we can provide Exceptions & what to do for the following. But, it doesn't work with Error.
DataIntegrityViolationException ca handle some SQL errors like more length, duplicate, etc.
But, some errors come under SQLError.
I tried adding SqlError.class, Error.class. But, it didn't capture as it handles only Exception
#ExceptionHandler
Temporarily, I am handling it in a try-catch block. And, if not handled without try-catch also fine, but it gives query result in REST response saying this field this error, etc. Which is vulnerable to show to the user.
So, if it can be handled globally, we will just avoid those parts.
I am using spring webflow 2.3.1.RELEASE in my project.
The customer's security team raised and issue witch is "It is possible to change the http method from POST to GET and the application accepts the change and continues working."
So I need to prevent this change and make my transitions accept only POST method. Or throw exception if I get any request parameter other than execution in the url.
How can I do this?
You could create your own FlowExecutionListener and throw an exception when the request method is different than POST and/or when request parameters are present.
see the documentation here and API here
I solved the problem using interceptors of the FlowHandlerMapping.
I've created a class and named it MethodInterceptor, implementend org.springframework.web.context.request.WebRequestInterceptor.
in the "public void preHandle(WebRequest request) throws Exception" method, I checked the request method, if it was get, I checked the request parameters to be either empty or contain only the execution parameter. If the condition didn't meet, I threw an exception.
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.
someone could tell me ,how can i get Response in a normal bean in spring, actually,
what i am gonna to do is to create a proxy to check whether a user is log in or not ,if it's not ,i would send him to my home page,if it does,then the request goes to spring mvc's Controller,i know i can get the HttpServletRequest Object with declaring the RequestContextListenerin web.xml, i want to get the Response Object, and then i could do the forward withRequestDispatcher` .is there a way to get the response object? or you have a solution to this, thanks in advance, i am waiting online ..