I have a web application which pings REST service using javax.ws.rs.client when it is being deployed to tomcat. Rest service is not available on purpose.
However, if this pinging is not on a seperate thread, tomcat application will not deploy and will be stuck (I'm guessing some timeout for HTTP call?).
I can't seem to figure out why is that. Must application be deployed to tomcat to use javax.ws.rs.client since tomcat provides implementation?
These 2 methods are used to ping REST service:
private Object sendGetRequest(WebTarget webTarget, Class<?> returnClass) throws BatchConnectionException {
if (returnClass != null) {
return webTarget.request().get(returnClass);
} else {
Response response = webTarget.request().get();
validateResponseStatus(response.getStatus());
return response;
}
}
public boolean isRestAccessible() {
boolean accessible = true;
try {
batchTaskUtils.sendRequest(batchTaskUtils.getBatchWebTarget().path(Resources.ROOT), String.class,
BatchTaskUtils.RequestType.GET);
} catch (BatchConnectionException e) {
accessible = false;
}
return accessible;
}
Does not work as exptected:
public class App extends GuiceServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
super.contextInitialized(servletContextEvent);
// stuck here
isRestAccessible();
}
}
Works as expected:
public class App extends GuiceServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
super.contextInitialized(servletContextEvent);
ExecutorService loggingExecutor = Executors.newFixedThreadPool(1);
loggingExecutor.execute(() -> {
isRestAccessible();
});
}