Java Code Examples for org.apache.mina.core.future.ConnectFuture#getException()
The following examples show how to use
org.apache.mina.core.future.ConnectFuture#getException() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapNetworkConnection.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Close the connection and generate the appropriate exception * * @exception LdapException If we weren't able to close the connection */ private void close( ConnectFuture connectionFuture ) throws LdapException { // disposing connector if not connected close(); Throwable e = connectionFuture.getException(); if ( e != null ) { // Special case for UnresolvedAddressException // (most of the time no message is associated with this exception) if ( ( e instanceof UnresolvedAddressException ) && ( e.getMessage() == null ) ) { throw new InvalidConnectionException( I18n.err( I18n.ERR_04121_CANNOT_RESOLVE_HOSTNAME, config.getLdapHost() ), e ); } // Default case throw new InvalidConnectionException( I18n.err( I18n.ERR_04110_CANNOT_CONNECT_TO_SERVER, e.getMessage() ), e ); } // We didn't received anything : this is an error if ( LOG.isErrorEnabled() ) { LOG.error( I18n.err( I18n.ERR_04112_OP_FAILED_TIMEOUT, "Connect" ) ); } throw new LdapException( TIME_OUT_ERROR ); }
Example 2
Source File: ClientBaseConnection.java From neoscada with Eclipse Public License 1.0 | 5 votes |
protected synchronized void handleConnectComplete ( final ConnectFuture future ) { logger.debug ( "Connection attempt complete: {}", future ); if ( this.connectFuture != future ) { logger.warn ( "handleConnectComplete got called with wrong future - current: {}, called: {}", this.connectFuture, future ); return; } this.connectFuture = null; final Throwable error = future.getException (); if ( error != null ) { setState ( ConnectionState.CLOSED, error ); return; } try { setSession ( future.getSession () ); } catch ( final Throwable e ) { setState ( ConnectionState.CLOSED, e ); } logger.debug ( "Connection established" ); }
Example 3
Source File: LdapNetworkConnection.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Process the connect. * * @exception LdapException If we weren't able to connect * @return A Future that can be used to check the status of the connection */ public ConnectFuture tryConnect() throws LdapException { // Build the connection address SocketAddress address = new InetSocketAddress( config.getLdapHost(), config.getLdapPort() ); ConnectFuture connectionFuture = connector.connect( address ); boolean result = false; // Wait until it's established try { result = connectionFuture.await( timeout ); } catch ( InterruptedException e ) { connector.dispose(); connector = null; if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04120_INTERRUPTED_WAITING_FOR_CONNECTION, config.getLdapHost(), config.getLdapPort() ), e ); } throw new LdapOtherException( e.getMessage(), e ); } if ( !result ) { // It may be an exception, or a timeout Throwable connectionException = connectionFuture.getException(); connector = null; if ( connectionException == null ) { // This was a timeout String message = I18n.msg( I18n.MSG_04177_CONNECTION_TIMEOUT, timeout ); if ( LOG.isDebugEnabled() ) { LOG.debug( message ); } throw new LdapConnectionTimeOutException( message ); } else { if ( LOG.isDebugEnabled() ) { if ( ( connectionException instanceof ConnectException ) || ( connectionException instanceof UnresolvedAddressException ) ) { // No need to wait // We know that there was a permanent error such as "connection refused". LOG.debug( I18n.msg( I18n.MSG_04144_CONNECTION_ERROR, connectionFuture.getException().getMessage() ) ); } LOG.debug( I18n.msg( I18n.MSG_04120_INTERRUPTED_WAITING_FOR_CONNECTION, config.getLdapHost(), config.getLdapPort() ), connectionException ); } throw new LdapOtherException( connectionException.getMessage(), connectionException ); } } return connectionFuture; }
Example 4
Source File: LdapNetworkConnection.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Verify that the connection has been secured, otherwise throw a meaningful exception * * @exception LdapException If we weren't able to check that the connection is secured */ private void checkSecured( ConnectFuture connectionFuture ) throws LdapException { try { boolean isSecured = handshakeFuture.get( timeout, TimeUnit.MILLISECONDS ); if ( !isSecured ) { // check for a specific cause Throwable cause = connectionFuture.getException(); if ( cause == null && connectionFuture.getSession() != null ) { cause = ( Throwable ) connectionFuture.getSession().getAttribute( EXCEPTION_KEY ); } // Cancel the latch connectionCloseFuture.complete( 0 ); // if there is no cause assume timeout if ( cause == null ) { throw new LdapException( TIME_OUT_ERROR ); } throw new LdapTlsHandshakeException( I18n.err( I18n.ERR_04120_TLS_HANDSHAKE_ERROR ), cause ); } } catch ( Exception e ) { if ( e instanceof LdapException ) { throw ( LdapException ) e; } String msg = I18n.err( I18n.ERR_04122_SSL_CONTEXT_INIT_FAILURE ); LOG.error( msg, e ); throw new LdapException( msg, e ); } }