use of java.net.HttpURLConnection in project hadoop by apache.
the class SelfThrottlingIntercept method responseReceived.
public void responseReceived(ResponseReceivedEvent event) {
RequestResult result = event.getRequestResult();
Date startDate = result.getStartDate();
Date stopDate = result.getStopDate();
long elapsed = stopDate.getTime() - startDate.getTime();
synchronized (this) {
this.lastE2Elatency = elapsed;
}
if (LOG.isDebugEnabled()) {
int statusCode = result.getStatusCode();
String etag = result.getEtag();
HttpURLConnection urlConnection = (HttpURLConnection) event.getConnectionObject();
int contentLength = urlConnection.getContentLength();
String requestMethod = urlConnection.getRequestMethod();
long threadId = Thread.currentThread().getId();
LOG.debug(String.format("SelfThrottlingIntercept:: ResponseReceived: threadId=%d, Status=%d, Elapsed(ms)=%d, ETAG=%s, contentLength=%d, requestMethod=%s", threadId, statusCode, elapsed, etag, contentLength, requestMethod));
}
}
use of java.net.HttpURLConnection in project hadoop by apache.
the class TestApplicationHistoryServer method testHostedUIs.
@Test(timeout = 240000)
public void testHostedUIs() throws Exception {
ApplicationHistoryServer historyServer = new ApplicationHistoryServer();
Configuration config = new YarnConfiguration();
config.setClass(YarnConfiguration.TIMELINE_SERVICE_STORE, MemoryTimelineStore.class, TimelineStore.class);
config.setClass(YarnConfiguration.TIMELINE_SERVICE_STATE_STORE_CLASS, MemoryTimelineStateStore.class, TimelineStateStore.class);
config.set(YarnConfiguration.TIMELINE_SERVICE_WEBAPP_ADDRESS, "localhost:0");
final String UI1 = "UI1";
String connFileStr = "";
File diskFile = new File("./pom.xml");
String diskFileStr = readInputStream(new FileInputStream(diskFile));
try {
config.set(YarnConfiguration.TIMELINE_SERVICE_UI_NAMES, UI1);
config.set(YarnConfiguration.TIMELINE_SERVICE_UI_WEB_PATH_PREFIX + UI1, "/" + UI1);
config.set(YarnConfiguration.TIMELINE_SERVICE_UI_ON_DISK_PATH_PREFIX + UI1, "./");
historyServer.init(config);
historyServer.start();
URL url = new URL("http://localhost:" + historyServer.getPort() + "/" + UI1 + "/pom.xml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
connFileStr = readInputStream(conn.getInputStream());
} finally {
historyServer.stop();
}
assertEquals("Web file contents should be the same as on disk contents", diskFileStr, connFileStr);
}
use of java.net.HttpURLConnection in project hadoop by apache.
the class TimelineConnector method initSslConnConfigurator.
private static ConnectionConfigurator initSslConnConfigurator(final int timeout, SSLFactory sslFactory) throws IOException, GeneralSecurityException {
final SSLSocketFactory sf;
final HostnameVerifier hv;
sf = sslFactory.createSSLSocketFactory();
hv = sslFactory.getHostnameVerifier();
return new ConnectionConfigurator() {
@Override
public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
if (conn instanceof HttpsURLConnection) {
HttpsURLConnection c = (HttpsURLConnection) conn;
c.setSSLSocketFactory(sf);
c.setHostnameVerifier(hv);
}
setTimeouts(conn, timeout);
return conn;
}
};
}
use of java.net.HttpURLConnection in project hadoop by apache.
the class TestHttpServer method validateXFrameOption.
private void validateXFrameOption(HttpServer2.XFrameOption option) throws Exception {
Configuration conf = new Configuration();
boolean xFrameEnabled = true;
HttpServer2 httpServer = createServer(xFrameEnabled, option.toString(), conf);
try {
HttpURLConnection conn = getHttpURLConnection(httpServer);
String xfoHeader = conn.getHeaderField("X-FRAME-OPTIONS");
assertTrue("X-FRAME-OPTIONS is absent in the header", xfoHeader != null);
assertTrue(xfoHeader.endsWith(option.toString()));
} finally {
httpServer.stop();
}
}
use of java.net.HttpURLConnection in project hadoop by apache.
the class TestHttpServer method getHttpStatusCode.
/**
* Access a URL and get the corresponding return Http status code. The URL
* will be accessed as the passed user, by sending user.name request
* parameter.
*
* @param urlstring
* @param userName
* @return
* @throws IOException
*/
static int getHttpStatusCode(String urlstring, String userName) throws IOException {
URL url = new URL(urlstring + "?user.name=" + userName);
System.out.println("Accessing " + url + " as user " + userName);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
return connection.getResponseCode();
}
Aggregations