diff --git a/src/main/java/com/openshift/client/OpenShiftConnectionFactory.java b/src/main/java/com/openshift/client/OpenShiftConnectionFactory.java index a7cc8c4a..fa9dce0a 100755 --- a/src/main/java/com/openshift/client/OpenShiftConnectionFactory.java +++ b/src/main/java/com/openshift/client/OpenShiftConnectionFactory.java @@ -181,13 +181,63 @@ protected IHttpClient createClient(final String clientId, final String username, .client(); } + protected IOpenShiftConnection getConnection(final String clientId, final String username, final String password, + final String token, final String serverUrl, IHttpClient httpClient) throws OpenShiftException, IOException { + Assert.notNull(clientId); + Assert.notNull(serverUrl); + Assert.notNull(httpClient); + + IRestService service = new RestService(serverUrl, clientId, new JsonMediaType(), + IHttpClient.MEDIATYPE_APPLICATION_JSON, new OpenShiftJsonDTOFactory(), httpClient); + return getConnection(service, username, password, token); + } + + /** + * Establish a connection with the clientId along with a user's + * authorization token + * + * @param clientId + * http client id + * @param token + * authorization token. + * @param serverUrl + * the server url. + * @return a valid connection + * @throws FileNotFoundException + * @throws IOException + * @throws OpenShiftException + */ + public IOpenShiftConnection getAuthTokenConnection(final String clientId, final String token, final String serverUrl) + throws OpenShiftException { + return getConnection(clientId, null, null, null, null, token, serverUrl, null); + } + + /** + * Establish a connection with the clientId along with a user's + * authorization token. Server URL is retrieved from the local configuration + * file (in see $USER_HOME/.openshift/express.conf) + * + * @param clientId + * http client id + * @param token + * authorization token. + * @return a valid connection + * @throws FileNotFoundException + * @throws IOException + * @throws OpenShiftException + */ + public IOpenShiftConnection getAuthTokenConnection(final String clientId, final String token) + throws OpenShiftException { + return getConnection(clientId, null, null, null, null, token, getConfiguration().getLibraServer(), null); + } + protected IOpenShiftConfiguration getConfiguration() throws OpenShiftException { if (this.configuration == null) { this.configuration = createConfiguration(); } return this.configuration; } - + protected IOpenShiftConfiguration createConfiguration() throws OpenShiftException { try { return new OpenShiftConfiguration(); @@ -196,56 +246,4 @@ protected IOpenShiftConfiguration createConfiguration() throws OpenShiftExceptio } } - protected IOpenShiftConnection getConnection(final String clientId, final String username, final String password, - final String token, final String serverUrl, IHttpClient httpClient) throws OpenShiftException, IOException { - Assert.notNull(clientId); - Assert.notNull(serverUrl); - Assert.notNull(httpClient); - - IRestService service = new RestService(serverUrl, clientId, new JsonMediaType(), - IHttpClient.MEDIATYPE_APPLICATION_JSON, new OpenShiftJsonDTOFactory(), httpClient); - return getConnection(service, username, password, token); - } - - /** - * Establish a connection with the clientId along with a user's authorization token - * - * @param clientId - * http client id - * @param token - * authorization token. - * @param serverUrl - * the server url. - * @return a valid connection - * @throws FileNotFoundException - * @throws IOException - * @throws OpenShiftException - */ - public IOpenShiftConnection getAuthTokenConnection(final String clientId,final String token, final String serverUrl) throws OpenShiftException { - return getConnection(clientId, null, null, null, null, token, serverUrl, null); - } - /** - * Establish a connection with the clientId along with a user's authorization - * token. Server URL is retrieved from the local configuration file (in - * see $USER_HOME/.openshift/express.conf) - * - * @param clientId - * http client id - * @param token - * authorization token. - * @return a valid connection - * @throws FileNotFoundException - * @throws IOException - * @throws OpenShiftException - */ - public IOpenShiftConnection getAuthTokenConnection(final String clientId, final String token) - throws OpenShiftException { - try { - configuration = new OpenShiftConfiguration(); - } catch (IOException e) { - throw new OpenShiftException(e, "Failed to load OpenShift configuration file."); - } - return getConnection(clientId, null, null, null, null, token, configuration.getLibraServer(), null); - } - }