I'm trying to configure the Spring WebClient to retry on a specific exception. Specifically PrematureCloseException but Im not really sure the exception matters.
I know how set a retry policy when calling a method on the client but I would like to do it globally for any request that goes through the client.
I fell like I should be able to do it with an ExchangeFilterFunction but I not really familiar with this and cannot figure it out.
Related
I'm writing a spring boot app and use spring-cloud-starter-openfeign. It will be rather convenient to change logger level dynamically (through API call, for example) but I can't find the way to do it without creating a new feign client manually. It seems I need to get access to feign client implementation and to get its properties. There I probably can set a new Logger level but haven't managed to find the way ho to do this. Does anyone have ideas on how to do it, or someone might face similar issues?
We are implementing a retry mechanism (using Spring Retry) for http 409 Conflict responses, which we sometimes get on the production server.
But we wonder how to purposely get a server to respond with a 409 status code? In our cases, the error seems to happen whenever we try to load a lot of data in parallel; since the probability of it happening seems quite random, is there a method to get it consistently for testing purposes?
Well, There might be multiple possible ways to do so, You need to clarify where exactly you need 409 to be thrown ,
I assume (Its spring boot app) from one of your service (A) calls to another service/API(B) and you expect it to throw 409.
If that's the case, you can write #RunWith(SpringRunner.class)/#SpringBootTest test and mock the response from service/API B with 409 and test your retry mechanism.
I have a WebSocket app on Spring Boot. I use STOMP, and I need to get destination path when user close the tab(disconnect from WS). I intercept the disconnect either with #EventListener or extends from ChannelInterceptor and override preSend().
I tried many ways - StompHeaderAccessor.getDestination(), SessionDisconnectEvent.getMessage().getHeaders().get("simpDestination"), etc, but they all return null. Is there a working way to get the path? Maybe not using interceptors, somehow differently?
I can't speak to Spring specifics, but I don't think the information you want is available from a Stomp perspective. As noted in the Stomp 1.2 specification, the DISCONNECT frame doesn't use any kind of destination header. The only possible header is receipt. The semantics of receipts are explained here.
There are following points to make you understand about my application:
I have a traditional spring web application running on Wild-fly.
In my application I have view controller and other controllers.
I have web.xml file and jboss xml file to configure context path.
Request to controller comes through either ajax request or simple get
request from browser.
I want to keep safe my application from possible 'Slow HTTP Post Vulnerability'. For that I have decided if any request takes more than specified amount of time then my application release that connection and throw request time-out exception.
My question is :
How can I implement request time in traditional spring mvc application ?
Note : You are most welcome If you have any other solution to prevent 'slow HTTP post vulnerability'.
You could delegate each controller invocation to a separate thread and then monitor that thread if/until it breaches your timeout condition. Java's ExecutorService already supports something much like this with its awaitTermination() feature.
Using Spring's support for asynchronous controllers (or more generally; implementing non blocking services) would formalise this approach since (a) it would force you to delegate your controller invocations to a separate threadpool and (b) it would encourage you to safely manage the resources available in this threadpool. More details on this approach here and here.
But, however you perform this delegation once you have each controller invocation running in a separate thread (separate from the original invocation, I mean) you will then be able to control how long that thread can run and if it exceeds some configured timeout you can respond with a relevant HTTP status.
I am using Spring Cloud Brixton.M3 and Spring Boot 1.3.0.RELEASE. I am sort of new in this (especially in Spring Cloud). I have created Registry Server (i.e. Eureka instance), Config server and Gateway.
As per my requirement I am intercepting each request hitting the gateway in one of my Filter to extract required information from Header and based upon that I am throwing exception or forwarding / verifying that request using Feign Client. Some time hystrix throw HystrixRuntimeException when it couldn't reach out to respective services or because of any other issues.
So What I want is:
Provide default fallback method for every forwarding request, so that I can read and process it accordingly.
Global Exception handling other than #ControllerAdvice since I am not providing any custom #HystrixCommand and Controller to call services (AOP based solution ?).
Is it possible to intercept every failed request and retry them for certain number of times ? Internally it might be happening but can I override this functionality and handle each failed request either because of TimedOutException or because of HttpConnectionPool exception ?
Update
Is it a good practice to provide own routing in Zuul gateway ? using #RestController and #HystrixCommand together ? (I think its a bad idea, because over the period of time we will end up with lots of controllers and hence actual use of intelligent routing wouldn't work as expected)
Currently there is an open issue for fallbacks with feign. There is also an open issue for fallbacks with zuul.