public static String rawHttp(final String url) throws Exception { final DefaultHttpClient<Void> httpClient = createDefaultHttpClient(url); try { final Header authenticateHeader = BasicScheme.authenticate(Users.getDefaultAdminCredentials(), "UTF-8", false); final Request request = httpClient.newRequest(url); request.setHeader(authenticateHeader.getName(), authenticateHeader.getValue()); final Response r = request.get().get(); return r.getEntity(); } finally { httpClient.destroy(); } }
public static void updateOndemandLicense(final JiraTestedProduct jira, final String license) throws Exception { final String baseUrl = jira.getProductInstance().getBaseUrl(); final DefaultHttpClient<Void> httpClient = createDefaultHttpClient(baseUrl); final long debugExecutionStart = System.currentTimeMillis(); try { final Header authenticateHeader = BasicScheme.authenticate(Users.getDefaultSysAdminCredentials(), "UTF-8", false); final Request request = httpClient.newRequest(baseUrl + "/rest/ondemand/license/latest/license"); request.setEntity(license).setContentType("text/plain") .setHeader(authenticateHeader.getName(), authenticateHeader.getValue()); final Response r = request.put().get(); if (r.getStatusCode() != Status.OK.getStatusCode()) { throw new IllegalStateException("Error updating OD license " + request.getUri() + ", status code =" + r.getStatusCode() + ": " + r.getEntity()); } } finally { httpClient.destroy(); final long debugExecutionEnd = System.currentTimeMillis(); System.out.println(String.format( "DEBUG com.atlassian.jira.utils.OndemandEnvironmentTestUtils.updateOndemandLicense execution took %.3f s", (debugExecutionEnd - debugExecutionStart) / 1000.0 )); } }
private DownloadResult<I18nKeysMapping> download(DownloadResult<ResponsePromise> downloadInProgress) throws TranslationsDownloadException { URI uri = downloadInProgress.getUri(); try { Response response = downloadInProgress.getResult().get(); if (response.getStatusCode() != OK.getStatusCode()) { throw new TranslationsDownloadException(uri, "Expected 200 status code but got " + response.getStatusCode(), i18nResolver.getText("connect.install.error.i18n.download.status", response.getStatusCode())); } Map<String, String> translations = parseResponse(uri, response); validator.validate(uri, translations); return new DownloadResult<>(downloadInProgress.getLanguage(), uri, I18nKeysMapping.of(translations)); } catch (InterruptedException | ExecutionException e) { log.info("Downloading " + uri + " failed", e); throw new TranslationsDownloadException(e, uri, e.getMessage(), i18nResolver.getText("connect.install.error.i18n.download.fail")); } }