public void createSocket() throws IOException { try { InetSocketAddress address = new InetSocketAddress(this.serverHost, this.serverPort); socket = new DatagramSocket(); packet = new DatagramPacket("".getBytes(StandardCharsets.UTF_8), 0, 0, address.getAddress(), this.serverPort); } catch (IOException ioe) { throw NetUtils.wrapException(this.serverHost, this.serverPort, "localhost", 0, ioe); } }
@Override public void authenticate(URL url, AuthenticatedURL.Token token) throws IOException, AuthenticationException { if (!hasDelegationToken(url, token)) { try { // check and renew TGT to handle potential expiration UserGroupInformation.getCurrentUser().checkTGTAndReloginFromKeytab(); LOG.debug("No delegation token found for url={}, token={}, " + "authenticating with {}", url, token, authenticator.getClass()); authenticator.authenticate(url, token); } catch (IOException ex) { throw NetUtils.wrapException(url.getHost(), url.getPort(), null, 0, ex); } } else { LOG.debug("Authenticated from delegation token. url={}, token={}", url, token); } }
throw NetUtils.wrapException(null, 0, address.getHostName(),
} else { // local exception InetSocketAddress address = connection.getRemoteAddress(); throw NetUtils.wrapException(address.getHostName(), address.getPort(), NetUtils.getHostname(),
int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { throw NetUtils.wrapException(host, port, NetUtils.UNKNOWN_HOST, 0, new ConnectException("Server response " + reply));
this.server = remoteId.getAddress(); if (server.isUnresolved()) { throw NetUtils.wrapException(server.getHostName(), server.getPort(), null,
} catch (Throwable e) { if (e instanceof BindException) { throw NetUtils.wrapException(null, 0, infoAddr.getHostName(), infoAddr.getPort(), (SocketException) e); } else { } catch (Throwable e) { if (e instanceof BindException) { throw NetUtils.wrapException(null, 0, secInfoSocAddr.getHostName(), secInfoSocAddr.getPort(), (SocketException) e); } else {
public void createSocket() throws IOException { try { InetSocketAddress address = new InetSocketAddress(this.serverHost, this.serverPort); socket = new DatagramSocket(); packet = new DatagramPacket("".getBytes(StandardCharsets.UTF_8), 0, 0, address.getAddress(), this.serverPort); } catch (IOException ioe) { throw NetUtils.wrapException(this.serverHost, this.serverPort, "localhost", 0, ioe); } }
/** * Open the TCP listener. * * @param addr the host address. * @param port the host port. * @return the created server socket channel. * @throws IOException */ private ServerSocketChannel openTCPChannel(InetAddress addr, int port) throws IOException { ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); try { serverSocketChannel.socket().bind(new InetSocketAddress(addr, port)); serverSocketChannel.configureBlocking(false); } catch (IOException e) { throw NetUtils.wrapException(null, 0, InetAddress.getLocalHost().getHostName(), port, e); } return serverSocketChannel; }
/** * Monitor the TCP socket for inbound requests. * * @param serverSocketChannel the server socket channel * @param addr the local inet address * @param port the listener (local) port * @throws Exception if the tcp processing fails. */ public void serveNIOTCP(ServerSocketChannel serverSocketChannel, InetAddress addr, int port) throws Exception { try { while (true) { final SocketChannel socketChannel = serverSocketChannel.accept(); if (socketChannel != null) { executor.submit(new Callable<Boolean>() { @Override public Boolean call() throws Exception { nioTCPClient(socketChannel); return true; } }); } else { Thread.sleep(500); } } } catch (IOException e) { throw NetUtils.wrapException(addr.getHostName(), port, addr.getHostName(), port, e); } }
/** * Create and UDP listener socket. * * @param addr host address. * @param port host port. * @return * @throws IOException if listener creation fails. */ private DatagramChannel openUDPChannel(InetAddress addr, int port) throws IOException { DatagramChannel channel = DatagramChannel.open(); try { channel.socket().bind(new InetSocketAddress(addr, port)); } catch (IOException e) { throw NetUtils.wrapException(null, 0, InetAddress.getLocalHost().getHostName(), port, e); } return channel; }
throw NetUtils.wrapException(null, 0, address.getHostName(),
throw NetUtils.wrapException(null, 0, address.getHostName(),
throw NetUtils.wrapException(null, 0, address.getHostName(),
private IOException verifyExceptionClass(IOException e, Class expectedClass) throws Throwable { assertNotNull("Null Exception", e); IOException wrapped = NetUtils.wrapException("desthost", DEST_PORT, "localhost", LOCAL_PORT, e); LOG.info(wrapped.toString(), wrapped); if(!(wrapped.getClass().equals(expectedClass))) { throw new AssertionFailedError("Wrong exception class; expected " + expectedClass + " got " + wrapped.getClass() + ": " + wrapped).initCause(wrapped); } return wrapped; }
private IOException verifyExceptionClass(IOException e, Class expectedClass) throws Throwable { assertNotNull("Null Exception", e); IOException wrapped = NetUtils.wrapException("desthost", DEST_PORT, "localhost", LOCAL_PORT, e); LOG.info(wrapped.toString(), wrapped); if(!(wrapped.getClass().equals(expectedClass))) { throw new AssertionFailedError("Wrong exception class; expected " + expectedClass + " got " + wrapped.getClass() + ": " + wrapped).initCause(wrapped); } return wrapped; }
/** * Connect to the FTP server using configuration parameters * * * @return An FTPClient instance * @throws IOException */ private FTPClient connect() throws IOException { FTPClient client = null; Configuration conf = getConf(); String host = conf.get(FS_FTP_HOST); int port = conf.getInt(FS_FTP_HOST_PORT, FTP.DEFAULT_PORT); String user = conf.get(FS_FTP_USER_PREFIX + host); String password = conf.get(FS_FTP_PASSWORD_PREFIX + host); client = new FTPClient(); client.connect(host, port); int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { throw NetUtils.wrapException(host, port, NetUtils.UNKNOWN_HOST, 0, new ConnectException("Server response " + reply)); } else if (client.login(user, password)) { client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE); client.setFileType(FTP.BINARY_FILE_TYPE); client.setBufferSize(DEFAULT_BUFFER_SIZE); } else { throw new IOException("Login failed on server - " + host + ", port - " + port + " as user '" + user + "'"); } return client; }
/** * Connect to the FTP server using configuration parameters * * * @return An FTPClient instance * @throws IOException */ private FTPClient connect() throws IOException { FTPClient client = null; Configuration conf = getConf(); String host = conf.get(FS_FTP_HOST); int port = conf.getInt(FS_FTP_HOST_PORT, FTP.DEFAULT_PORT); String user = conf.get(FS_FTP_USER_PREFIX + host); String password = conf.get(FS_FTP_PASSWORD_PREFIX + host); client = new FTPClient(); client.connect(host, port); int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { throw NetUtils.wrapException(host, port, NetUtils.UNKNOWN_HOST, 0, new ConnectException("Server response " + reply)); } else if (client.login(user, password)) { client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE); client.setFileType(FTP.BINARY_FILE_TYPE); client.setBufferSize(DEFAULT_BUFFER_SIZE); } else { throw new IOException("Login failed on server - " + host + ", port - " + port + " as user '" + user + "'"); } return client; }
/** * Connect to the FTP server using configuration parameters * * * @return An FTPClient instance * @throws IOException */ private FTPClient connect() throws IOException { FTPClient client = null; Configuration conf = getConf(); String host = conf.get(FS_FTP_HOST); int port = conf.getInt(FS_FTP_HOST_PORT, FTP.DEFAULT_PORT); String user = conf.get(FS_FTP_USER_PREFIX + host); String password = conf.get(FS_FTP_PASSWORD_PREFIX + host); client = new FTPClient(); client.connect(host, port); int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { throw NetUtils.wrapException(host, port, NetUtils.UNKNOWN_HOST, 0, new ConnectException("Server response " + reply)); } else if (client.login(user, password)) { client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE); client.setFileType(FTP.BINARY_FILE_TYPE); client.setBufferSize(DEFAULT_BUFFER_SIZE); } else { throw new IOException("Login failed on server - " + host + ", port - " + port + " as user '" + user + "'"); } return client; }
/** * Connect to the FTP server using configuration parameters * * * @return An FTPClient instance * @throws IOException */ private FTPClient connect() throws IOException { FTPClient client = null; Configuration conf = getConf(); String host = conf.get(FS_FTP_HOST); int port = conf.getInt(FS_FTP_HOST_PORT, FTP.DEFAULT_PORT); String user = conf.get(FS_FTP_USER_PREFIX + host); String password = conf.get(FS_FTP_PASSWORD_PREFIX + host); client = new FTPClient(); client.connect(host, port); int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { throw NetUtils.wrapException(host, port, NetUtils.UNKNOWN_HOST, 0, new ConnectException("Server response " + reply)); } else if (client.login(user, password)) { client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE); client.setFileType(FTP.BINARY_FILE_TYPE); client.setBufferSize(DEFAULT_BUFFER_SIZE); } else { throw new IOException("Login failed on server - " + host + ", port - " + port + " as user '" + user + "'"); } return client; }