org.apache.brooklyn.util.http.HttpTool Java Examples
The following examples show how to use
org.apache.brooklyn.util.http.HttpTool.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SeaCloudsMonitoringInitializationPolicies.java From SeaCloudsPlatform with Apache License 2.0 | 6 votes |
private void postSeaCloudsDcConfiguration(String requestBody) { URI apiEndpoint = URI.create(getConfig(SEACLOUDS_DC_ENDPOINT) + RESOURCES); Map<String, String> headers = MutableMap.of( HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString(), HttpHeaders.ACCEPT, MediaType.JSON_UTF_8.toString()); HttpToolResponse response = HttpTool .httpPost(HttpTool.httpClientBuilder().build(), apiEndpoint, headers, requestBody.getBytes()); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { throw new RuntimeException("Something went wrong during SeaCloudsDc configuration, " + response.getResponseCode() + ":" + response.getContentAsString()); } }
Example #2
Source File: BrooklynLauncherTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups="Integration") public void testStartsWebServerWithCredentials() throws Exception { launcher = newLauncherForTests(true) .restServerPort("10000+") .brooklynProperties(BrooklynWebConfig.USERS, "myname") .brooklynProperties(BrooklynWebConfig.PASSWORD_FOR_USER("myname"), "mypassword") .start(); String uri = launcher.getServerDetails().getWebServerUrl(); HttpToolResponse response = HttpTool.execAndConsume(HttpTool.httpClientBuilder().build(), new HttpGet(uri)); assertEquals(response.getResponseCode(), 401); HttpToolResponse response2 = HttpTool.execAndConsume( HttpTool.httpClientBuilder() .uri(uri) .credentials(new UsernamePasswordCredentials("myname", "mypassword")) .build(), new HttpGet(uri)); assertEquals(response2.getResponseCode(), 200); }
Example #3
Source File: VaultExternalConfigSupplier.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected JsonObject apiPost(String path, ImmutableMap<String, String> headers, ImmutableMap<String, String> requestData) { try { String body = gson.toJson(requestData); String uri = Urls.mergePaths(endpoint, path); LOG.trace("Vault request - POST: {}", uri); HttpToolResponse response = HttpTool.httpPost(httpClient, Urls.toUri(uri), headers, body.getBytes(CHARSET_NAME)); LOG.trace("Vault response - code: {} {}", response.getResponseCode(), response.getReasonPhrase()); String responseBody = new String(response.getContent(), CHARSET_NAME); if (HttpTool.isStatusCodeHealthy(response.getResponseCode())) { return gson.fromJson(responseBody, JsonObject.class); } else { throw new IllegalStateException("HTTP request returned error"); } } catch (UnsupportedEncodingException e) { throw Exceptions.propagate(e); } }
Example #4
Source File: BrooklynWebServerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
private void verifyHttpsFromConfig(BrooklynProperties brooklynProperties) throws Exception { webServer = new BrooklynWebServer(MutableMap.of(), newManagementContext(brooklynProperties)); webServer.skipSecurity(); webServer.start(); try { KeyStore keyStore = load("client.ks", "password"); KeyStore trustStore = load("client.ts", "password"); SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.TLS, keyStore, "password", trustStore, (SecureRandom)null, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpToolResponse response = HttpTool.execAndConsume( HttpTool.httpClientBuilder() .port(webServer.getActualPort()) .https(true) .socketFactory(socketFactory) .build(), new HttpGet(webServer.getRootUrl())); assertEquals(response.getResponseCode(), 200); } finally { webServer.stop(); } }
Example #5
Source File: VaultExternalConfigSupplier.java From brooklyn-server with Apache License 2.0 | 6 votes |
public VaultExternalConfigSupplier(ManagementContext managementContext, String name, Map<String, String> config) { super(managementContext, name); this.config = config; this.name = name; httpClient = HttpTool.httpClientBuilder().build(); gson = new GsonBuilder().create(); List<String> errors = Lists.newArrayListWithCapacity(2); endpoint = config.get("endpoint"); if (Strings.isBlank(endpoint)) errors.add("missing configuration 'endpoint'"); path = config.get("path"); if (Strings.isBlank(path)) errors.add("missing configuration 'path'"); if (!errors.isEmpty()) { String message = String.format("Problem configuration Vault external config supplier '%s': %s", name, Joiner.on(System.lineSeparator()).join(errors)); throw new IllegalArgumentException(message); } token = initAndLogIn(config); headersWithToken = ImmutableMap.<String, String>builder() .putAll(MINIMAL_HEADERS) .put("X-Vault-Token", token) .build(); }
Example #6
Source File: BrooklynWebServerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void verifySecurityInitializedExplicitUser() throws Exception { webServer = new BrooklynWebServer(newManagementContext(brooklynProperties)); webServer.start(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("myuser", "somepass")); HttpClient client = HttpTool.httpClientBuilder() .credentials(new UsernamePasswordCredentials("myuser", "somepass")) .uri(webServer.getRootUrl()) .build(); try { HttpToolResponse response = HttpTool.execAndConsume(client, new HttpGet(webServer.getRootUrl())); assertEquals(response.getResponseCode(), 401); } finally { webServer.stop(); } }
Example #7
Source File: SeaCloudsManagementPolicy.java From SeaCloudsPlatform with Apache License 2.0 | 6 votes |
private HttpToolResponse delete(String url, String mediaType, String username, String password) { URI apiEndpoint = URI.create(url); // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials if (username == null || password == null) { return HttpTool.httpDelete(HttpTool.httpClientBuilder().build(), apiEndpoint, MutableMap.of(HttpHeaders.CONTENT_TYPE, mediaType, HttpHeaders.ACCEPT, mediaType)); } else { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials return HttpTool.httpDelete(HttpTool.httpClientBuilder().uri(apiEndpoint).credentials(credentials).build(), apiEndpoint, MutableMap.of(HttpHeaders.CONTENT_TYPE, mediaType, HttpHeaders.ACCEPT, mediaType, HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials))); } }
Example #8
Source File: BrooklynPropertiesSecurityFilterTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
private String startAppAtNode(Server server) throws Exception { String blueprint = "name: TestApp\n" + "location: localhost\n" + "services:\n" + "- type: org.apache.brooklyn.test.entity.TestEntity"; HttpClient client = HttpTool.httpClientBuilder() .uri(getBaseUriRest(server)) .build(); HttpToolResponse response = HttpTool.httpPost(client, URI.create(getBaseUriRest() + "applications"), ImmutableMap.of(HttpHeaders.CONTENT_TYPE, "application/x-yaml"), blueprint.getBytes()); assertTrue(HttpTool.isStatusCodeHealthy(response.getResponseCode()), "error creating app. response code=" + response.getResponseCode()); @SuppressWarnings("unchecked") Map<String, Object> body = new ObjectMapper().readValue(response.getContent(), HashMap.class); return (String) body.get("entityId"); }
Example #9
Source File: SeaCloudsManagementPolicy.java From SeaCloudsPlatform with Apache License 2.0 | 6 votes |
private HttpToolResponse post(String url, String mediaType, String username, String password, byte[] payload) { URI apiEndpoint = URI.create(url); // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials if (username == null || password == null) { return HttpTool.httpPost(HttpTool.httpClientBuilder().build(), apiEndpoint, MutableMap.of(HttpHeaders.CONTENT_TYPE, mediaType, HttpHeaders.ACCEPT, mediaType), payload); } else { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials return HttpTool.httpPost(HttpTool.httpClientBuilder().uri(apiEndpoint).credentials(credentials).build(), apiEndpoint, MutableMap.of(HttpHeaders.CONTENT_TYPE, mediaType, HttpHeaders.ACCEPT, mediaType, HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)), payload); } }
Example #10
Source File: DeployBlueprintTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testStartsAppViaEffector() throws Exception { URI webConsoleUri = URI.create(ENDPOINT_ADDRESS_HTTP); // BrooklynNode will append "/v1" to it EntitySpec<BrooklynNode> spec = EntitySpec.create(BrooklynNode.class); EntityManager mgr = getManagementContext().getEntityManager(); // getManagementContextFromJettyServerAttributes(server).getEntityManager(); BrooklynNode node = mgr.createEntity(spec); node.sensors().set(BrooklynNode.WEB_CONSOLE_URI, webConsoleUri); mgr.manage(node); Map<String, String> params = ImmutableMap.of(DeployBlueprintEffector.BLUEPRINT_CAMP_PLAN.getName(), "{ services: [ serviceType: \"java:"+BasicApplication.class.getName()+"\" ] }"); String id = node.invoke(BrooklynNode.DEPLOY_BLUEPRINT, params).getUnchecked(); log.info("got: "+id); String apps = HttpTool.getContent(getEndpointAddress() + "/applications"); List<String> appType = parseJsonList(apps, ImmutableList.of("spec", "type"), String.class); assertEquals(appType, ImmutableList.of(BasicApplication.class.getName())); String status = HttpTool.getContent(getEndpointAddress()+"/applications/"+id+"/entities/"+id+"/sensors/service.status"); log.info("STATUS: "+status); }
Example #11
Source File: MonitorUtils.java From brooklyn-library with Apache License 2.0 | 6 votes |
/** * Confirm can read from URL. * * @param url */ public static boolean isUrlUp(URL url) { try { HttpToolResponse result = HttpTool.httpGet( HttpTool.httpClientBuilder().trustAll().build(), URI.create(url.toString()), ImmutableMap.<String,String>of()); int statuscode = result.getResponseCode(); if (statuscode != 200) { LOG.info("Error reading URL {}: {}, {}", new Object[]{url, statuscode, result.getReasonPhrase()}); return false; } else { return true; } } catch (Exception e) { LOG.info("Error reading URL {}: {}", url, e); return false; } }
Example #12
Source File: GeoscalingWebClientTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Override @BeforeMethod(alwaysRun = true) public void setUp() throws Exception { // Want to load username and password from user's properties. mgmt = LocalManagementContextForTests.newInstance(BrooklynProperties.Factory.newDefault()); String username = getBrooklynProperty(mgmt, "brooklyn.geoscaling.username"); String password = getBrooklynProperty(mgmt, "brooklyn.geoscaling.password"); if (username == null || password == null) { throw new SkipException("Set brooklyn.geoscaling.username and brooklyn.geoscaling.password in brooklyn.properties to enable test"); } // Insecurely use "trustAll" so that don't need to import signature into trust store // before test will work on jenkins machine. HttpClient httpClient = HttpTool.httpClientBuilder().uri(GEOSCALING_URL).trustAll().build(); geoscaling = new GeoscalingWebClient(httpClient); geoscaling.login(username, password); super.setUp(); }
Example #13
Source File: WebAppConcurrentDeployTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Test(groups = "Live", dataProvider="basicEntities") public void testConcurrentDeploys(EntitySpec<? extends JavaWebAppSoftwareProcess> webServerSpec) throws Exception { JavaWebAppSoftwareProcess server = app.createAndManageChild(webServerSpec); app.start(ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(server, Attributes.SERVICE_UP, Boolean.TRUE); Collection<Task<Void>> deploys = MutableList.of(); for (int i = 0; i < 5; i++) { deploys.add(server.invoke(TomcatServer.DEPLOY, MutableMap.of("url", getTestWar(), "targetName", "/"))); } for(Task<Void> t : deploys) { t.getUnchecked(); } final HttpClient client = HttpTool.httpClientBuilder().build(); final URI warUrl = URI.create(server.getAttribute(JavaWebAppSoftwareProcess.ROOT_URL)); Asserts.succeedsEventually(new Runnable() { @Override public void run() { HttpToolResponse resp = HttpTool.httpGet(client, warUrl, ImmutableMap.<String,String>of()); assertEquals(resp.getResponseCode(), 200); } }); }
Example #14
Source File: GeoscalingDnsServiceImpl.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Override public void init() { super.init(); // defaulting to randomized subdomains makes deploying multiple applications easier if (config().get(RANDOMIZE_SUBDOMAIN_NAME) == null) { config().set(RANDOMIZE_SUBDOMAIN_NAME, true); } Boolean trustAll = config().get(SSL_TRUST_ALL); if (Boolean.TRUE.equals(trustAll)) { webClient = new GeoscalingWebClient(HttpTool.httpClientBuilder().trustAll().build()); } else { webClient = new GeoscalingWebClient(); } }
Example #15
Source File: SeaCloudsManagementPolicy.java From SeaCloudsPlatform with Apache License 2.0 | 6 votes |
private void installMonitoringRules() { LOG.info("SeaCloudsInitializerPolicy is installing T4C Monitoring Rules for " + entity.getId()); HttpToolResponse response = post(getConfig(T4C_ENDPOINT) + "/v1/monitoring-rules", MediaType.APPLICATION_XML_UTF_8.toString(), getConfig(T4C_USERNAME), getConfig(T4C_PASSWORD), BaseEncoding.base64().decode(getConfig(T4C_RULES))); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { throw new RuntimeException("Something went wrong while the monitoring rules installation. " + "Invalid response code, " + response.getResponseCode() + ":" + response.getContentAsString()); } else { List<String> ruleIds = new ArrayList<>(); for (MonitoringRule rule : monitoringRules.getMonitoringRules()) { ruleIds.add(rule.getId()); } entity.sensors().set(T4C_IDS, ruleIds); } }
Example #16
Source File: CorsFilterLauncherTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void test1CorsIsEnabledOnAllDomainsGET() throws IOException { final String shouldAllowOrigin = "http://foo.bar.com"; setCorsFilterFeature(true, ImmutableList.<String>of()); HttpClient client = client(); // preflight request HttpToolResponse response = HttpTool.execAndConsume(client, httpOptionsRequest("server/ha/state", "GET", shouldAllowOrigin)); List<String> accessControlAllowOrigin = response.getHeaderLists().get(HEADER_AC_ALLOW_ORIGIN); assertEquals(accessControlAllowOrigin.size(), 1); assertEquals(accessControlAllowOrigin.get(0), "*", "Should allow GET requests made from " + shouldAllowOrigin); assertEquals(response.getHeaderLists().get(HEADER_AC_ALLOW_HEADERS).size(), 1); assertEquals(response.getHeaderLists().get(HEADER_AC_ALLOW_HEADERS).get(0), "x-csrf-token", "Should have asked and allowed x-csrf-token header from " + shouldAllowOrigin); assertOkayResponse(response, ""); HttpUriRequest httpRequest = RequestBuilder.get(getBaseUriRest() + "server/ha/state") .addHeader("Origin", shouldAllowOrigin) .addHeader(HEADER_AC_REQUEST_METHOD, "GET") .build(); response = HttpTool.execAndConsume(client, httpRequest); accessControlAllowOrigin = response.getHeaderLists().get(HEADER_AC_ALLOW_ORIGIN); assertEquals(accessControlAllowOrigin.size(), 1); assertEquals(accessControlAllowOrigin.get(0), "*", "Should allow GET requests made from " + shouldAllowOrigin); assertOkayResponse(response, "\"MASTER\""); }
Example #17
Source File: SeaCloudsManagementPolicy.java From SeaCloudsPlatform with Apache License 2.0 | 6 votes |
private void installGrafanaDashboards() { try { HttpToolResponse response = post(getConfig(GRAFANA_ENDPOINT) + "/api/dashboards/db", MediaType.JSON_UTF_8.toString(), getConfig(GRAFANA_USERNAME), getConfig(GRAFANA_PASSWORD), grafanaInitializerPayload.getBytes()); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { throw new RuntimeException("Something went wrong while installing Grafana Dashboards. " + "Invalid response code, " + response.getResponseCode() + ":" + response.getContentAsString()); } // Retrieving unique slug to be able to remove the Dashboard later ObjectMapper mapper = new ObjectMapper(); JsonNode json = mapper.readTree(response.getContent()); grafanaDashboardSlug = json.get("slug").asText(); } catch (Exception e) { Exceptions.propagateIfFatal(e); LOG.warn("Error installingGrafanaDashboards, using " + getConfig(GRAFANA_ENDPOINT) + "/api/dashboards/db {}", e); } }
Example #18
Source File: HttpToolIntegrationTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(groups = {"Integration"}) public void testHttpsGetWithTrustAll() throws Exception { URI baseUri = new URI(httpsService.getUrl()); HttpClient client = HttpTool.httpClientBuilder().https(true).trustAll().build(); HttpToolResponse result = HttpTool.httpGet(client, baseUri, ImmutableMap.<String,String>of()); assertTrue(new String(result.getContent()).contains("Hello, World"), "val="+new String(result.getContent())); }
Example #19
Source File: SeaCloudsManagementPolicy.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
private void notifyRulesReady() { LOG.info("SeaCloudsInitializerPolicy is starting to enforce SLA Agreements for " + entity.getId()); HttpToolResponse response = post(getConfig(SLA_ENDPOINT) + "/seaclouds/commands/rulesready?agreementId=" + agreement.getAgreementId(), MediaType.APPLICATION_XML_UTF_8.toString(), getConfig(SLA_USERNAME), getConfig(SLA_PASSWORD), "".getBytes()); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { throw new RuntimeException("Something went wrong during the SLA Agreements installation. " + "Invalid response code, " + response.getResponseCode() + ":" + response.getContentAsString()); } }
Example #20
Source File: HttpToolIntegrationTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(groups = {"Integration"}) public void testHttpsPostWithTrustSelfSigned() throws Exception { URI baseUri = new URI(httpsService.getUrl()); HttpClient client = HttpTool.httpClientBuilder().https(true).trustSelfSigned().build(); HttpToolResponse result = HttpTool.httpPost(client, baseUri, ImmutableMap.<String,String>of(), new byte[0]); assertTrue(new String(result.getContent()).contains("Hello, World"), "val="+new String(result.getContent())); }
Example #21
Source File: TestHttpCallImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
private HttpRequestBase createHttpMethod(HttpMethod method, String url, Map<String, String> headers, String body) throws Exception { return new HttpTool.HttpRequestBuilder<>(method.requestClass) .uri(new URI(url)) .body(body) .headers(headers) .build(); }
Example #22
Source File: SeaCloudsManagementPolicy.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
private void installSLA() { LOG.info("SeaCloudsInitializerPolicy is installing SLA Agreements for " + entity.getId()); HttpToolResponse response = post(getConfig(SLA_ENDPOINT) + "/seaclouds/agreements", MediaType.APPLICATION_XML_UTF_8.toString(), getConfig(SLA_USERNAME), getConfig(SLA_PASSWORD), BaseEncoding.base64().decode(getConfig(SLA_AGREEMENT))); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { throw new RuntimeException("Something went wrong during the SLA Agreements installation. " + "Invalid response code, " + response.getResponseCode() + ":" + response.getContentAsString()); } else { entity.sensors().set(SLA_ID, agreement.getAgreementId()); } }
Example #23
Source File: HttpToolSNITest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(groups = {"Integration", "Broken"}) public void testHttpGetRequiringSNI() throws Exception { URI baseUri = new URI("https://httpbin.org/get?id=myId"); HttpClient client = org.apache.brooklyn.util.http.HttpTool.httpClientBuilder().build(); org.apache.brooklyn.util.http.HttpToolResponse result = HttpTool.httpGet(client, baseUri, ImmutableMap.<String,String>of()); assertEquals(result.getResponseCode(), 200); }
Example #24
Source File: BrooklynJacksonSerializerIntegrationTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override @BeforeMethod(alwaysRun = true) public void setUp() throws Exception { super.setUp(); server = BrooklynRestApiLauncher.launcher().managementContext(mgmt).start(); client = HttpTool.httpClientBuilder().build(); String serverAddress = "http://localhost:"+((NetworkConnector)server.getConnectors()[0]).getLocalPort(); String appUrl = serverAddress + "/v1/applications/" + app.getId(); entityUrl = URI.create(appUrl + "/entities/" + app.getId()); configUri = new URIBuilder(entityUrl + "/config/" + TestEntity.CONF_OBJECT.getName()) .addParameter("raw", "true") .build(); }
Example #25
Source File: BrooklynRestApiLauncherTestFixture.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected HttpClient newClient(String user) throws Exception { HttpTool.HttpClientBuilder builder = httpClientBuilder() .uri(getBaseUriRest()); if (user != null) { builder.credentials(new UsernamePasswordCredentials(user, "ignoredPassword")); } return builder.build(); }
Example #26
Source File: BrooklynPropertiesSecurityFilterTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") private String getTestEntityInApp(Server server, String appId) throws Exception { HttpClient client = HttpTool.httpClientBuilder() .uri(getBaseUriRest(server)) .build(); List entities = new ObjectMapper().readValue( HttpTool.httpGet(client, URI.create(getBaseUriRest(server) + "applications/" + appId + "/entities"), MutableMap.<String, String>of()).getContent(), List.class); LOG.info((String) ((Map) entities.get(0)).get("id")); return (String) ((Map) entities.get(0)).get("id"); }
Example #27
Source File: ServerResourceIntegrationTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
private String getServerUser(Server server) throws Exception { HttpClient client = httpClientBuilder() .uri(getBaseUriRest(server)) .credentials(TestSecurityProvider.CREDENTIAL) .build(); HttpToolResponse response = HttpTool.httpGet(client, URI.create(getBaseUriRest(server) + "server/user"), ImmutableMap.<String, String>of()); HttpAsserts.assertHealthyStatusCode(response.getResponseCode()); return new Gson().fromJson(response.getContentAsString(), String.class); }
Example #28
Source File: CorsFilterLauncherTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void test2CorsIsDisabled() throws IOException { BrooklynFeatureEnablement.disable(BrooklynFeatureEnablement.FEATURE_CORS_CXF_PROPERTY); final String shouldAllowOrigin = "http://foo.bar.com"; setCorsFilterFeature(false, null); HttpClient client = client(); HttpToolResponse response = HttpTool.execAndConsume(client, httpOptionsRequest("server/ha/state", "GET", shouldAllowOrigin)); assertAcNotAllowOrigin(response); assertOkayResponse(response, ""); response = HttpTool.execAndConsume(client, httpOptionsRequest("script/groovy", shouldAllowOrigin, "POST")); assertAcNotAllowOrigin(response); assertOkayResponse(response, ""); }
Example #29
Source File: CouchbaseNodeImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
protected void renameServerToPublicHostname() { // http://docs.couchbase.com/couchbase-manual-2.5/cb-install/#couchbase-getting-started-hostnames URI apiUri = null; try { HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(COUCHBASE_WEB_ADMIN_PORT)); apiUri = URI.create(String.format("http://%s:%d/node/controller/rename", accessible.getHostText(), accessible.getPort())); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(getConfig(COUCHBASE_ADMIN_USERNAME), getConfig(COUCHBASE_ADMIN_PASSWORD)); HttpToolResponse response = HttpTool.httpPost( // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials HttpTool.httpClientBuilder().uri(apiUri).credentials(credentials).build(), apiUri, MutableMap.of( HttpHeaders.CONTENT_TYPE, MediaType.FORM_DATA.toString(), HttpHeaders.ACCEPT, "*/*", // this appears needed; without it we get org.apache.http.NoHttpResponseException !? HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)), Charsets.UTF_8.encode("hostname="+Urls.encode(accessible.getHostText())).array()); log.debug("Renamed Couchbase server "+this+" via "+apiUri+": "+response); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { log.warn("Invalid response code, renaming {} ({}): {}", new Object[]{apiUri, response.getResponseCode(), response.getContentAsString()}); } } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Error renaming server, using "+apiUri+": "+e, e); } }
Example #30
Source File: PaasWebAppCloudFoundryDriver.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
private boolean isApplicationDomainAvailable(){ boolean result; try { result = HttpTool.getHttpStatusCode(getDomainUri()) == HttpURLConnection.HTTP_OK ; } catch (Exception e) { result = false; } return result; }