@TestConnectivity
public void testConnect(String username, String password, String url, String optionalConnectionParam)
throws ConnectionException
{
if (StringUtils.isBlank(username) || StringUtils.isBlank(password)){
throw new ConnectionException(ConnectionExceptionCode.INCORRECT_CREDENTIALS,
"001", "Username or Password is blank");
}
if ( !StringUtils.isBlank(optionalConnectionParam) && !validParams(optionalConnectionParam)){
throw new ConnectionException(ConnectionExceptionCode.INCORRECT_CREDENTIALS,
"002", "Given connection parameters are not valid for this connection");
}
UrlValidator urlValidator = new UrlValidator();
if ( !urlValidator.isValid(url)){
throw new ConnectionException(ConnectionExceptionCode.UNKNOWN_HOST, "003", "Url is not valid");
}
Result result = new ServiceClient(username, password).test(url);
if ( !result.success()){
throw new ConnectionException(result.cause(), result.code(), result.message());
}
}
@Connect
public void connect(@ConnectionKey String username, @Password String password,
@Optional @Default("http://www.mulesoft.org") String url,
@Optional String optionalConnectionParam)
throws ConnectionException
{
ServiceClient client = new ServiceClient(username, password);
try {
client.connect(url, optionalConnectionParams);
} catch (ServiceConnectionException e) {
throw new ConnectionException(getExceptionCode(e.getCause()), e.getCode(), e.getMessage(), e);
}
}