try { connection = (HttpURLConnection) connectionFactory.openConnection(url, isSpnegoEnabled); } catch (AuthenticationException e) { throw new IOException(e);
URLConnection connection; try { connection = connectionFactory.openConnection(path, isSpnegoEnabled); } catch (AuthenticationException e) { throw new IOException(e);
try { connection = (HttpURLConnection) connectionFactory.openConnection(url, isSpnegoEnabled); } catch (AuthenticationException e) { throw new IOException(e);
URLConnection connection; try { connection = connectionFactory.openConnection(path, isSpnegoEnabled); } catch (AuthenticationException e) { throw new IOException(e);
connection = (HttpURLConnection) connectionFactory.openConnection( urlWithParams, UserGroupInformation.isSecurityEnabled());
protected HttpURLConnection openConnection() throws IOException { return (HttpURLConnection)connFactory.openConnection(url); }
protected HttpURLConnection openConnection() throws IOException { return (HttpURLConnection)connFactory.openConnection(url); }
/** * Opens a url with read and connect timeouts * * @param url * to open * @return URLConnection * @throws IOException */ public URLConnection openConnection(URL url) throws IOException { try { return openConnection(url, false); } catch (AuthenticationException e) { // Unreachable return null; } }
/** * Opens a url with read and connect timeouts * * @param url * to open * @return URLConnection * @throws IOException */ public URLConnection openConnection(URL url) throws IOException { try { return openConnection(url, false); } catch (AuthenticationException e) { // Unreachable return null; } }
/** * Opens a url with read and connect timeouts * * @param url * to open * @return URLConnection * @throws IOException */ public URLConnection openConnection(URL url) throws IOException { try { return openConnection(url, false); } catch (AuthenticationException e) { // Unreachable LOG.error("Open connection {} failed", url, e); return null; } }
private static HttpURLConnection run(URLConnectionFactory factory, URL url) throws IOException, AuthenticationException { HttpURLConnection conn = null; try { conn = (HttpURLConnection) factory.openConnection(url, true); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { String msg = conn.getResponseMessage(); throw new IOException("Error when dealing remote token: " + msg); } } catch (IOException ie) { LOG.info("Error when dealing remote token:", ie); IOException e = getExceptionFromResponse(conn); if (e != null) { LOG.info("rethrowing exception from HTTP request: " + e.getLocalizedMessage()); throw e; } throw ie; } return conn; } }
@Override public URLConnection openConnection(URL url) throws IOException { return super.openConnection(new URL(url + "&service=foo&kind=bar")); } };
/** * Open an HTTP connection to the namenode to read file data and metadata. * @param path The path component of the URL * @param query The query component of the URL */ protected HttpURLConnection openConnection(String path, String query) throws IOException { query = addDelegationTokenParam(query); final URL url = getNamenodeURL(path, query); final HttpURLConnection connection; connection = (HttpURLConnection)connectionFactory.openConnection(url); connection.setRequestMethod("GET"); connection.connect(); return connection; }
/** * Open an HTTP connection to the namenode to read file data and metadata. * @param path The path component of the URL * @param query The query component of the URL */ protected HttpURLConnection openConnection(String path, String query) throws IOException { query = addDelegationTokenParam(query); final URL url = getNamenodeURL(path, query); final HttpURLConnection connection; connection = (HttpURLConnection)connectionFactory.openConnection(url); connection.setRequestMethod("GET"); connection.connect(); return connection; }
private static HttpURLConnection run(URLConnectionFactory factory, URL url) throws IOException, AuthenticationException { HttpURLConnection conn = null; try { conn = (HttpURLConnection) factory.openConnection(url, true); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { String msg = conn.getResponseMessage(); throw new IOException("Error when dealing remote token: " + msg); } } catch (IOException ie) { LOG.info("Error when dealing remote token:", ie); IOException e = getExceptionFromResponse(conn); if (e != null) { LOG.info("rethrowing exception from HTTP request: " + e.getLocalizedMessage()); throw e; } throw ie; } return conn; } }
private static boolean canAccess(String scheme, InetSocketAddress addr) { if (addr == null) return false; try { URL url = new URL(scheme + "://" + NetUtils.getHostPortString(addr)); URLConnection conn = connectionFactory.openConnection(url); conn.connect(); conn.getContent(); } catch (Exception e) { return false; } return true; }
@Test public void testConnConfiguratior() throws IOException { final URL u = new URL("http://localhost"); final List<HttpURLConnection> conns = Lists.newArrayList(); URLConnectionFactory fc = new URLConnectionFactory(new ConnectionConfigurator() { @Override public HttpURLConnection configure(HttpURLConnection conn) throws IOException { Assert.assertEquals(u, conn.getURL()); conns.add(conn); return conn; } }); fc.openConnection(u); Assert.assertEquals(1, conns.size()); }
@Test public void testConnConfiguratior() throws IOException { final URL u = new URL("http://localhost"); final List<HttpURLConnection> conns = Lists.newArrayList(); URLConnectionFactory fc = new URLConnectionFactory(new ConnectionConfigurator() { @Override public HttpURLConnection configure(HttpURLConnection conn) throws IOException { Assert.assertEquals(u, conn.getURL()); conns.add(conn); return conn; } }); fc.openConnection(u); Assert.assertEquals(1, conns.size()); } }
@Test public void testTimeout() throws IOException { Configuration conf = new Configuration(); URI uri = URI.create("hftp://localhost"); HftpFileSystem fs = (HftpFileSystem) FileSystem.get(uri, conf); URLConnection conn = fs.connectionFactory.openConnection(new URL( "http://localhost")); assertEquals(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, conn.getConnectTimeout()); assertEquals(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, conn.getReadTimeout()); }
@Test public void testReadURL() throws Exception { HttpURLConnection conn = mock(HttpURLConnection.class); doReturn(new ByteArrayInputStream(FAKE_LOG_DATA)).when(conn).getInputStream(); doReturn(HttpURLConnection.HTTP_OK).when(conn).getResponseCode(); doReturn(Integer.toString(FAKE_LOG_DATA.length)).when(conn).getHeaderField("Content-Length"); URLConnectionFactory factory = mock(URLConnectionFactory.class); doReturn(conn).when(factory).openConnection(Mockito.<URL> any(), anyBoolean()); URL url = new URL("http://localhost/fakeLog"); EditLogInputStream elis = EditLogFileInputStream.fromUrl(factory, url, HdfsConstants.INVALID_TXID, HdfsConstants.INVALID_TXID, false); // Read the edit log and verify that we got all of the data. EnumMap<FSEditLogOpCodes, Holder<Integer>> counts = FSImageTestUtil .countEditLogOpTypes(elis); assertThat(counts.get(FSEditLogOpCodes.OP_ADD).held, is(1)); assertThat(counts.get(FSEditLogOpCodes.OP_SET_GENSTAMP_V1).held, is(1)); assertThat(counts.get(FSEditLogOpCodes.OP_CLOSE).held, is(1)); // Check that length header was picked up. assertEquals(FAKE_LOG_DATA.length, elis.length()); elis.close(); } }