use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.
the class OpenShiftConnectionRequirement method fulfill.
@Override
public void fulfill() {
String server = TestUtils.getValueOrDefault(connectionSpec.server(), DatastoreOS3.SERVER);
String username = TestUtils.getValueOrDefault(connectionSpec.username(), DatastoreOS3.USERNAME);
String password = TestUtils.getValueOrDefault(connectionSpec.password(), DatastoreOS3.PASSWORD);
String token = TestUtils.getValueOrDefault(connectionSpec.token(), DatastoreOS3.TOKEN);
try {
ConnectionURL url;
if (StringUtils.isNotEmpty(password) && StringUtils.isNotEmpty(username)) {
url = getConnectionURL(username, server);
} else {
url = getConnectionURL(server);
}
Connection connection = ConnectionsRegistrySingleton.getInstance().getByUrl(url, Connection.class);
if (connection == null) {
LOGGER.debug(NLS.bind("No connection for {0} found. Creating a new one.", url));
connection = createConnection(server, username, password, token);
ConnectionsRegistrySingleton.getInstance().add(connection);
}
LOGGER.debug(NLS.bind("Connecting to OpenShift 3 server at {0}", url));
connection.connect();
this.connection = connection;
} catch (UnsupportedEncodingException | MalformedURLException e) {
throw new OpenShiftToolsException(NLS.bind("Could not create connection for {0} : {1}", server, e));
}
}
use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.
the class ConnectionURLTest method shouldExtractUrlPortions.
@Test
public void shouldExtractUrlPortions() throws UnsupportedEncodingException, MalformedURLException {
// pre-conditions
String scheme = UrlUtils.SCHEME_HTTP;
String username = "adietish@redhat.com";
String password = "12345";
String server = "openshift.redhat.com";
// operations
ConnectionURL connectionUrl = ConnectionURL.forURL(scheme + URLEncoder.encode(username, "UTF-8") + ":" + password + "@" + server);
// verifications
assertEquals(scheme, connectionUrl.getScheme());
assertEquals(username, connectionUrl.getUsername());
assertEquals(server, connectionUrl.getHost());
assertEquals(scheme + server, connectionUrl.getHostWithScheme());
}
use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.
the class ConnectionURLTest method shouldAllowPortInUrl.
@Test
public void shouldAllowPortInUrl() throws UnsupportedEncodingException, MalformedURLException {
// pre-conditions
// operations
ConnectionURL connectionUrl = ConnectionURL.forURL("http://adietish%40redhat.com@localhost:8081");
// verifications
assertEquals("http://localhost:8081", connectionUrl.getHostWithScheme());
}
use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.
the class ConnectionRegistryTest method shouldGetConnectionByUrl.
@Test
public void shouldGetConnectionByUrl() throws UnsupportedEncodingException, MalformedURLException {
// pre-conditions
registry.add(connection);
// operations
ConnectionURL connectionUrl = ConnectionURL.forConnection(connection);
IConnection queriedConnection = registry.getByUrl(connectionUrl);
// verifications
assertEquals(connection, queriedConnection);
}
use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.
the class OpenShiftServerUtils method getConnection.
/**
* Returns the connection for the given server. Returns {@code null} if none was
* found.
*
* @param server
* @return
*/
public static Connection getConnection(IServerAttributes server) {
if (server == null) {
return null;
}
Connection connection = null;
try {
String url = getConnectionURL(server);
if (StringUtils.isEmpty(url)) {
return null;
}
ConnectionURL connectionUrl = ConnectionURL.forURL(url);
if (connectionUrl != null) {
connection = ConnectionsRegistrySingleton.getInstance().getByUrl(connectionUrl, Connection.class);
}
if (connection == null) {
OpenShiftCoreActivator.pluginLog().logError(NLS.bind("Could not find an existing OpenShift connection to host {0} with user {1} for server {2}", new String[] { connectionUrl.getHost(), connectionUrl.getUsername(), server.getName() }));
}
} catch (UnsupportedEncodingException | MalformedURLException e) {
OpenShiftCoreActivator.pluginLog().logError(NLS.bind("Connection url stored in server {0} is malformed.", server.getName()), e);
}
return connection;
}
Aggregations