Search in sources :

Example 1 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class TestSQLException method testCreateThrowable_01.

/*
	 * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
	 * 
	 * Tests various simple exceptions to see if the expected SQLState is
	 * returend.
	 */
@Test
public void testCreateThrowable_01() {
    testCreateThrowable(new CommunicationException(// $NON-NLS-1$
    "A test MM Communication Exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectionException("A test MM Connection Exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new IOException(// $NON-NLS-1$
    "A test Generic java.io.IOException"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(new MalformedURLException(// $NON-NLS-1$
    "A test java.net.MalformedURLException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new TeiidException("A test Generic MM Core Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(// $NON-NLS-1$
    new TeiidException("A test MM Exception"), SQLStates.DEFAULT);
    testCreateThrowable(new TeiidProcessingException(// $NON-NLS-1$
    "A test Generic MM Query Processing Exception"), SQLStates.USAGE_ERROR);
    testCreateThrowable(new TeiidRuntimeException("A test MM Runtime Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new TeiidSQLException("A test Generic MM SQL Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new NoRouteToHostException(// $NON-NLS-1$
    "A test java.net.NoRouteToHostException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new NullPointerException("A test NPE"), SQLStates.DEFAULT);
    testCreateThrowable(new ProcedureErrorInstructionException(// $NON-NLS-1$
    "A test SQL Procedure Error exception"), SQLStates.VIRTUAL_PROCEDURE_ERROR);
    testCreateThrowable(new SocketTimeoutException(// $NON-NLS-1$
    "A test socket timeout exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new UnknownHostException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
}
Also used : MalformedURLException(java.net.MalformedURLException) CommunicationException(org.teiid.net.CommunicationException) UnknownHostException(java.net.UnknownHostException) ProcedureErrorInstructionException(org.teiid.client.ProcedureErrorInstructionException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) NoRouteToHostException(java.net.NoRouteToHostException) TeiidException(org.teiid.core.TeiidException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectionException(org.teiid.net.ConnectionException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 2 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class SocketServerConnection method getService.

public <T> T getService(Class<T> iface) {
    return iface.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { iface }, new SocketServerInstanceImpl.RemoteInvocationHandler(iface, PropertiesUtils.getBooleanProperty(connProps, TeiidURL.CONNECTION.ENCRYPT_REQUESTS, false)) {

        @Override
        protected SocketServerInstance getInstance() throws CommunicationException {
            if (failOver && System.currentTimeMillis() - lastPing > pingFailOverInterval) {
                try {
                    ResultsFuture<?> future = selectServerInstance(false).getService(ILogon.class).ping();
                    future.get();
                } catch (SingleInstanceCommunicationException e) {
                    closeServerInstance();
                } catch (CommunicationException e) {
                    throw e;
                } catch (InvalidSessionException e) {
                    disconnect();
                    closeServerInstance();
                } catch (Exception e) {
                    closeServerInstance();
                }
            }
            lastPing = System.currentTimeMillis();
            try {
                return selectServerInstance(false);
            } catch (ConnectionException e) {
                throw new CommunicationException(e);
            }
        }

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            try {
                return super.invoke(proxy, method, args);
            } catch (Exception e) {
                if (ExceptionUtil.getExceptionOfType(e, InvalidSessionException.class) != null) {
                    disconnect();
                }
                throw e;
            }
        }
    }));
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) CommunicationException(org.teiid.net.CommunicationException) Method(java.lang.reflect.Method) ILogon(org.teiid.client.security.ILogon) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) SocketException(java.net.SocketException) CommunicationException(org.teiid.net.CommunicationException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ConnectionException(org.teiid.net.ConnectionException) ConnectionException(org.teiid.net.ConnectionException)

Example 3 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class SocketServerConnectionFactory method getConnection.

/**
 * @param connectionProperties will be updated with additional information before logon
 */
public SocketServerConnection getConnection(Properties connectionProperties) throws CommunicationException, ConnectionException {
    TeiidURL url;
    try {
        url = new TeiidURL(connectionProperties.getProperty(TeiidURL.CONNECTION.SERVER_URL));
    } catch (MalformedURLException e1) {
        throw new ConnectionException(JDBCPlugin.Event.TEIID20014, e1, e1.getMessage());
    }
    String discoveryStrategyName = connectionProperties.getProperty(TeiidURL.CONNECTION.DISCOVERY_STRATEGY, URL);
    ServerDiscovery discovery;
    if (URL.equalsIgnoreCase(discoveryStrategyName)) {
        discovery = new UrlServerDiscovery();
    } else {
        try {
            discovery = (ServerDiscovery) ReflectionHelper.create(discoveryStrategyName, null, this.getClass().getClassLoader());
        } catch (TeiidException e) {
            throw new ConnectionException(e);
        }
    }
    discovery.init(url, connectionProperties);
    return new SocketServerConnection(this, url.isUsingSSL(), discovery, connectionProperties);
}
Also used : MalformedURLException(java.net.MalformedURLException) TeiidURL(org.teiid.net.TeiidURL) ConnectionException(org.teiid.net.ConnectionException) TeiidException(org.teiid.core.TeiidException)

Example 4 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class ModuleHelper method createFromModule.

static ServerConnection createFromModule(Properties info) throws ConnectionException, TeiidException {
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        ModuleLoader callerModuleLoader = Module.getCallerModuleLoader();
        if (callerModuleLoader == null) {
            logger.fine(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20033));
            // $NON-NLS-1$
            return (ServerConnection) ReflectionHelper.create("org.teiid.transport.LocalServerConnection", Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, LocalProfile.USE_CALLING_THREAD, true)), Thread.currentThread().getContextClassLoader());
        }
        // $NON-NLS-1$
        final Module module = callerModuleLoader.loadModule(ModuleIdentifier.create("org.jboss.teiid"));
        Thread.currentThread().setContextClassLoader(module.getClassLoader());
        // $NON-NLS-1$
        return (ServerConnection) ReflectionHelper.create("org.teiid.transport.LocalServerConnection", Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, LocalProfile.USE_CALLING_THREAD, true)), Thread.currentThread().getContextClassLoader());
    } catch (ModuleLoadException e) {
        throw new ConnectionException(JDBCPlugin.Event.TEIID20008, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20008));
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleLoader(org.jboss.modules.ModuleLoader) ServerConnection(org.teiid.net.ServerConnection) Module(org.jboss.modules.Module) ConnectionException(org.teiid.net.ConnectionException)

Example 5 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class VDBRepository method waitForFinished.

public void waitForFinished(VDBKey key, int timeOutMillis) throws ConnectionException {
    CompositeVDB cvdb = null;
    if (timeOutMillis < 0) {
        timeOutMillis = DEFAULT_TIMEOUT_MILLIS;
    }
    long timeOutNanos = TimeUnit.MILLISECONDS.toNanos(timeOutMillis);
    lock.lock();
    try {
        while ((cvdb = this.vdbRepo.get(key)) == null) {
            if (timeOutNanos <= 0) {
                throw new ConnectionException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40096, timeOutMillis, key.getName(), key.getVersion()));
            }
            timeOutNanos = this.vdbAdded.awaitNanos(timeOutNanos);
        }
    } catch (InterruptedException e) {
        return;
    } finally {
        lock.unlock();
    }
    VDBMetaData vdb = cvdb.getVDB();
    long finishNanos = System.nanoTime() + timeOutNanos;
    synchronized (vdb) {
        while (vdb.getStatus() != Status.ACTIVE) {
            long millis = timeOutNanos / 1000000;
            if (millis <= 0) {
                throw new ConnectionException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40097, timeOutMillis, key.getName(), key.getVersion(), vdb.getValidityErrors()));
            }
            try {
                vdb.wait(millis);
            } catch (InterruptedException e) {
                return;
            }
            timeOutNanos = finishNanos - System.nanoTime();
        }
    }
}
Also used : VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ConnectionException(org.teiid.net.ConnectionException)

Aggregations

ConnectionException (org.teiid.net.ConnectionException)10 CommunicationException (org.teiid.net.CommunicationException)7 IOException (java.io.IOException)4 LogonException (org.teiid.client.security.LogonException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 TeiidException (org.teiid.core.TeiidException)4 UnknownHostException (java.net.UnknownHostException)3 InvalidSessionException (org.teiid.client.security.InvalidSessionException)3 MalformedURLException (java.net.MalformedURLException)2 SocketException (java.net.SocketException)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 ILogon (org.teiid.client.security.ILogon)2 ConnectionImpl (org.teiid.jdbc.ConnectionImpl)2 ConnectionProfile (org.teiid.jdbc.ConnectionProfile)2 TeiidDriver (org.teiid.jdbc.TeiidDriver)2 HostInfo (org.teiid.net.HostInfo)2 TeiidURL (org.teiid.net.TeiidURL)2 Method (java.lang.reflect.Method)1 ConnectException (java.net.ConnectException)1