Commit b7b62f86 authored by Michel Schudel's avatar Michel Schudel

geen requests doorlaten zolang de initialisatiefase nog niet voorbij is.

parent c217628b
......@@ -22,14 +22,16 @@ class ApplicationStartedListener implements ApplicationListener<ApplicationStart
private final Network network;
private final BlockchainService blockchainService;
private final SignatureService signatureService;
private final StartedInterceptor startedInterceptor;
@Autowired
public ApplicationStartedListener(Environment environment, InstanceInfo instanceInfo, Network network, BlockchainService blockchainService, SignatureService signatureService) {
public ApplicationStartedListener(Environment environment, InstanceInfo instanceInfo, Network network, BlockchainService blockchainService, SignatureService signatureService, StartedInterceptor startedInterceptor) {
this.environment = environment;
this.instanceInfo = instanceInfo;
this.network = network;
this.blockchainService = blockchainService;
this.signatureService = signatureService;
this.startedInterceptor = startedInterceptor;
}
@Override
......@@ -42,5 +44,6 @@ class ApplicationStartedListener implements ApplicationListener<ApplicationStart
network.connectToNetwork();
blockchainService.init();
signatureService.init();
startedInterceptor.setOpen(true);
}
}
package nl.craftsmen.blockchain.craftscoinnode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {
@Bean
public StartedInterceptor startedInterceptor() {
return new StartedInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(startedInterceptor());
}
}
package nl.craftsmen.blockchain.craftscoinnode;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class StartedInterceptor implements HandlerInterceptor {
private boolean isOpen = false;
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if (!isOpen) {
throw new RuntimeException("no open for business yet!");
} else {
return true;
}
}
public void setOpen(boolean open) {
isOpen = open;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment