List of usage examples for org.apache.http.auth InvalidCredentialsException getMessage
public String getMessage()
From source file:com.ibm.team.build.internal.hjplugin.util.RTCFacadeFacade.java
/** * Logs into the repository to test the connection. Essentially exercises the configuration parameters supplied. * Either the rest service or the build toolkit will be used to test the connection. * //from w w w .j av a 2 s .c o m * @param buildToolkitPath The path to the build toolkit should the toolkit need to be used * @param avoidUsingToolkit Whether to avoid using the build toolkit (use rest service instead) * @param serverURI The address of the repository server * @param userId The user id to use when logging into the server * @param password The password to use when logging into the server. * @param timeout The timeout period for requests made to the server * @return an error message to display, or null if no problem * @throws Exception */ public static String testConnection(String buildToolkitPath, String serverURI, String userId, String password, int timeout, boolean avoidUsingToolkit) throws Exception { // Attempt to use Rest api if this is for a build definition if (avoidUsingToolkit) { String errorMessage = null; String uri = RTCBuildConstants.URI_COMPATIBILITY_CHECK; try { // Validate that the server version is sufficient JSON json = HttpUtils.performGet(serverURI, uri, userId, password, timeout, null, null).getJson(); errorMessage = ensureCompatability(json); if (errorMessage == null) { // Make sure the credentials are good HttpUtils.validateCredentials(serverURI, userId, password, timeout); } } catch (InvalidCredentialsException e) { errorMessage = e.getMessage(); } catch (IOException e) { errorMessage = e.getMessage(); } return errorMessage; } else { // use the toolkit to test the connection RTCFacadeWrapper facade = RTCFacadeFactory.getFacade(buildToolkitPath, null); String errorMessage = (String) facade.invoke("testConnection", new Class[] { //$NON-NLS-1$ String.class, // serverURI String.class, // userId String.class, // password int.class, // timeout Locale.class }, // clientLocale serverURI, userId, password, timeout, LocaleProvider.getLocale()); return errorMessage; } }
From source file:com.ibm.team.build.internal.hjplugin.util.RTCFacadeFacade.java
/** * Logs into the repository to test the connection and validates the RTC build definition is valid for use. * password first.// w w w.j ava 2 s . c om * The rest service or the build toolkit will be used * * @param buildToolkitPath The path to the build toolkit should the toolkit need to be used * @param avoidUsingToolkit Whether to avoid using the build toolkit (use rest service instead) * @param serverURI The address of the repository server * @param userId The user id to use when logging into the server * @param password The password to use when logging into the server. * @param timeout The timeout period for requests made to the server * @param buildDefinition The name of the RTC build definition * @return an error message to display, or null if no problem * @throws Exception */ public static String testBuildDefinition(String buildToolkitPath, String serverURI, String userId, String password, int timeout, boolean avoidUsingToolkit, String buildDefinitionId) throws Exception { if (avoidUsingToolkit) { // Make sure that the server is compatible. Rest api on older releases ignores // the query parameter which would mean it finding more than returning possibly > 1 element String errorMessage = null; String uri = RTCBuildConstants.URI_COMPATIBILITY_CHECK; try { // Validate that the server version is sufficient GetResult getResult = HttpUtils.performGet(serverURI, uri, userId, password, timeout, null, null); errorMessage = ensureCompatability(getResult.getJson()); if (errorMessage != null) { return errorMessage; } // validate the build definition exists uri = RTCBuildConstants.URI_DEFINITIONS + "?" //$NON-NLS-1$ + RTCBuildConstants.QUERY_PARAM_BUILD_DEFINITION + "=" //$NON-NLS-1$ + Util.encode(buildDefinitionId); // Since we are going to make more than one Rest call, hang onto the context so that // login only needs to be done once. HttpClientContext context = getResult.getHttpContext(); getResult = HttpUtils.performGet(serverURI, uri, userId, password, timeout, context, null); JSON json = getResult.getJson(); if (json instanceof JSONArray) { JSONArray definitions = (JSONArray) json; if (definitions.size() == 0) { // not found return Messages.RTCFacadeFacade_definition_not_found(buildDefinitionId); } else { // validate the build definition is a hudson/jenkins build definition JSONObject buildDefinition = definitions.getJSONObject(0); boolean found = JSONHelper.searchJSONArray(buildDefinition, JSON_PROP_CONFIGURATION_ELEMENTS, JSON_PROP_ELEMENT_ID, RTCBuildConstants.HJ_ELEMENT_ID); if (!found) { return Messages.RTCFacadeFacade_build_definition_missing_hudson_config(); } // validate the build definition as a Jazz Source Control option found = JSONHelper.searchJSONArray(buildDefinition, JSON_PROP_CONFIGURATION_ELEMENTS, JSON_PROP_ELEMENT_ID, RTCBuildConstants.SCM_ELEMENT_ID); if (!found) { return Messages.RTCFacadeFacade_build_definition_missing_jazz_scm_config(); } // get the supporting build engines for the definition uri = RTCBuildConstants.URI_DEFINITION + SLASH + buildDefinition.getString(JSON_PROP_ITEM_ID) + SLASH + RTCBuildConstants.URI_SEGMENT_SUPPORTING_ENGINES; getResult = HttpUtils.performGet(serverURI, uri, userId, password, timeout, context, null); context = getResult.getHttpContext(); json = getResult.getJson(); JSONArray engineStatusRecords = JSONHelper.getJSONArray(json, JSON_PROP_ENGINE_STATUS_RECORDS); if (engineStatusRecords != null && engineStatusRecords.size() > 0) { JSONObject buildEngineStatusRecord = engineStatusRecords.getJSONObject(0); JSONObject buildEngine = buildEngineStatusRecord.getJSONObject(JSON_PROP_BUILD_ENGINE); // validate the build definition has a hudson/jenkins build engine found = JSONHelper.searchJSONArray(buildEngine, JSON_PROP_CONFIGURATION_ELEMENTS, JSON_PROP_ELEMENT_ID, RTCBuildConstants.HJ_ENGINE_ELEMENT_ID); if (!found) { return Messages .RTCFacadeFacade_build_definition_missing_build_engine_hudson_config(); } // everything is valid return null; } return Messages.RTCFacadeFacade_build_definition_missing_build_engine(); } } else { LOGGER.finer("Unexpected response to " + uri + " received: " //$NON-NLS-1$//$NON-NLS-2$ + (json == null ? "null" : json.toString(4))); //$NON-NLS-1$ throw new IOException(Messages.RTCFacadeFacade_unexpected_validate_build_definition_response( uri, (json == null ? "null" : json.toString(4)))); //$NON-NLS-1$ } } catch (InvalidCredentialsException e) { errorMessage = e.getMessage(); } catch (IOException e) { errorMessage = e.getMessage(); } return errorMessage; } else { // Use the toolkit to validate the build definition LOGGER.finer("Testing Build Definition using the toolkit"); //$NON-NLS-1$ RTCFacadeWrapper facade = RTCFacadeFactory.getFacade(buildToolkitPath, null); String errorMessage = (String) facade.invoke("testBuildDefinition", //$NON-NLS-1$ new Class[] { String.class, // serverURI String.class, // userId String.class, // password int.class, // timeout String.class, // buildDefinition Locale.class }, // clientLocale serverURI, userId, password, timeout, buildDefinitionId, LocaleProvider.getLocale()); return errorMessage; } }
From source file:org.apache.cloudstack.storage.datastore.util.ElastistorUtil.java
/** * This intializes a new jersey restclient for http call with elasticenter *///from ww w .ja v a 2s. com public static ElastiCenterClient getElastistorRestClient() { ElastiCenterClient restclient = null; try { String ip = getConfigurationDao().getValue("cloudbyte.management.ip"); String apikey = getConfigurationDao().getValue("cloudbyte.management.apikey"); if (ip == null) { throw new CloudRuntimeException("set the value of cloudbyte.management.ip in global settings"); } if (apikey == null) { throw new CloudRuntimeException("set the value of cloudbyte.management.apikey in global settings"); } restclient = new ElastiCenterClient(ip, apikey); } catch (InvalidCredentialsException e) { throw new CloudRuntimeException("InvalidCredentialsException:" + e.getMessage(), e); } catch (InvalidParameterException e) { throw new CloudRuntimeException("InvalidParameterException:" + e.getMessage(), e); } catch (SSLHandshakeException e) { throw new CloudRuntimeException("SSLHandshakeException:" + e.getMessage(), e); } catch (ServiceUnavailableException e) { throw new CloudRuntimeException("ServiceUnavailableException:" + e.getMessage(), e); } return restclient; }