Search in sources :

Example 61 with HttpURLConnection

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));
    }
}
Also used : RequestResult(com.microsoft.azure.storage.RequestResult) HttpURLConnection(java.net.HttpURLConnection) Date(java.util.Date)

Example 62 with HttpURLConnection

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) File(java.io.File) FileInputStream(java.io.FileInputStream) URL(java.net.URL) Test(org.junit.Test)

Example 63 with HttpURLConnection

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;
        }
    };
}
Also used : ConnectionConfigurator(org.apache.hadoop.security.authentication.client.ConnectionConfigurator) HttpURLConnection(java.net.HttpURLConnection) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 64 with HttpURLConnection

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();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Configuration(org.apache.hadoop.conf.Configuration)

Example 65 with HttpURLConnection

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();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL)

Aggregations

HttpURLConnection (java.net.HttpURLConnection)3831 URL (java.net.URL)2447 IOException (java.io.IOException)1634 InputStream (java.io.InputStream)1082 InputStreamReader (java.io.InputStreamReader)692 Test (org.junit.Test)650 BufferedReader (java.io.BufferedReader)573 OutputStream (java.io.OutputStream)466 MalformedURLException (java.net.MalformedURLException)372 URLConnection (java.net.URLConnection)248 HashMap (java.util.HashMap)216 OutputStreamWriter (java.io.OutputStreamWriter)208 Map (java.util.Map)199 Gson (com.google.gson.Gson)190 ByteArrayOutputStream (java.io.ByteArrayOutputStream)186 ArrayList (java.util.ArrayList)168 ExecutionException (java.util.concurrent.ExecutionException)161 File (java.io.File)159 AsyncTask (android.os.AsyncTask)158 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)157