Change Retries and Timeout of RTC connection from Java Plain API script
Hello,
I am doing some code with RTC API Java Plain which connect into RTC and then perform some actions.
In the part of my code which connect to RTC and login, I added a try/catch sentences so if the server is unavailable,
then I can catch the exception and give some custom message:
def loginRTC(repositoryUri, user, passwd){
try {
TeamPlatform.startup();
// Login to the repository using the provided credentials
ITeamRepository repository = TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryUri)
repository.registerLoginHandler(new ILoginHandler2() {
@Override
public ILoginInfo2 challenge(ITeamRepository arg0) {
return new UsernameAndPasswordLoginInfo(user, passwd)
}
});
repository.login(new SysoutProgressMonitor())
return repository
}
catch (Exception e) {
println "\tError message is: " + e.getCause() + ", String: " + e.getCause().toString()
return -1
}
/*catch (AuthenticationException e) {
return -1
}*/
}
But what I see in my console output is that the connection retries many times until it throws an error with timeout:
Trying to connect into RTC....
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
INFO I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO Retrying request
Error message is: java.net.ConnectException: Connection timed out: connect, String: java.net.ConnectException: Connection timed out: connect
So, my question is:
Is there a way to specify that do not perform retries? Or to specifify a limited number or retries and timeout to connect in RTC from my script?
Thanks a lot for the help.
Accepted answer
In this case, I'd recommend to just check if the server is alive or not. For example, if ping is allowed, then java net inetaddress isreachable() might be easy solution. Another is to create http session and try to obtain login page of RTC. If these succeeds, then you can try login procedure.