List of usage examples for java.net ConnectException ConnectException
public ConnectException(String msg)
From source file:org.sakaiproject.antivirus.impl.ClamAVScanner.java
protected int getStreamPortFromAnswer(String answer) throws ConnectException { int port = -1; if (answer != null && answer.startsWith(STREAM_PORT_STRING)) { try {/*from w ww.ja v a 2 s. c o m*/ port = Integer.parseInt(answer.substring(STREAM_PORT_STRING.length())); } catch (NumberFormatException nfe) { } } if (port <= 0) { throw new ConnectException("\"PORT nn\" expected - unable to parse: " + "\"" + answer + "\""); } return port; }
From source file:com.evolveum.icf.dummy.resource.DummyResource.java
public DummyObjectClass getAccountObjectClass() throws ConnectException, FileNotFoundException { if (schemaBreakMode == BreakMode.NONE) { return accountObjectClass; } else if (schemaBreakMode == BreakMode.NETWORK) { throw new ConnectException("The schema is not available (simulated error)"); } else if (schemaBreakMode == BreakMode.IO) { throw new FileNotFoundException("The schema file not found (simulated error)"); } else if (schemaBreakMode == BreakMode.GENERIC) { // The connector will react with generic exception throw new IllegalArgumentException("Generic error fetching schema (simulated error)"); } else if (schemaBreakMode == BreakMode.RUNTIME) { // The connector will just pass this up throw new IllegalStateException("Generic error fetching schema (simulated error)"); } else if (schemaBreakMode == BreakMode.UNSUPPORTED) { throw new UnsupportedOperationException("Schema is not supported (simulated error)"); } else {/*from ww w . j a v a2 s.com*/ // This is a real error. Use this strange thing to make sure it passes up throw new RuntimeException("Unknown schema break mode " + schemaBreakMode); } }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.LDAPUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#removeUserAccount(java.lang.String) *///from www . java2s.c om public synchronized boolean removeUserAccount(final String userId) throws UserManagementException { final String methodName = LDAPUserManager.CNAME + "#removeUserAccount(final String userId) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug(userId); } boolean isComplete = false; LDAPConnection ldapConn = null; LDAPConnectionPool ldapPool = null; try { ldapPool = (LDAPConnectionPool) svcBean.getAuthDataSource(); if (DEBUG) { DEBUGGER.debug("LDAPConnectionPool: {}", ldapPool); } if (ldapPool.isClosed()) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } ldapConn = ldapPool.getConnection(); if (DEBUG) { DEBUGGER.debug("LDAPConnection: {}", ldapConn); } if (!(ldapConn.isConnected())) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } DeleteRequest deleteRequest = new DeleteRequest( new StringBuilder().append(userAttributes.getUserId() + "=" + userId + ",") .append(repoConfig.getRepositoryUserBase() + "," + repoConfig.getRepositoryBaseDN()) .toString()); if (DEBUG) { DEBUGGER.debug("DeleteRequest: {}", deleteRequest); } LDAPResult ldapResult = ldapConn.delete(deleteRequest); if (DEBUG) { DEBUGGER.debug("LDAPResult: {}", ldapResult); } if (ldapResult.getResultCode() == ResultCode.SUCCESS) { isComplete = true; } } catch (LDAPException lx) { throw new UserManagementException(lx.getMessage(), lx); } catch (ConnectException cx) { throw new UserManagementException(cx.getMessage(), cx); } finally { if ((ldapPool != null) && ((ldapConn != null) && (ldapConn.isConnected()))) { ldapConn.close(); ldapPool.releaseConnection(ldapConn); } } return isComplete; }
From source file:com.mgmtp.perfload.core.console.LtConsole.java
private void connectToDaemons() throws ConnectException { LOG.info("Connecting to daemons..."); boolean connected = true; for (Client client : clients.values()) { LOG.info("Connecting to daemon {}", client.getClientId()); client.connect();/* w w w . j a v a 2 s . c o m*/ if (!client.isConnected()) { connected = false; LOG.error("Could not connect to daemon: {}", client.getClientId()); } } if (!connected) { // set to null so the shutdown hook will not try to abort and disconnect doneLatch = null; throw new ConnectException("Could not connect to at least one daemon."); } }
From source file:org.apache.hama.util.BSPNetUtils.java
/** * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but also takes a * local address and port to bind the socket to. * /*from w w w .j a v a2 s . co m*/ * @param socket * @param endpoint the remote address * @param localAddr the local address to bind the socket to * @param timeout timeout in milliseconds */ public static void connect(Socket socket, SocketAddress endpoint, SocketAddress localAddr, int timeout) throws IOException { if (socket == null || endpoint == null || timeout < 0) { throw new IllegalArgumentException("Illegal argument for connect()"); } SocketChannel ch = socket.getChannel(); if (localAddr != null) { socket.bind(localAddr); } if (ch == null) { // let the default implementation handle it. socket.connect(endpoint, timeout); } else { SocketIOWithTimeout.connect(ch, endpoint, timeout); } // There is a very rare case allowed by the TCP specification, such that // if we are trying to connect to an endpoint on the local machine, // and we end up choosing an ephemeral port equal to the destination port, // we will actually end up getting connected to ourself (ie any data we // send just comes right back). This is only possible if the target // daemon is down, so we'll treat it like connection refused. if (socket.getLocalPort() == socket.getPort() && socket.getLocalAddress().equals(socket.getInetAddress())) { LOG.info("Detected a loopback TCP socket, disconnecting it"); socket.close(); throw new ConnectException("Localhost targeted connection resulted in a loopback. " + "No daemon is listening on the target port."); } }
From source file:net.NetUtils.java
/** * This is a drop-in replacement for /* w w w . j av a 2s .c om*/ * {@link Socket#connect(SocketAddress, int)}. * In the case of normal sockets that don't have associated channels, this * just invokes <code>socket.connect(endpoint, timeout)</code>. If * <code>socket.getChannel()</code> returns a non-null channel, * connect is implemented using Hadoop's selectors. This is done mainly * to avoid Sun's connect implementation from creating thread-local * selectors, since Hadoop does not have control on when these are closed * and could end up taking all the available file descriptors. * * @see java.net.Socket#connect(java.net.SocketAddress, int) * * @param socket * @param endpoint * @param timeout - timeout in milliseconds */ public static void connect(Socket socket, SocketAddress endpoint, int timeout) throws IOException { if (socket == null || endpoint == null || timeout < 0) { throw new IllegalArgumentException("Illegal argument for connect()"); } SocketChannel ch = socket.getChannel(); if (ch == null) { // let the default implementation handle it. socket.connect(endpoint, timeout); } else { SocketIOWithTimeout.connect(ch, endpoint, timeout); } // There is a very rare case allowed by the TCP specification, such that // if we are trying to connect to an endpoint on the local machine, // and we end up choosing an ephemeral port equal to the destination port, // we will actually end up getting connected to ourself (ie any data we // send just comes right back). This is only possible if the target // daemon is down, so we'll treat it like connection refused. if (socket.getLocalPort() == socket.getPort() && socket.getLocalAddress().equals(socket.getInetAddress())) { LOG.info("Detected a loopback TCP socket, disconnecting it"); socket.close(); throw new ConnectException("Localhost targeted connection resulted in a loopback. " + "No daemon is listening on the target port."); } }
From source file:com.evolveum.icf.dummy.resource.DummyResource.java
public Collection<DummyAccount> listAccounts() throws ConnectException, FileNotFoundException { if (getBreakMode == BreakMode.NONE) { return accounts.values(); } else if (schemaBreakMode == BreakMode.NETWORK) { throw new ConnectException("Network error (simulated error)"); } else if (schemaBreakMode == BreakMode.IO) { throw new FileNotFoundException("IO error (simulated error)"); } else if (schemaBreakMode == BreakMode.GENERIC) { // The connector will react with generic exception throw new IllegalArgumentException("Generic error (simulated error)"); } else if (schemaBreakMode == BreakMode.RUNTIME) { // The connector will just pass this up throw new IllegalStateException("Generic error (simulated error)"); } else if (schemaBreakMode == BreakMode.UNSUPPORTED) { throw new UnsupportedOperationException("Not supported (simulated error)"); } else {/*from w w w . j a v a 2 s . c o m*/ // This is a real error. Use this strange thing to make sure it passes up throw new RuntimeException("Unknown schema break mode " + schemaBreakMode); } }
From source file:phex.bootstrap.GWebCacheConnection.java
/** * Opens a connection to the request url and checks the response code. * 3xx are automatically redirected./*from w ww . j av a 2s . c o m*/ * 400 - 599 response codes will throw a ConnectException. * * @throws IOException if an IO error occurs */ private void openConnection(URL requestURL) throws IOException { HttpClient client = HttpClientFactory.createHttpClient(); if (ProxyPrefs.UseHttp.get().booleanValue() && !StringUtils.isEmpty(ProxyPrefs.HttpHost.get())) { client.getHostConfiguration().setProxy(ProxyPrefs.HttpHost.get(), ProxyPrefs.HttpPort.get().intValue()); } method = new GetMethod(requestURL.toExternalForm()); method.setFollowRedirects(false); method.addRequestHeader("Cache-Control", "no-cache"); // be HTTP/1.1 compliant method.addRequestHeader(HTTPHeaderNames.CONNECTION, "close"); logger.debug("Open GWebCache connection to {}.", requestURL); int responseCode = client.executeMethod(method); logger.debug("GWebCache {} returned response code: {}", requestURL, responseCode); // we only accept the status codes 2xx all others fail... if (responseCode < 200 || responseCode > 299) { throw new ConnectException("GWebCache service not available, response code: " + responseCode); } InputStream bodyStream = method.getResponseBodyAsStream(); if (bodyStream != null) { // ensure we never read a body size larger then 100K to reduce misuse reader = new BufferedReader( new InputStreamReader(new LengthLimitedInputStream(bodyStream, MAX_LENGTH))); } else { throw new ConnectException("Empty response."); } }
From source file:phex.gwebcache.GWebCacheConnection.java
/** * Opens a connection to the request url and checks the response code. * 3xx are automaticly redirected.//www. jav a2 s . c o m * 400 - 599 response codes will throw a ConnectException. */ private void openConnection(URL requestURL) throws IOException { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); if (ProxyPrefs.UseHttp.get().booleanValue() && !StringUtils.isEmpty(ProxyPrefs.HttpHost.get())) { client.getHostConfiguration().setProxy(ProxyPrefs.HttpHost.get(), ProxyPrefs.HttpPort.get().intValue()); } method = new GetMethod(requestURL.toExternalForm()); method.setFollowRedirects(false); method.addRequestHeader("Cache-Control", "no-cache"); // be HTTP/1.1 complient method.addRequestHeader(HTTPHeaderNames.USER_AGENT, Environment.getPhexVendor()); method.addRequestHeader(HTTPHeaderNames.CONNECTION, "close"); NLogger.debug(GWebCacheConnection.class, "Open GWebCache connection to " + requestURL + "."); int responseCode = client.executeMethod(method); NLogger.debug(GWebCacheConnection.class, "GWebCache " + requestURL + " returned response code: " + responseCode); // we only accept the status codes 2xx all others fail... if (responseCode < 200 || responseCode > 299) { throw new ConnectException("GWebCache service not available, response code: " + responseCode); } InputStream bodyStream = method.getResponseBodyAsStream(); if (bodyStream != null) { reader = new BufferedReader(new InputStreamReader(bodyStream)); } else { throw new ConnectException("Empty response."); } }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.LDAPUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#searchUsers(java.lang.String) *//*from w ww. java2s .com*/ public synchronized List<String[]> searchUsers(final String searchData) throws UserManagementException { final String methodName = LDAPUserManager.CNAME + "#searchUsers(final String searchData) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", searchData); } List<String[]> results = null; LDAPConnection ldapConn = null; LDAPConnectionPool ldapPool = null; try { ldapPool = (LDAPConnectionPool) svcBean.getAuthDataSource(); if (DEBUG) { DEBUGGER.debug("LDAPConnectionPool: {}", ldapPool); } if (ldapPool.isClosed()) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } ldapConn = ldapPool.getConnection(); if (DEBUG) { DEBUGGER.debug("LDAPConnection: {}", ldapConn); } if (!(ldapConn.isConnected())) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } Filter searchFilter = Filter.create("(&(objectClass=" + repoConfig.getBaseObject() + ")" + "(|(" + userAttributes.getCommonName() + "=" + searchData + ")" + "(" + userAttributes.getUserId() + "=" + searchData + ")" + "(" + userAttributes.getEmailAddr() + "=" + searchData + ")" + "(" + userAttributes.getGivenName() + "=" + searchData + ")" + "(" + userAttributes.getSurname() + "=" + searchData + ")" + "(" + userAttributes.getDisplayName() + "=" + searchData + ")))"); if (DEBUG) { DEBUGGER.debug("searchFilter: {}", searchFilter); } SearchRequest searchReq = new SearchRequest( repoConfig.getRepositoryUserBase() + "," + repoConfig.getRepositoryBaseDN(), SearchScope.SUB, searchFilter, userAttributes.getCommonName(), userAttributes.getUserId()); if (DEBUG) { DEBUGGER.debug("searchRequest: {}", searchReq); } SearchResult searchResult = ldapConn.search(searchReq); if (DEBUG) { DEBUGGER.debug("searchResult: {}", searchResult); } if (searchResult.getResultCode() == ResultCode.SUCCESS) { results = new ArrayList<String[]>(); for (SearchResultEntry entry : searchResult.getSearchEntries()) { String[] userData = new String[] { entry.getAttributeValue(userAttributes.getCommonName()), entry.getAttributeValue(userAttributes.getUserId()) }; if (DEBUG) { DEBUGGER.debug("Data: {}", (Object) userData); } results.add(userData); } } else { throw new UserManagementException("No users were located with the search data provided"); } } catch (LDAPException lx) { throw new UserManagementException(lx.getMessage(), lx); } catch (ConnectException cx) { throw new UserManagementException(cx.getMessage(), cx); } finally { if ((ldapPool != null) && ((ldapConn != null) && (ldapConn.isConnected()))) { ldapConn.close(); ldapPool.releaseConnection(ldapConn); } } return results; }