@Override public boolean startConnection() { HttpClientStarter httpstarter = getLevel().find(HttpClientStarter.class); if (!httpstarter.isStarted()) { return false; } try { String protocol = ssl ? "https" : "http"; int resolvedport = port > 0 ? port : ssl ? 443 : 80; URL url = new URL(protocol, getHostName(), resolvedport, path); j4pClient = new J4pClient(url.toString(), httpstarter.getHttpClient()); connection = new JolokiaJmxSource(j4pClient); return true; } catch (MalformedURLException e) { log(Level.ERROR, e, "can't build jolokia URL: %s", e.getMessage()); return false; } }
final SocketFactory ss = getLevel().find(SocketFactory.class); ConnectionSocketFactory plainsf = new PlainConnectionSocketFactory() { @Override ConnectionSocketFactory sslfactory = getSSLSocketFactory(); if (sslfactory != null) { r.register("https", sslfactory); } else { log(Level.WARN, "ssl factory not found, won't manage https");
@Test public void testStart() throws Exception { MockHttpServer server = new MockHttpServer(false); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(SSLStarter.class).doStart(); localhost.find(Resolver.class).doStart(); logger.debug("resolver started for localhost:" + localhost.find(Resolver.class).isStarted()); cnx.doStart(); Assert.assertTrue("Apache HttpClient failed to start", cnx.isStarted()); cnx.stop(); server.stop(); }
@Test public void testConnectTwice() throws Exception { MockHttpServer server = new MockHttpServer(false); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(Resolver.class).doStart(); cnx.doStart(); TestHttpProbe p = new TestHttpProbe(); p.setMainStore(new RrdDbStoreFactory(), empty); p.setHost(localhost); p.setPort(server.getURI().toURL().getPort()); p.configure(); p.checkStore(); localhost.addProbe(p); localhost.getParent().startCollect(); // Run twice, to detect failure management in the probe localhost.collectAll(); shouldFail = false; Thread.sleep(1500); localhost.collectAll(); Assert.assertTrue("Didn't try to collect", p.collected); server.stop(); }
private SSLConnectionSocketFactory getSSLSocketFactory() { SSLStarter sslstarter = getLevel().find(SSLStarter.class); if (sslstarter == null) { return null; } else { SSLContext sc = sslstarter.getContext(); return new SSLConnectionSocketFactory(sc); } }
@Override public void stop() { try { client.close(); } catch (IOException e) { log(Level.ERROR, "http client closed failed: %s", e.getMessage()); } client = null; }
HttpClient cnx = httpstarter.getHttpClient();
@Test public void testConnectSSL() throws Exception { MockHttpServer server = new MockHttpServer(true); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(Resolver.class).doStart(); localhost.find(SSLStarter.class).doStart(); cnx.doStart(); TestHttpProbe p = new TestHttpProbe(); p.setMainStore(new RrdDbStoreFactory(), empty); p.setHost(localhost); p.setPort(server.getURI().toURL().getPort()); p.setScheme("https"); p.configure(); p.checkStore(); localhost.addProbe(p); localhost.getParent().startCollect(); Assert.assertTrue(p.find(SSLStarter.class).isStarted()); shouldFail = false; localhost.collectAll(); Assert.assertTrue("Didn't try to collect", p.collected); server.stop(); }
@Override public boolean isStarted() { SSLStarter sslfactory = getLevel().find(SSLStarter.class); // if no sslfactory, don't check if it's started return client != null && (sslfactory != null ? sslfactory.isStarted() : true); } }
@Override public Map<KeyType, Number> getNewSampleValues() { HttpClientStarter httpstarter = find(HttpClientStarter.class); if (! httpstarter.isStarted()) { return Collections.emptyMap(); HttpClient cnx = httpstarter.getHttpClient(); HttpEntity entity = null; try { return Collections.emptyMap(); if (! httpstarter.isStarted()) { return Collections.emptyMap();